Advertisement
SUNSPINX

Untitled

Aug 16th, 2017
481
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4. *
  5. * Vzorový kontoler (rodič) všech kontrolerů v komponentě "presentation"
  6. *
  7. * @author Michal Šmahel (ceskyDJ) <admin@ceskydj.cz>
  8. * @copyright (C) 2017-Současnost, Michal ŠMAHEL, Vladislav Domin
  9. *
  10. */
  11. abstract class PresentationController
  12. {
  13. /**
  14. * @var array Pole, jehož indexy jsou poté viditelné v šabloně jako běžné proměnné
  15. */
  16. public $data = [];
  17. /**
  18. * @var array Hlavička HTML stránky
  19. * FIXME: Problém s jazyky...
  20. * TODO: Pozor na používání tohoto pole v obsahových kontrolerech (názvy klíčů musí být stejné)
  21. */
  22. public $head = [
  23. 'title' => "",
  24. 'keywords' => "",
  25. 'description' => "",
  26. 'active_link' => "",
  27. ];
  28. /**
  29. * @var string Hlavní pohled (rozložení)
  30. */
  31. public $mainView = "";
  32. /**
  33. * @var string Obsahový pohled
  34. */
  35. public $contentView = "";
  36.  
  37. /**
  38. * @var string Název komponenty
  39. */
  40. const COMPONENT_NAME = "presentation";
  41.  
  42.  
  43.  
  44. /**
  45. * Hlavní metoda konstruktoru (řídící)
  46. *
  47. * @param $params array Parametry pro zpracování
  48. */
  49. abstract function process($params);
  50.  
  51. /**
  52. * Přesměruje na dané URL
  53. *
  54. * @param $url string URL adresa pro přesměrování
  55. */
  56. protected function route($url, $time = 0) {
  57. $domainUrl = "http://" . $_SERVER['SERVER_NAME'] . '/' .$_SESSION['lang'];
  58.  
  59. if($time = 0) {
  60. header("Location: $domainUrl/$url");
  61. header("Connection: close");
  62. exit;
  63. }
  64. else {
  65. header("refresh: $time ;url= $domainUrl/$url");
  66. header("Connection: close");
  67. exit;
  68. }
  69. }
  70.  
  71. /**
  72. * Nastaví HTTP hlavičku
  73. *
  74. * @param $code int Kód HTTP hlavičky
  75. */
  76. public function setHeader($code) {
  77. switch ($code) {
  78. // Nenalezeno
  79. case 404:
  80. header("HTTP/1.0 404 Not Found");
  81. break;
  82. // Vnitřní chyba
  83. default:
  84. header("HTTP/1.0 500 Internal Server Error");
  85. break;
  86. }
  87. }
  88.  
  89. /**
  90. * Vrátí cestu do složky této komponenty
  91. *
  92. * @return string Cesta do složky
  93. */
  94. public function getDirectory() {
  95. return $_SERVER['DOCUMENT_ROOT'] . "/components/" . self::COMPONENT_NAME;
  96. }
  97.  
  98. /**
  99. * Nastaví notifikáciu do SESSIONU
  100. *
  101. * @param $message string Text notifikacie
  102. * @param $cssClass string Typ notifikacie
  103. *
  104. */
  105. public function setNotification($message, $cssClass) {
  106. $data = array(
  107. "text" => $message,
  108. "class" => $cssClass
  109. );
  110.  
  111. if (isset($_SESSION['notifications']))
  112. $_SESSION['notifications'][] = $data;
  113. else
  114. $_SESSION['notifications'] = array($data);
  115. }
  116.  
  117. /**
  118. * Vráti text a triedu zo SESSIONU a následne vymaže SESSION
  119. *
  120. * @return array string text a trieda notifikacie
  121. */
  122. public function getNotification() {
  123. if (isset($_SESSION['notifications']))
  124. {
  125. $notification = $_SESSION['notifications'];
  126. unset($_SESSION['notifications']);
  127. return $notification;
  128. }
  129. else
  130. return array();
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement