Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *
- * Vzorový kontoler (rodič) všech kontrolerů v komponentě "presentation"
- *
- * @author Michal Šmahel (ceskyDJ) <admin@ceskydj.cz>
- * @copyright (C) 2017-Současnost, Michal ŠMAHEL, Vladislav Domin
- *
- */
- abstract class PresentationController
- {
- /**
- * @var array Pole, jehož indexy jsou poté viditelné v šabloně jako běžné proměnné
- */
- public $data = [];
- /**
- * @var array Hlavička HTML stránky
- * FIXME: Problém s jazyky...
- * TODO: Pozor na používání tohoto pole v obsahových kontrolerech (názvy klíčů musí být stejné)
- */
- public $head = [
- 'title' => "",
- 'keywords' => "",
- 'description' => "",
- 'active_link' => "",
- ];
- /**
- * @var string Hlavní pohled (rozložení)
- */
- public $mainView = "";
- /**
- * @var string Obsahový pohled
- */
- public $contentView = "";
- /**
- * @var string Název komponenty
- */
- const COMPONENT_NAME = "presentation";
- /**
- * Hlavní metoda konstruktoru (řídící)
- *
- * @param $params array Parametry pro zpracování
- */
- abstract function process($params);
- /**
- * Přesměruje na dané URL
- *
- * @param $url string URL adresa pro přesměrování
- */
- protected function route($url, $time = 0) {
- $domainUrl = "http://" . $_SERVER['SERVER_NAME'] . '/' .$_SESSION['lang'];
- if($time = 0) {
- header("Location: $domainUrl/$url");
- header("Connection: close");
- exit;
- }
- else {
- header("refresh: $time ;url= $domainUrl/$url");
- header("Connection: close");
- exit;
- }
- }
- /**
- * Nastaví HTTP hlavičku
- *
- * @param $code int Kód HTTP hlavičky
- */
- public function setHeader($code) {
- switch ($code) {
- // Nenalezeno
- case 404:
- header("HTTP/1.0 404 Not Found");
- break;
- // Vnitřní chyba
- default:
- header("HTTP/1.0 500 Internal Server Error");
- break;
- }
- }
- /**
- * Vrátí cestu do složky této komponenty
- *
- * @return string Cesta do složky
- */
- public function getDirectory() {
- return $_SERVER['DOCUMENT_ROOT'] . "/components/" . self::COMPONENT_NAME;
- }
- /**
- * Nastaví notifikáciu do SESSIONU
- *
- * @param $message string Text notifikacie
- * @param $cssClass string Typ notifikacie
- *
- */
- public function setNotification($message, $cssClass) {
- $data = array(
- "text" => $message,
- "class" => $cssClass
- );
- if (isset($_SESSION['notifications']))
- $_SESSION['notifications'][] = $data;
- else
- $_SESSION['notifications'] = array($data);
- }
- /**
- * Vráti text a triedu zo SESSIONU a následne vymaže SESSION
- *
- * @return array string text a trieda notifikacie
- */
- public function getNotification() {
- if (isset($_SESSION['notifications']))
- {
- $notification = $_SESSION['notifications'];
- unset($_SESSION['notifications']);
- return $notification;
- }
- else
- return array();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement