/** * 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', '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; }
/** * Finds the MenuItem model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return MenuItem the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = MenuItem::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException(Yii::t('gromver.platform', 'The requested page does not exist.')); } }
/** * @param string $link * @return MenuItem */ public function getMenuByLink($link) { $menuId = array_search($link, $this->_links); return $menuId ? MenuItem::findOne($menuId) : null; }