Skip to content

Commit

Permalink
fix: form fixes in user edit (#166)
Browse files Browse the repository at this point in the history
  • Loading branch information
ByteCarlos authored Feb 16, 2023
1 parent 6606b8c commit e1b73de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
17 changes: 9 additions & 8 deletions app/controllers/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,18 +480,19 @@ public function actionUpdate($id) {
$model->password = $password;
if ($model->save()) {
$save = TRUE;
foreach ($userSchools as $school) {
UsersSchool::model()->deleteAll(array("condition"=>"school_fk='$school->school_fk'"));
}
foreach ($_POST['schools'] as $school) {
$userSchool = UsersSchool::model()->findByAttributes(array('school_fk' => $school, 'user_fk' => $model->id));
if( $userSchool == null) {
$userSchool = new UsersSchool;
$userSchool->user_fk = $model->id;
$userSchool->school_fk = $school;
$save = $save && $userSchool->validate() && $userSchool->save();
}
$userSchool = new UsersSchool;
$userSchool->user_fk = $model->id;
$userSchool->school_fk = $school;
$save = $save && $userSchool->validate() && $userSchool->save();

}
if ($save) {
$auth = Yii::app()->authManager;
$auth->revoke($_POST['Role'], $model->id);
$auth->revoke($actual_role, $model->id);
$auth->assign($_POST['Role'], $model->id);
Yii::app()->user->setFlash('success', Yii::t('default', 'Usuário alterado com sucesso!'));
$this->redirect(['index']);
Expand Down
2 changes: 1 addition & 1 deletion app/models/Users.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function attributeLabels()
'name' => Yii::t('default', 'Name'),
'username' => Yii::t('default', 'Username'),
'password' => Yii::t('default', 'Password'),
'active' => 'Active',
'active' => Yii::t('default', 'Active'),
);
}

Expand Down

0 comments on commit e1b73de

Please # to comment.