Beispiel #1
0
 /**
  * Updates a particular model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * param integer $id the ID of the model to be updated
  */
 public function actionUpdateUser()
 {
     Yii::log("actionUpdate called", "trace", self::LOG_CAT);
     if (isset($_GET['userId'])) {
         $model = Users::model()->findByAttributes(array('userId' => $_GET['userId']));
         if ($model === null) {
             Yii::app()->user->setFlash('error', Yii::t("translation", "The user does not exist"));
             $this->redirect(array('users/index'));
         }
         $role = UsersHasRoles::model()->findByAttributes(array('users_id' => $_GET['userId']));
         $model->roles = $role->roles_id;
         if (isset($_POST['Users'])) {
             $model->attributes = $_POST['Users'];
             $model->roles = $_POST['Users']['roles'];
             if ($model->update() && $model->saveRoles($_GET['userId'], 'update')) {
                 Yii::app()->user->setFlash('success', Yii::t("translation", "User successfully updated"));
                 $this->redirect(array('users/index'));
             }
         }
         $this->render('update', array('model' => $model));
     } else {
         Yii::log("User not selected", "warning", self::LOG_CAT);
         Yii::app()->user->setFlash('error', Yii::t("translation", "Please select a user to edit"));
         $this->redirect(array('users/index'));
     }
 }
Beispiel #2
0
 /**
  * saveRoles
  * @param string $userId
  * @param string $action
  * @return boolean
  */
 public function saveRoles($userId, $action)
 {
     $roles = new UsersHasRoles();
     if ($action == 'create') {
         $roles->users_id = $userId;
         $roles->roles_id = $this->roles;
         return $roles->save();
     } else {
         $updateRole = UsersHasRoles::model()->findByAttributes(array('users_id' => $userId));
         $updateRole->roles_id = $this->roles;
         return $updateRole->update();
     }
 }