Пример #1
0
 public function actionCreate($type = null)
 {
     $model = new Role();
     $model->type = $type;
     $model->setScenario('create');
     if ($model->load(Yii::$app->request->post(), 'Role') && $model->validate()) {
         if (RoleService::create($model)) {
             $binder = new Binder();
             $binder->binderId = $model->id;
             $binder->load(Yii::$app->request->post(), 'Binder');
             RoleService::bindPermissions($binder);
             return $this->redirect($this->returnUrl);
         }
     }
     $permissions = PermissionService::getIdNameListByType($type);
     return $this->render('create', ['model' => $model, 'permissions' => $permissions]);
 }
Пример #2
0
 /**
  * @return Role - from the mapping.
  */
 public function getRole()
 {
     return $this->hasOne(Role::className(), ['id' => 'roleId']);
 }
Пример #3
0
 /**
  * @return Role array
  */
 public function getRoles()
 {
     return $this->hasMany(Role::className(), ['id' => 'roleId'])->viaTable(CoreTables::TABLE_ROLE_PERMISSION, ['permissionId' => 'id']);
 }
Пример #4
0
 /**
  * @return Role - assigned to User.
  */
 public function getRole()
 {
     $roleTable = CoreTables::TABLE_ROLE;
     $siteTable = CoreTables::TABLE_SITE;
     $siteMemberTable = CoreTables::TABLE_SITE_MEMBER;
     return Role::find()->leftJoin($siteMemberTable, "{$siteMemberTable}.roleId = {$roleTable}.id")->leftJoin($siteTable, "{$siteTable}.id = {$siteMemberTable}.siteId")->where("{$siteMemberTable}.userId=:id AND {$siteTable}.name=:name", [':id' => $this->id, ':name' => Yii::$app->cmgCore->getSiteName()]);
 }
Пример #5
0
 /**
  * @param Role $role
  * @return Role
  */
 public static function create($role)
 {
     // Create Role
     $role->save();
     // Return Role
     return $role;
 }