Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Controller
- {
- const HAS_MODEL = 1;
- const HAS_VIEW = 2;
- const USE_HELPERS = 3;
- protected $_defaultAction = 'index';
- public function setDefaultAction($action = 'index')
- {
- $this->_defaultAction = $action;
- }
- public function getDefaultAction()
- {
- return $this->_defaultAction;
- }
- protected $_model;
- protected $_controller;
- protected $_action;
- protected $_view;
- protected $_modelBaseName;
- protected static $_opt;
- protected $_options;
- protected static $_siteDataModel = null;
- protected $_helpersCatName = null;
- public function __construct($model = null, $action = null, $options = array(Controller::HAS_MODEL, Controller::HAS_VIEW, Controller::USE_HELPERS))
- {
- // wywołanie z bootstrap.php, by pobrać nazwę domyślnej akcji
- if ($model == null && $action == null)
- {
- $this->setDefaultAction();
- return;
- }
- if (self::$_siteDataModel == null)
- {
- self::$_siteDataModel = Model::getInstance('SiteData'); //new SiteDataModel();
- }
- $this->_options = $options;
- $this->_controller = ucwords(__CLASS__);
- $this->_action = $action;
- $this->_modelBaseName = $model;
- if (in_array(Controller::USE_HELPERS, $options))
- $this->_helpersCatName = $model . '-' . $action;
- if (in_array(Controller::HAS_MODEL, $options))
- $this->_setModel($model);
- if (in_array(Controller::HAS_VIEW, $options))
- {
- $this->_view = new View(HOME . DS . 'views' . DS . strtolower($this->_modelBaseName) . DS . $action . '.php');
- $this->_view->set('app_model', strtolower($this->_modelBaseName));
- $this->_view->set('app_action', strtolower($this->_action));
- }
- }
- public static function setOpt($opt)
- {
- self::$_opt = $opt;
- }
- public static function getOpt()
- {
- return self::$_opt;
- }
- protected function initHelpers($opt)
- {
- if ($this->_helpersCatName != null)
- {
- // $n = $this->_helpersCatName.($opt != null ? '-'.$opt : '');
- // $this->_helpersCatName = $n;
- return Helpers::init($this->_helpersCatName);
- }
- }
- protected function _setModel($modelName)
- {
- // $modelName .= 'Model';
- $this->_model = Model::getInstance($modelName);//new $modelName();
- }
- protected function _setView($viewName)
- {
- $this->_view = new View(HOME . DS . 'views' . DS . strtolower($this->_modelBaseName) . DS . $viewName . '.php');
- }
- public static final function getSiteDataModel()
- {
- return self::$_siteDataModel;
- }
- public static final function getDefaultUserRoute()
- {
- return MSession::getUserDefaultRoute();
- }
- public static final function isLoggedIn()
- {
- $logged = MSession::getUser();
- if ($logged !== NULL && ($logged->canLogin() || $logged->canLoinToForm()) && $logged->getIsOnline() != 0)
- {
- if (defined('_AJAX_APP') && _AJAX_APP)
- return true;
- $logged->_updateInternalVars(false, false);
- //MSession::set("logged_user", new privs($logged->getUserLogin()));
- return true;
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement