Пример #1
0
 /**
  * @return array
  */
 public function getItems()
 {
     if (!isset($this->_items)) {
         if ($cache = $this->ensureCache()) {
             $cacheKey = [__CLASS__, $this->type, $this->activateItems, $this->activateParents];
             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;
 }
Пример #2
0
 /**
  * @inheritdoc
  */
 public function init()
 {
     //$this->initI18N();
     //$this->bootstrap = array_merge($this->bootstrap, ['main']);
     parent::init();
     $this->_modulesConfigDependency = new ExpressionDependency(['expression' => '\\Yii::$app->getModulesHash()']);
     DbState::bootstrap();
     Yii::$container->set('gromver\\models\\fields\\EditorField', ['controller' => 'media/manager', 'editorOptions' => ['filebrowserBrowseUrl' => ['/menu/backend/item/ckeditor-select'], 'autoGrow_onStartup' => true, 'autoGrow_bottomSpace' => 50]]);
     Yii::$container->set('gromver\\models\\fields\\MediaField', ['controller' => 'media/manager']);
     Yii::$container->set('gromver\\modulequery\\ModuleQuery', ['cache' => $this->cache, 'cacheDependency' => $this->_modulesConfigDependency]);
     Yii::$container->set('gromver\\platform\\core\\components\\MenuMap', ['cache' => $this->cache, 'cacheDependency' => DbState::dependency(MenuItem::tableName())]);
     Yii::$container->set('gromver\\platform\\core\\components\\MenuUrlRule', ['cache' => $this->cache, 'cacheDependency' => $this->_modulesConfigDependency]);
     Yii::$container->set('gromver\\platform\\core\\modules\\main\\widgets\\Desktop', ['cache' => $this->cache, 'cacheDependency' => $this->_modulesConfigDependency]);
     Yii::$container->set('gromver\\platform\\core\\components\\ParamsManager', ['cache' => $this->cache, 'cacheDependency' => $this->_modulesConfigDependency]);
     $this->urlManager->addRules($this->defaultUrlRules);
     $this->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 */
         $additionalItems = @$this->listFieldItems[$event->model->getSourceClass() . '::' . $event->attribute];
         if (is_array($additionalItems)) {
             $event->items = array_merge($event->items, $additionalItems);
         }
     });
     $this->applyDefaultMetadata();
 }
Пример #3
0
 /**
  * @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']));
 }