public function safeDown() { AuthItemChild::deleteAll(['parent' => $this->getRoles()]); AuthItemChild::deleteAll(['child' => $this->getRoles()]); AuthItem::deleteAll(['name' => $this->getRoles()]); return true; }
public function down() { foreach ($this->getPermissions() as $role => $permissions) { AuthItemChild::deleteAll(['parent' => $role, 'child' => $permissions]); AuthItem::deleteAll(['name' => $permissions]); } return true; }
public function search($params) { $query = AuthItemChild::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['like', 'parent', $this->parent])->andFilterWhere(['like', 'child', $this->child]); return $dataProvider; }
/** * Callback for $this->menuWidget() method. * @param array $data data to process. * @return array processed data. */ public function menuCallback($data) { $contextMenu = ARTreeMenuWidget::this()->commonOptions()['contextmenu']; $contextMenu['items'] = ['create' => $contextMenu['items']['create'], 'delete' => $contextMenu['items']['delete']]; $data['options'] = ['types' => $this->types, 'contextmenu' => $contextMenu]; $items = AuthItem::find()->where(['type' => \yii\rbac\Item::TYPE_ROLE])->indexBy('name')->all(); $relations = AuthItemChild::find()->all(); $data['items'] = $this->generateTree($items, $relations); return $data; }
/** * @param bool $id * @throws NotFoundHttpException * @return AuthItemChild */ protected function findModel($id = false) { if (!$id) { $model = new AuthItemChild(); } else { if (!($model = AuthItemChild::findOne($id))) { throw new NotFoundHttpException('Model not found.'); } } return $model; }
/** * @return \yii\db\ActiveQuery */ public function getAuthItemChildren() { return $this->hasMany(AuthItemChild::className(), ['parent' => 'name']); }