2
0

callout.class.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Class callout
  4. *
  5. * Cette classe génère des callouts Bootstrap personnalisés.
  6. * Un callout est un composant d'interface qui permet de mettre en avant des informations importantes.
  7. *
  8. * @method static string get(array $_array) Renvoie le HTML du callout.
  9. * @method static void print(array $_array) Affiche le callout directement.
  10. */
  11. class callout {
  12. /**
  13. * Construit le HTML d'un callout en fonction des paramètres fournis.
  14. *
  15. * @param array $_array Les paramètres du callout (type, class, h4, p).
  16. * @return string Le HTML du callout.
  17. */
  18. static private function construct(array $_array) {
  19. $type = $_array['type'] ?? 'default';
  20. $allowedTypes = ['success', 'primary', 'danger', 'warning', 'info'];
  21. $type = !in_array($type, $allowedTypes) ? 'default' : $type;
  22. $size = $_array['size'] ?? '';
  23. $allowedSizes = ['tiny'];
  24. $size = in_array($size, $allowedSizes) ? "bd-callout-" . $size : NULL;
  25. $class = $_array['class'] ?? '';
  26. $style = $_array['style'] ?? '';
  27. $h4 = $_array['h4'] ?? '';
  28. $p = $_array['p'] ?? '';
  29. return '<div class="bd-callout bd-callout-' . $type . ($size ? ' ' . $size : '') . ($class ? ' ' . $class : '') . '"' . ($style ? ' style="' . $style . '"' : '') . '>' .
  30. ($h4 ? '<h4>' . $h4 . '</h4>' : '') .
  31. ($p ? '<p>' . $p . '</p>' : '') .
  32. '</div>';
  33. }
  34. /**
  35. * Renvoie le HTML d'un callout.
  36. *
  37. * @param array $_array Les paramètres du callout.
  38. * @return string Le HTML du callout.
  39. */
  40. static public function get(array $_array) {
  41. return self::construct($_array);
  42. }
  43. /**
  44. * Affiche directement le callout.
  45. *
  46. * @param array $_array Les paramètres du callout.
  47. * @return void
  48. */
  49. static public function print(array $_array) {
  50. echo self::construct($_array);
  51. }
  52. }