File: /var/www/vhosts/enlugo.es/httpdocs/wp-content/plugins/google-maps-ready/classes/controller.php
<?php
abstract class controllerGmp {
protected $_models = array();
protected $_views = array();
protected $_task = '';
protected $_defaultView = '';
protected $_code = '';
public function __construct($code) {
$this->setCode($code);
$this->_defaultView = $this->getCode();
}
public function init() {
/*load model and other preload data goes here*/
}
protected function _onBeforeInit() {
}
protected function _onAfterInit() {
}
public function setCode($code) {
$this->_code = $code;
}
public function getCode() {
return $this->_code;
}
public function exec($task = '') {
if(method_exists($this, $task)) {
$this->_task = $task; //For multicontrollers module version - who know, maybe that's will be?))
return $this->$task();
}
return null;
}
public function getView($name = '') {
if(empty($name)) $name = $this->getCode();
if(!isset($this->_views[$name])) {
$this->_views[$name] = $this->_createView($name);
}
return $this->_views[$name];
}
public function getModel($name = '') {
if(!$name)
$name = $this->_code;
if(!isset($this->_models[$name])) {
$this->_models[$name] = $this->_createModel($name);
}
return $this->_models[$name];
}
protected function _createModel($name = '') {
if(empty($name)) $name = $this->getCode();
$parentModule = frameGmp::_()->getModule( $this->getCode() );
$className = toeGetClassNameGmp($name. 'Model', true);
if(!class_exists($className)) {
import($parentModule->getModDir(). 'models'. DS. $name. '.php');
}
if($className && class_exists($className)) {
$model = new $className();
$model->setCode( $this->getCode() );
return $model;
}
return NULL;
}
protected function _createView($name = '') {
if(empty($name)) $name = $this->getCode();
$parentModule = frameGmp::_()->getModule( $this->getCode() );
$className = toeGetClassNameGmp($name. 'View', true);
if(!class_exists($className)) {
import($parentModule->getModDir(). 'views'. DS. $name. '.php');
}
if($className && class_exists($className)) {
$view = new $className();
$view->setCode( $this->getCode() );
return $view;
}
return NULL;
}
public function display($viewName = '') {
$view = NULL;
if(($view = $this->getView($viewName)) === NULL) {
$view = $this->getView(); //Get default view
}
if($view) {
$view->display();
}
}
public function __call($name, $arguments) {
$model = $this->getModel();
if(method_exists($model, $name))
return $model->$name($arguments[0]);
else
return false;
}
/**
* Retrive permissions for controller methods if exist.
* If need - should be redefined in eacH controller where it required.
* @return array with permissions
* @example :
return array(
S_METHODS => array(
'save' => array(GMP_ADMIN),
'remove' => array(GMP_ADMIN),
'restore' => GMP_ADMIN,
),
S_USERLEVELS => array(
S_ADMIN => array('save', 'remove', 'restore')
),
);
* Can be used on of sub-array - GMP_METHODS or GMP_USERLEVELS
*/
public function getPermissions() {
return array();
}
}