HtmlHelper.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Helpers;
  3. use App\Interfaces\OptionInterface;
  4. class HtmlHelper {
  5. public static function renderOptions(array $options, $selected_value = null): void {
  6. foreach($options as $i => $x) {
  7. if($x instanceof OptionInterface) {
  8. $value = $x->getOptionValue();
  9. $label = $x->getOptionLabel();
  10. }
  11. else {
  12. $value = $i;
  13. $label = $x;
  14. }
  15. $selected = ((string) $value === (string) $selected_value) ? "selected" : "";
  16. ?>
  17. <option value="<?=htmlspecialchars($value)?>" <?=$selected?>>
  18. <?=htmlspecialchars($label)?>
  19. </option>
  20. <?php
  21. }
  22. }
  23. public static function renderInfoAlert(string $message): void {
  24. ?>
  25. <div class="alert alert-info">
  26. <i class="fa fa-fw fa-info-circle"></i>
  27. <?=htmlspecialchars($message)?>
  28. </div>
  29. <?php
  30. }
  31. public static function readonly($value): string {
  32. return $value ? "readonly" : "";
  33. }
  34. public static function checked($value): string {
  35. return $value ? "checked" : "";
  36. }
  37. public static function hidden($value): string {
  38. return $value ? "hidden" : "";
  39. }
  40. public static function required($value): string {
  41. return $value ? "required" : "";
  42. }
  43. }