Example #1
0
 /**
  * Displays a single Person model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     $name = ArrayHelper::getValue($model, 'user.assignment.itemName.name');
     $parent = AuthItemChild::find()->where(['child' => $name])->one();
     return $this->render('view', ['model' => $model, 'parent' => $parent]);
 }
 /**
  * Updates an existing AuthItem model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param string $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     $parent = AuthItemChild::find()->where(['child' => $model->name])->one();
     if (Yii::$app->request->isPost) {
         $oldRole = $model->name;
         if ($model->load(Yii::$app->request->post()) && $model->validate()) {
             $role = $this->auth->getRole($oldRole);
             if (empty($role)) {
                 Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Jabatan Gagal Diubah'));
             } else {
                 $role->name = $model->name;
                 $role->description = $model->description;
                 $role->data = Yii::$app->request->post('routers');
                 $role->ruleName = $model->rule_name;
                 $this->auth->update($oldRole, $role);
                 Yii::$app->getSession()->setFlash('success', Yii::t('app', 'Data Jabatan Berhasil Diubah'));
                 return $this->redirect(['index']);
             }
         } else {
             Yii::$app->getSession()->setFlash('error', Yii::t('app', 'Data Jabatan Gagal Diubah'));
         }
     }
     $routers = RouterGenerator::run();
     ksort($routers);
     $children = AuthItem::find()->all();
     $rule = AuthRule::find()->all();
     return $this->render('update', ['model' => $model, 'routers' => $routers, 'registeredRouters' => $this->auth->getRole($model->name), 'children' => $children, 'rule' => $rule, 'parent' => $parent]);
 }
Example #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAuthItemChildren0()
 {
     return $this->hasMany(AuthItemChild::className(), ['child' => 'name']);
 }