Overview

Namespaces

  • GLFramework
    • Cache
    • Controller
    • DaMa
      • Manipulators
    • Database
    • HTTP
    • Mail
    • Middleware
    • Model
    • Module
    • Tests
    • Upload
    • Utils
  • None

Classes

  • GLFramework\Bootstrap
  • GLFramework\Cache\Cache
  • GLFramework\Cache\MemcachedCache
  • GLFramework\Cache\MemoryCache
  • GLFramework\Controller
  • GLFramework\Controller\AdminController
  • GLFramework\Controller\APIController
  • GLFramework\Controller\AuthController
  • GLFramework\Controller\ErrorController
  • GLFramework\Controller\ExceptionController
  • GLFramework\DaMa\Association
  • GLFramework\DaMa\DataManipulation
  • GLFramework\DaMa\Manipulator
  • GLFramework\DaMa\Manipulators\CSVManipulator
  • GLFramework\DaMa\Manipulators\ManipulatorCore
  • GLFramework\DaMa\Manipulators\XLSManipulator
  • GLFramework\DaMa\Manipulators\XLSXManipulator
  • GLFramework\Database\Connection
  • GLFramework\Database\MySQLConnection
  • GLFramework\DatabaseManager
  • GLFramework\DBStructure
  • GLFramework\Events
  • GLFramework\Filesystem
  • GLFramework\HTTP\API
  • GLFramework\Log
  • GLFramework\Mail
  • GLFramework\Mail\Mail
  • GLFramework\Mail\MailSystem
  • GLFramework\Mail\PHPMailer
  • GLFramework\MailView
  • GLFramework\Middleware\APIAuthorizationMiddleware
  • GLFramework\Middleware\ControllerMiddleware
  • GLFramework\Model
  • GLFramework\Model\Page
  • GLFramework\Model\User
  • GLFramework\Model\UserPage
  • GLFramework\ModelResult
  • GLFramework\Module\Module
  • GLFramework\Module\ModuleManager
  • GLFramework\Request
  • GLFramework\Response
  • GLFramework\Tests\DatabaseTestCase
  • GLFramework\Tests\TestCase
  • GLFramework\Upload\Upload
  • GLFramework\Upload\Uploads
  • GLFramework\Utils\DataTablesManager
  • GLFramework\Versions
  • GLFramework\View

Interfaces

  • GLFramework\Middleware

