/** * Get list of link siblings * @return array */ public function getSiblings() { $siblings = MenuLink::find()->joinWith('translations')->andFilterWhere(['like', 'menu_id', $this->menu_id])->andFilterWhere(['!=', 'menu_link.id', $this->id])->all(); $list = ArrayHelper::map($siblings, 'id', function ($array, $default) { return $array->label . ' [' . $array->id . ']'; }); return ArrayHelper::merge([NULL => Yii::t('yee', 'No Parent')], $list); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params = []) { $queryParams = Yii::$app->request->getQueryParams(); $query = MenuLink::find()->joinWith('translations'); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => -1], 'sort' => ['defaultOrder' => ['order' => SORT_ASC]]]); $this->load($queryParams); foreach ($params as $key => $value) { $this->{$key} = $value; } $restrictLinkAccess = YeeHelper::isImplemented(MenuLink::className(), OwnerAccess::CLASSNAME) && !User::hasPermission(MenuLink::getFullAccessPermission()); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } if ($restrictLinkAccess) { $query->andFilterWhere([MenuLink::getOwnerField() => Yii::$app->user->identity->id]); } $query->andWhere(['menu_id' => $this->menu_id])->andFilterWhere(['alwaysVisible' => $this->alwaysVisible])->andFilterWhere(['like', 'id', $this->id])->andWhere(['parent_id' => $this->parent_id]); return $dataProvider; }