public function execute($user, $item, $params) { if (!Yii::$app->user->isGuest) { $group = Yii::$app->user->identity->role_id; // получаем id Модератора из таблицы Role $moder_id = Role::getIdByName('moderator'); // получаем id Писателя из таблицы Role $writer_id = Role::getIdByName('writer'); if ($item->name === 'moderator') { return $group == $moder_id; } elseif ($item->name === 'writer') { $role = Role::findOne(['name' => 'moderator']); return $group == $moder_id || $group == $writer_id; } } return FALSE; }
public function actionUpdateRole() { if ($this->isUpdateAllowed()) { if (Yii::$app->request->post()) { $role = Role::findOne(Yii::$app->request->get()['id']); $role->name = Yii::$app->request->post()['role']; $role->update(); $rowsDeleted = RoleModule::deleteAll('role = ' . Yii::$app->request->get()['id']); $roleModel = new Role(); $roleModel->updateRole(Yii::$app->request->get()['id'], Yii::$app->request->post()); /*return $this->render('role_list');*/ return $this->redirect(['security/role-management']); } return $this->render('update_role'); } else { echo "You don't have access here"; die; } }
/** * Finds the Role model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Role the loaded model * @throws HttpException if the model cannot be found */ protected function findModel($id) { if (($model = Role::findOne($id)) !== null) { return $model; } else { throw new HttpException(404, 'The requested page does not exist.'); } }
public static function getNameById($id) { $role = Role::findOne(['id' => $id]); return $role->name; }
public function actionParsingLog($id) { $mod = LogUpload::findOne($id); $type = $mod->type; $keys = \yii\helpers\Json::decode($mod->keys); $values = \yii\helpers\Json::decode($mod->values); $modelAttribute = new Role(); $not = Util::excelNot(); foreach ($values as $value) { if ($type == LogUpload::TYPE_INSERT) { $model = new Role(); } else { $model = Role::findOne($value['id']); } foreach ($keys as $v) { $model->{$v} = $value[$v]; } $e = 0; if ($model->save()) { $model = NULL; $pos = NULL; } else { $error[] = \yii\helpers\Json::encode($model->getErrors()); $e = 1; } } if ($error) { foreach ($error as $err) { if ($err) { $er[] = $err; $e += 1; } } if ($e) { $mod->warning = \yii\helpers\Json::encode($er); $mod->save(); echo '<pre>'; print_r($er); } } }
public function getRoleName($roleId) { return Role::findOne($roleId)->name; }