/** * 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); }
public function actionSaveOrders() { if (Yii::$app->getRequest()->isAjax) { $n = 1; $params = []; $select = []; $db = Yii::$app->db; $settings = Yii::$app->getRequest()->post('settings'); foreach ($settings as $setting) { $select[] = "SELECT :id_{$n} as 'id', :order_{$n} as 'order', :parent_{$n} as 'parent_id'"; $params[":id_{$n}"] = $setting[0]; $params[":order_{$n}"] = (int) $setting[1]; $params[":parent_{$n}"] = isset($setting[2]) ? $setting[2] : ''; $n++; } $select = implode(' UNION ', $select); $menuLinkTable = MenuLink::tableName(); $db->createCommand("UPDATE {$menuLinkTable} m INNER JOIN ({$select})t ON m.id=t.id " . " SET m.order=t.order, m.parent_id=t.parent_id", $params)->execute(); } return false; }
/** * 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; }
/** * @return \omgdef\multilingual\MultilingualQuery */ public function getLinks() { return $this->hasMany(MenuLink::className(), ['menu_id' => 'id'])->joinWith('translations'); }