Ejemplo n.º 1
0
 /**
  * Create actions, if actions block is in config
  * Create menus, if menus block is in config and action used in menu has been already created
  */
 private function createMenusAndActions()
 {
     $actions = array();
     $menus = array();
     /**
      * Create actions if any
      */
     if (count($this->config->getActions()) > 0) {
         foreach ($this->config->getActions() as $act) {
             /** @var modAction[] $actions */
             $actions[$act->getId()] = $this->modx->newObject('modAction');
             $actions[$act->getId()]->fromArray(array('namespace' => $this->config->getLowCaseName(), 'controller' => $act->getController(), 'haslayout' => $act->getHasLayout(), 'lang_topics' => $act->getLangTopics(), 'assets' => $act->getAssets()), '', true, true);
             $actions[$act->getId()]->save();
         }
         $this->modx->log(modX::LOG_LEVEL_INFO, 'Actions created.');
     }
     /**
      * Crete menus if any
      */
     if (count($this->config->getMenus()) > 0) {
         foreach ($this->config->getMenus() as $i => $men) {
             /** @var modMenu[] $menus */
             $menus[$i] = $this->modx->newObject('modMenu');
             $menus[$i]->fromArray(array('text' => $men->getText(), 'parent' => $men->getParent(), 'description' => $men->getDescription(), 'icon' => $men->getIcon(), 'menuindex' => $men->getMenuIndex(), 'params' => $men->getParams(), 'handler' => $men->getHandler(), 'permissions' => $men->getPermissions()), '', true, true);
             if (isset($actions[$men->getAction()])) {
                 $menus[$i]->addOne($actions[$men->getAction()]);
             } else {
                 $menus[$i]->set('action', $men->getAction());
                 $menus[$i]->set('namespace', $this->config->getLowCaseName());
             }
             $menus[$i]->save();
         }
         $this->modx->log(modX::LOG_LEVEL_INFO, 'Menus created.');
     }
 }
 private function updateActionsAndMenus()
 {
     /** @var modAction[] $actions */
     $actions = $this->modx->getCollection('modAction', array('namespace' => $this->newConfig->getLowCaseName()));
     foreach ($actions as $action) {
         $action->remove();
     }
     foreach ($this->oldConfig->getMenus() as $menu) {
         $menuObject = $this->modx->getObject('modMenu', array('text' => $menu->getText()));
         $menuObject->remove();
     }
     $actions = array();
     $menus = array();
     /**
      * Create actions if any
      */
     if (count($this->newConfig->getActions()) > 0) {
         foreach ($this->newConfig->getActions() as $act) {
             /** @var modAction[] $actions */
             $actions[$act->getId()] = $this->modx->newObject('modAction');
             $actions[$act->getId()]->fromArray(array('namespace' => $this->newConfig->getLowCaseName(), 'controller' => $act->getController(), 'haslayout' => $act->getHasLayout(), 'lang_topics' => $act->getLangTopics(), 'assets' => $act->getAssets()), '', true, true);
             $actions[$act->getId()]->save();
         }
     }
     /**
      * Crete menus if any
      */
     if (count($this->newConfig->getMenus()) > 0) {
         foreach ($this->newConfig->getMenus() as $i => $men) {
             /** @var modMenu[] $menus */
             $menus[$i] = $this->modx->newObject('modMenu');
             $menus[$i]->fromArray(array('text' => $men->getText(), 'parent' => $men->getParent(), 'description' => $men->getDescription(), 'icon' => $men->getIcon(), 'menuindex' => $men->getMenuIndex(), 'params' => $men->getParams(), 'handler' => $men->getHandler()), '', true, true);
             if (isset($actions[$men->getAction()])) {
                 $menus[$i]->addOne($actions[$men->getAction()]);
             } else {
                 $menus[$i]->set('action', $men->getAction());
                 $menus[$i]->set('namespace', $this->newConfig->getLowCaseName());
             }
             $menus[$i]->save();
         }
     }
 }