Esempio n. 1
0
 /**
  * @inheritdoc
  */
 public function bootstrap($app)
 {
     $app->set($this->id, $this);
     $this->_moduleConfigDependency = new ExpressionDependency(['expression' => '\\Yii::$app->getModulesHash()']);
     DbState::bootstrap();
     Yii::$container->set('gromver\\models\\fields\\EditorField', ['controller' => 'grom/media/manager', 'editorOptions' => ['filebrowserBrowseUrl' => ['/grom/menu/backend/item/ckeditor-select'], 'extraPlugins' => 'codesnippet']]);
     Yii::$container->set('gromver\\models\\fields\\MediaField', ['controller' => 'grom/media/manager']);
     Yii::$container->set('gromver\\modulequery\\ModuleQuery', ['cache' => $app->cache, 'cacheDependency' => $this->_moduleConfigDependency]);
     Yii::$container->set('gromver\\platform\\basic\\components\\MenuMap', ['cache' => $app->cache, 'cacheDependency' => DbState::dependency(MenuItem::tableName())]);
     Yii::$container->set('gromver\\platform\\basic\\components\\MenuUrlRule', ['cache' => $app->cache, 'cacheDependency' => $this->_moduleConfigDependency]);
     Yii::$container->set('gromver\\platform\\basic\\modules\\main\\widgets\\Desktop', ['cache' => $app->cache, 'cacheDependency' => $this->_moduleConfigDependency]);
     /** @var MenuManager $manager */
     $rules['auth'] = 'grom/auth/default/login';
     $rules['admin'] = 'grom/backend/default/index';
     if (is_array($this->blockedUrlRules) && count($this->blockedUrlRules)) {
         foreach ($this->blockedUrlRules as $rule) {
             $rules[$rule] = 'grom/default/page-not-found';
             //блокируем доступ напрямую
         }
     }
     $app->urlManager->addRules($rules, false);
     //вставляем в начало списка
     $app->set('menuManager', \Yii::createObject(MenuManager::className()));
     // пропускаем \gromver\models\fields\events\ListItemsEvent событие, через ModuleEvent - не факт, что нужно, но почему бы и нет
     Event::on('\\gromver\\models\\fields\\ListField', 'fetchItems', function ($event) {
         /** @var $event \gromver\models\fields\events\ListItemsEvent */
         ModuleEvent::trigger(self::EVENT_FETCH_LIST_ITEMS, new ListItemsModuleEvent(['sender' => $event]));
     });
     ModuleQuery::instance()->implement('\\gromver\\platform\\common\\interfaces\\BootstrapInterface')->invoke('bootstrap', [$app]);
 }
 /**
  * @return Response
  */
 public function actionOrdering()
 {
     $data = Yii::$app->request->getBodyParam('data', []);
     foreach ($data as $id => $order) {
         if ($target = MenuItem::findOne($id)) {
             $target->updateAttributes(['ordering' => intval($order)]);
         }
     }
     MenuItem::find()->roots()->one()->reorderNode('ordering');
     DbState::updateState(MenuItem::tableName());
     return $this->redirect(ArrayHelper::getValue(Yii::$app->request, 'referrer', ['index']));
 }
Esempio n. 3
0
 /**
  * @return array
  */
 public function getItems()
 {
     if (!isset($this->_items)) {
         if ($cache = $this->ensureCache()) {
             $cacheKey = [__CLASS__, $this->type, $this->activateItems, $this->activateParents, $this->language];
             if (($this->_items = $cache->get($cacheKey)) === false) {
                 $this->_items = $this->items();
                 $cache->set($cacheKey, $this->_items, $this->cacheDuration, $this->cacheDependency ? $this->cacheDependency : DbState::dependency(MenuItem::tableName()));
             }
         } else {
             $this->_items = $this->items();
         }
     }
     return $this->_items;
 }