示例#1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MenuItem::find()->noRoots();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'menu_type_id' => $this->menu_type_id, 'parent_id' => $this->parent_id, 'status' => $this->status, 'link_type' => $this->link_type, 'secure' => $this->secure, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by, 'lft' => $this->lft, 'rgt' => $this->rgt, 'level' => $this->level, 'ordering' => $this->ordering, 'hits' => $this->hits, 'lock' => $this->lock]);
     $query->andFilterWhere(['like', 'language', $this->language])->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'path', $this->path])->andFilterWhere(['like', 'note', $this->note])->andFilterWhere(['like', 'link', $this->link])->andFilterWhere(['like', 'link_params', $this->link_params])->andFilterWhere(['like', 'layout_path', $this->layout_path])->andFilterWhere(['like', 'access_rule', $this->access_rule])->andFilterWhere(['like', 'metakey', $this->metakey])->andFilterWhere(['like', 'metadesc', $this->metadesc])->andFilterWhere(['like', 'robots', $this->robots]);
     return $dataProvider;
 }
示例#2
0
 public function init()
 {
     parent::init();
     if (empty($this->type)) {
         throw new InvalidConfigException(Yii::t('gromver.platform', 'Menu type must be set.'));
     }
     $this->language or $this->language = Yii::$app->language;
     $this->_rawItems = Yii::$app->db->cache(function ($db) {
         return MenuItem::find()->type($this->type)->published()->language($this->language)->asArray()->orderBy('lft')->all($db);
     }, $this->cacheDuration, Table::dependency(MenuItem::tableName()));
     $i = 0;
     $this->_items = $this->prepareMenuItems($i, 2);
 }
示例#3
0
 private function createMap()
 {
     $items = MenuItem::find()->published()->language($this->language)->asArray()->all();
     foreach ($items as $item) {
         if ($item['link_type'] == MenuItem::LINK_ROUTE) {
             $this->_paths[$item['id']] = $item['path'];
             $this->_routes[$item['id']] = $item['link'];
             if ($item['status'] == MenuItem::STATUS_MAIN_PAGE) {
                 $this->_mainPagePath = $item['path'];
             }
         } else {
             $this->_links[$item['id']] = $item['link'];
         }
     }
 }
示例#4
0
 public function actionTypeItems($update_item_id = null, $selected = '')
 {
     if (isset($_POST['depdrop_parents'])) {
         $parents = $_POST['depdrop_parents'];
         if ($parents != null) {
             $typeId = $parents[0];
             $language = $parents[1];
             //исключаем редактируемый пункт и его подпункты из списка
             if (!empty($update_item_id) && ($updateItem = MenuItem::findOne($update_item_id))) {
                 $excludeIds = array_merge([$update_item_id], $updateItem->descendants()->select('id')->column());
                 //если выбранный тип меню совпадает с типом меню редактируемого пункта, выбираем текущее значение родительского элемента
                 $selected = $updateItem->menu_type_id == $typeId ? $updateItem->parent_id : '';
             } else {
                 $excludeIds = [];
             }
             $out = array_map(function ($value) {
                 return ['id' => $value['id'], 'name' => str_repeat(" • ", $value['level'] - 1) . $value['title']];
             }, MenuItem::find()->noRoots()->type($typeId)->language($language)->orderBy('lft')->andWhere(['not in', 'id', $excludeIds])->asArray()->all());
             /** @var MenuItem $root */
             $root = MenuItem::find()->roots()->one();
             array_unshift($out, ['id' => $root->id, 'name' => Yii::t('gromver.platform', 'Root')]);
             echo Json::encode(['output' => $out, 'selected' => $selected ? $selected : $root->id]);
             return;
         }
     }
     echo Json::encode(['output' => '', 'selected' => $selected]);
 }