Functions

  • array_merge_recursive_ex
  • e
  • file_get_php_classes
  • fix_date
  • fix_date_format
  • fix_decimal
  • fix_url
  • get
  • get_php_classes
  • http_response_code
  • instance_method
  • is_module_enabled
  • now
  • post
  • print_array
  • print_brief_debug
  • print_debug
  • random_str
  • reArrayFiles
  • reArrayPost
  • today
  • Overview
  • Namespace
  • Class
  1: <?php
  2: /**
  3:  * Created by PhpStorm.
  4:  * User: manus
  5:  * Date: 13/1/16
  6:  * Time: 17:26
  7:  */
  8: 
  9: namespace GLFramework;
 10: 
 11: 
 12: use GLFramework\Module\ModuleManager;
 13: 
 14: class View
 15: {
 16:     private $filters = array();
 17:     private $twig;
 18:     /**
 19:      * @var Controller
 20:      */
 21:     private $controller;
 22: 
 23:     /**
 24:      * View constructor.
 25:      * @param $controller Controller
 26:      */
 27:     public function __construct($controller)
 28:     {
 29:         $this->controller = $controller;
 30:         $directories = ModuleManager::getInstance()->getViews($controller->module);
 31:         $loader = new \Twig_Loader_Filesystem($directories);
 32:         $this->twig = new \Twig_Environment($loader, array());
 33:         Events::fire('onViewCreated', array(&$this->twig));
 34:         $this->twig->addGlobal('config', $this->controller->config);
 35:         $this->twig->addGlobal('_GET', $_GET);
 36:         $this->twig->addGlobal('_POST', $_POST);
 37:         $this->twig->addGlobal('_REQUEST', $_REQUEST);
 38:         $this->twig->addGlobal('_SERVER', $_SERVER);
 39:         $this->twig->addGlobal('this', $this->controller);
 40:         $this->twig->addGlobal('render', $this);
 41:         $this->twig->addGlobal('manager', ModuleManager::getInstance());
 42:         $this->twig->addFunction(new \Twig_SimpleFunction('fire', array($this, 'fireEvent')));
 43:         $this->twig->addFilter(new \Twig_SimpleFilter('active', array($this, 'isHrefActive')));
 44:         $this->twig->addFilter(new \Twig_SimpleFilter('fecha_hora', array($this, 'parseFechaHora')));
 45:         $this->twig->addFilter(new \Twig_SimpleFilter('fecha', array($this, 'parseFecha')));
 46:         $this->twig->addFilter(new \Twig_SimpleFilter('hora', array($this, 'parseHora')));
 47:         $this->twig->addFilter(new \Twig_SimpleFilter('debug', array($this, 'debug')));
 48:         $this->twig->addFilter(new \Twig_SimpleFilter('number', array($this, 'isNumber')));
 49:         $this->twig->addFilter(new \Twig_SimpleFilter('implode', array($this, 'implode')));
 50:     }
 51: 
 52:     /**
 53:      * Devuelve la vista renderizada
 54:      * @param null $data
 55:      * @param array $params
 56:      * @return array|null|string
 57:      */
 58:     public function render($data = null, $params = array())
 59:     {
 60:         if($this->controller->getTemplate() != null)
 61:         {
 62:             $data = $data == null?array():$data;
 63:             $this->twig->addGlobal('params', $params);
 64:             $template = $this->twig->loadTemplate($this->controller->getTemplate());
 65:             return $template->render($data);
 66:         }
 67:         return $data;
 68:     }
 69: 
 70:     /**
 71:      * Devuelve la plantilla renderizada
 72:      * @param $template
 73:      * @param array $data
 74:      * @return string
 75:      */
 76:     public function display($template, $data = array())
 77:     {
 78:         return $this->getTwig()->render($template, $data);
 79:     }
 80: 
 81:     /**
 82:      * Devulve una vista compatible con los clientes de correo
 83:      * @param $template
 84:      * @param array $data
 85:      * @param array $css
 86:      * @return string
 87:      */
 88:     public function mail($template, $data = array(), &$css = array())
 89:     {
 90:         $this->twig->addFunction(new \Twig_SimpleFunction('css', function($file) use(&$css)
 91:         {
 92:             $css[] = $file;
 93:         }));
 94:         $template = $this->twig->loadTemplate($template);
 95:         return $template->render($data);
 96:     }
 97: 
 98:     public function addFilter($filter)
 99:     {
100:         $this->filters[] = $filter;
101:     }
102: 
103: 
104:     public function isHrefActive($url)
105:     {
106:         if(strpos($_SERVER['REQUEST_URI'], $url) !== FALSE)
107:         {
108:             return 'active';
109:         }
110:         return "";
111:     }
112: 
113:     public function parseFechaHora($fecha)
114:     {
115:         return $this->parseFecha($fecha) . " " . $this->parseHora($fecha);
116:     }
117:     public function parseFecha($fecha)
118:     {
119:         if(!$fecha) return "";
120:         $time = strtotime($fecha);
121:         return date("d-m-Y", $time);
122:     }
123: 
124:     public function parseHora($fecha)
125:     {
126:         if(!$fecha) return "";
127:         $time = strtotime($fecha);
128:         return date("H:i:s", $time);
129:     }
130: 
131:     public function debug($data)
132:     {
133:         print_debug($data);
134:     }
135: 
136:     public function isNumber($data)
137:     {
138:         return is_numeric($data);
139:     }
140: 
141:     public function implode($array, $separator)
142:     {
143:         return implode($separator, $array);
144:     }
145:     /**
146:      * @return \Twig_Environment
147:      */
148:     public function getTwig()
149:     {
150:         return $this->twig;
151:     }
152: 
153:     public function fireEvent($name, $args = array())
154:     {
155:         Events::fire($name, $args);
156:     }
157: 
158:     /**
159:      * @return Controller
160:      */
161:     public function getController()
162:     {
163:         return $this->controller;
164:     }
165: 
166:     /**
167:      * @param Controller $controller
168:      */
169:     public function setController($controller)
170:     {
171:         $this->controller = $controller;
172:     }
173: 
174:     
175: 
176: 
177: }
API documentation generated by ApiGen