public static function init() { //Load database definitions if (is_null(self::$_databaseDef)) { self::_loadDatabaseDefinition(); } $obj = new static(); //Set default class name $classNameFull = "\\" . get_class($obj); $classSplit = explode("\\", $classNameFull); $module = $classSplit[1]; $class = end($classSplit); $table = \ATP\Inflector::underscore(\ATP\Inflector::pluralize($class)); self::$_classDefs[$classNameFull] = array(); self::$_classDefs[$classNameFull]['children'] = array(); self::$_classDefs[$classNameFull]['owners'] = array(); self::$_classDefs[$classNameFull]['defaultOrder'] = "id ASC"; //Setup child relations self::$_classDefs[$classNameFull]['relations'] = $obj->_relations(); //Setup class $obj->setTableNamespace(strtolower($module)); $obj->_setup(); //Determine final table name $tableFull = is_null($obj->getTableNamespace()) ? $table : $obj->getTableNamespace() . "_" . $table; self::$_databaseDef['tables'][$tableFull]['class'] = $classNameFull; self::$_databaseDef['classes'][$classNameFull] = array(); self::$_databaseDef['classes'][$classNameFull]['table'] = $tableFull; self::$_databaseDef['classes'][$classNameFull]['namespace'] = $obj->getTableNamespace(); //Copy definition to class self::$_classDefs[$classNameFull]['namespace'] = $obj->getTableNamespace(); self::$_classDefs[$classNameFull]['table'] = $tableFull; foreach (self::$_databaseDef['tables'][$tableFull] as $key => $data) { self::$_classDefs[$classNameFull][$key] = $data; } }
protected function init($checkLogin = true) { $this->noCache(); //Set password salt for user \ATPAdmin\Model\User::setPasswordSalt($this->config('admin.auth.password_salt')); //Check for logged in user $this->_validLogin = !$checkLogin || !$this->_checkLogin || \ATPAdmin\Auth::isLoggedIn(); if (!$this->_validLogin) { $this->redirect()->toRoute('admin', array('action' => 'login')); } //Set the admin layout $this->layout("atp-admin/layout/admin"); //Get the model information $this->models = $this->config('admin.models'); $this->reports = $this->config('admin.reports'); //Setup the view $this->view = new \Zend\View\Model\ViewModel(); //Get the flash messenger $this->flash = $this->flashMessenger(); $this->layout()->addChild(new \ATPCore\View\Widget\FlashWidget($this->flash), 'flash'); //Create the admin menu $adminMenu = array(); //Add the models foreach ($this->models as $model => $modelData) { if (!isset($adminMenu[$modelData['category']])) { $adminMenu[$modelData['category']] = array(); } $linkData = array('action' => 'list', 'model' => \ATP\Inflector::underscore($model)); if (isset($modelData['custom_actions']['list'])) { $linkData['controller'] = $modelData['custom_actions']['list']['controller']; $linkData['action'] = $modelData['custom_actions']['list']['action']; } $adminMenu[$modelData['category']][] = array('label' => \ATP\Inflector::pluralize($modelData['displayName']), 'linkData' => $linkData); } //Add the reports foreach ($this->reports as $report => $reportData) { if (!isset($adminMenu[$reportData['category']])) { $adminMenu[$reportData['category']] = array(); } $adminMenu[$reportData['category']][] = array('label' => $reportData['label'], 'linkData' => array('action' => 'report', 'model' => $report)); } $this->layout()->menu = $adminMenu; //Load the model data if needed $this->modelType = $this->params('model'); if (!empty($this->modelType) && $this->params('action') != 'report') { $this->modelData = $this->models[$this->modelType]; } }