public function afterSave($isNewRecord, $changedAttributes) { if ($isNewRecord) { if (isset($this->_groupRoleName)) { $userDomainRole = new UserDomainRole(); $userDomainRole->user_id = $this->id; $userDomainRole->domain = $this->_domain; $userDomainRole->_groupRoleName = $this->_groupRoleName; $userDomainRole->save(); } } return parent::afterSave($isNewRecord, $changedAttributes); }
public function actionCreateRoleSystem($id) { if (!self::can("user/create")) { if (!self::can("user/read")) { return $this->goHome(); } else { Yii::$app->getSession()->addFlash('warning', Yii::t('aaa', 'You are not allowed to create system roles')); return $this->redirect(array('/aaa/user/view', 'id' => $id)); } } $udr = new UserDomainRole(); $udr->user_id = $id; if (isset($_POST["UserDomainRole"])) { $form = $_POST["UserDomainRole"]; $udr->_groupRoleName = $form["_groupRoleName"]; $roleDomain = null; $alreadyHas = false; $roles = UserDomainRole::find()->where(['domain' => $udr->domain, 'user_id' => $udr->user_id])->all(); foreach ($roles as $role) { if ($role->getGroup()->role_name == $udr->_groupRoleName) { $alreadyHas = true; break; } } if ($alreadyHas) { Yii::$app->getSession()->setFlash("warning", Yii::t("aaa", 'The user already has this profile')); return $this->redirect(array('/aaa/user/view', 'id' => $id)); } else { if ($udr->save()) { AaaNotification::createRole($udr); Yii::$app->getSession()->setFlash("success", Yii::t("aaa", 'Role created successfully')); return $this->redirect(array('/aaa/user/view', 'id' => $id)); } else { foreach ($udr->getErrors() as $attribute => $error) { Yii::$app->getSession()->setFlash("error", $error[0]); } } } } $groups = []; foreach ($udr->getSystemGroupsNoArray() as $group) { $groups[$group->role_name] = $group->name; } return $this->renderPartial('_add-role-system', array('udr' => $udr, 'groups' => $groups)); }