1
0

html_helper.php 658 B

123456789101112131415161718192021222324252627282930
  1. <?php
  2. class HtmlHelper {
  3. public static function checked(?string $value): string {
  4. return $value ? "checked" : "";
  5. }
  6. public static function selected(?string $value, ?string $selected): string {
  7. return ((string) $value === (string) $selected) ? "selected" : "";
  8. }
  9. public static function renderOptions(array $options, ?string $selected = null): void {
  10. foreach($options as $value => $display) {
  11. ?>
  12. <option value="<?=$value?>" <?=self::selected($value, $selected)?>>
  13. <?=htmlspecialchars($display)?>
  14. </option>
  15. <?php
  16. }
  17. }
  18. public static function getYesNoOptions(): array {
  19. return [
  20. 1 => __("Yes"),
  21. 0 => __("No")
  22. ];
  23. }
  24. }