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]);
 }
Esempio n. 2
0
 protected function launch()
 {
     if ($cache = $this->ensureCache()) {
         if ((list($items, $prevModel, $nextModel) = $cache->get([__CLASS__, $this->rootPage->id, $this->page->id])) === false) {
             list($items, $prevModel, $nextModel) = $this->getViewData();
             $cache->set([__CLASS__, $this->rootPage->id, $this->page->id], [$items, $prevModel, $nextModel], $this->cacheDuration, $this->cacheDependency ? $this->cacheDependency : DbState::dependency(Page::tableName()));
         }
     } else {
         list($items, $prevModel, $nextModel) = $this->getViewData();
     }
     echo $this->render($this->layout, ['model' => $this->page, 'rootModel' => $this->rootPage, 'items' => $items, 'prevModel' => $prevModel, 'nextModel' => $nextModel]);
 }
 /**
  * @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']));
 }
 public function behaviors()
 {
     return [['class' => 'yii\\filters\\HttpCache', 'only' => ['rss'], 'lastModified' => function () {
         return DbState::timestamp('{{%grom_post}}');
     }]];
 }
Esempio n. 5
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;
 }