/** * Prepares the data provider that should return the requested collection of the models. * @param string $id the primary key of the model. * @return ActiveDataProvider */ protected function prepareDataProvider($id) { if ($this->prepareDataProvider !== null) { return call_user_func($this->prepareDataProvider, $this); } return new ActiveDataProvider(['query' => $this->level && $this->level !== 1 ? MenuItem::find()->where(['menu_id' => $id])->andWhere(['<', 'depth', $this->level]) : MenuItem::find()->where(['menu_id' => $id])->roots()]); }
/** * @inheritdoc */ public function run() { $items = MenuItem::find()->where(['menu_id' => 1, 'status' => MenuItem::STATUS_ACTIVE])->with(['icon', 'activeIcon', 'video'])->all(); if ($items) { $items = TreeHelper::buildNodesTree($items); } return $this->render('menu/menu', ['widget' => $this, 'items' => $items]); }
/** * Prepares the data provider that should return the requested collection of the models. * @param string $id the primary key of the model. * @return ActiveDataProvider */ protected function prepareDataProvider($id) { if ($this->prepareDataProvider !== null) { return call_user_func($this->prepareDataProvider, $this); } $query = MenuItem::find()->where(['menu_id' => $id]); $data = \Yii::$app->getRequest()->getBodyParams(); $string = isset($data['string']) ? $data['string'] : ''; if ($this->searchableAttributes) { $condition = ['or']; foreach ($this->searchableAttributes as $attribute) { $condition[] = ['like', $attribute, $string]; } $query->andWhere($condition); /** @var $models MenuItem[] */ $models = $query->all(); foreach ($models as $model) { $query->union($model->parents()); } } return new ActiveDataProvider(['query' => $query]); }
/** * @inheritdoc */ public function run() { $items = MenuItem::find()->where(['menu_id' => 1, 'status' => MenuItem::STATUS_ACTIVE])->all(); $items = TreeHelper::buildNodesTree($items); return $this->render('menu/menu', ['widget' => $this, 'items' => $items, 'level' => 1]); }