예제 #1
0
파일: MenuMap.php 프로젝트: oakcms/oakcms
 private function createMap()
 {
     $items = MenuItem::find()->published()->language($this->language)->orderBy('link_weight ASC')->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'];
         } else {
             $this->_links[$item['id']] = $item['link'];
         }
     }
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = MenuItem::find();
     $query->with(['menuType']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['lft' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         if ($this->excludeRoots) {
             $query->excludeRoots();
         }
         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]);
     if ($this->excludeRoots) {
         $query->excludeRoots();
     }
     if ($this->excludeItem && ($item = MenuItem::findOne($this->excludeItem))) {
         /** @var $item MenuItem */
         $query->excludeItem($item);
     }
     return $dataProvider;
 }
예제 #3
0
 /**
  * todo remove
  * @param null $update_item_id
  * @param string $selected
  */
 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->children()->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()->excludeRoots()->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]);
 }
예제 #4
0
파일: Menu.php 프로젝트: oakcms/oakcms
 /**
  * @return array
  */
 protected function items()
 {
     $rawItems = MenuItem::find()->type($this->type)->published()->language($this->language)->orderBy('lft')->all();
     if (count($rawItems)) {
         return $this->prepareItems($rawItems, $rawItems[0]->level);
     }
     return [];
 }