Exemplo n.º 1
0
 /**
  * Updates an existing User model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $modelUser = $this->findModel($id);
     if (Yii::$app->request->post('User')) {
         //
         Role::deleteAll(['user_id' => $id]);
         if (Yii::$app->request->post('User')['item_name'] == '') {
             $sendRoles[] = 'Пользователь';
         } else {
             $sendRoles = Yii::$app->request->post('User')['item_name'];
         }
         //
         foreach ($sendRoles as $one) {
             $model = new Role();
             $model->item_name = $one;
             $model->user_id = $id;
             $model->created_at = time();
             $model->save();
         }
     }
     if ($modelUser->load(Yii::$app->request->post()) && $modelUser->save()) {
         return $this->redirect(['view', 'id' => $modelUser->id]);
     } else {
         $value = ArrayHelper::map($modelUser->role, "item_name", "item_name");
         $allRoles = [];
         foreach (AuthItem::getRoles() as $item_name) {
             if ($item_name->name != 'Создатель') {
                 $allRoles[$item_name->name] = $item_name->name;
             }
         }
         return $this->render('update', ['modelUser' => $modelUser, 'allRoles' => $allRoles, 'value' => $value]);
     }
 }
Exemplo n.º 2
0
 /**
  * Возвращает массив возможных ролей.
  * Примечание: используется в backend/user/index представлении.
  *
  * @return mixed
  */
 public static function getRolesList()
 {
     $roles = [];
     foreach (AuthItem::getRoles() as $item_name) {
         $roles[$item_name->name] = $item_name->name;
     }
     return $roles;
 }
Exemplo n.º 3
0
 /**
  * @return array
  */
 public static function getPermissions()
 {
     $permissions = [];
     foreach (AuthItem::getPermissions() as $permission) {
         $permissions[] = $permission->name;
     }
     return $permissions;
 }
Exemplo n.º 4
0
        <?php 
} else {
    ?>
            <?php 
    echo $form->field($user, 'password')->widget(PasswordInput::classname(), [])->passwordInput(['placeholder' => Yii::t('backend', 'New pwd ( if you want to change it )')]);
    ?>
        <?php 
}
?>
    <div class="row">
        <div class="col-lg-6">
            <?php 
echo $form->field($user, 'status')->dropDownList($user->statusList);
?>
            <?php 
foreach (AuthItem::getRoles() as $item_name) {
    ?>
                <?php 
    $roles[$item_name->name] = $item_name->name;
    ?>
            <?php 
}
?>
            <?php 
echo $form->field($role, 'item_name')->dropDownList($roles);
?>
        </div>
    </div>
    <div class="form-group"><?php 
echo Html::submitButton($user->isNewRecord ? Yii::t('backend', 'Create') : Yii::t('backend', 'Update'), ['class' => $user->isNewRecord ? 'btn btn-success' : 'btn btn-primary']);
echo Html::a(Yii::t('backend', 'Cancel'), ['user/index'], ['class' => 'btn btn-default']);
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getItemName()
 {
     return $this->hasOne(AuthItem::className(), ['name' => 'item_name']);
 }