Example #1
0
 public function actionPermission($id)
 {
     $groupName = YiiForum::getGetValue('group');
     $model = $this->findModel($id);
     $existPermissions = $this->getCachedRoles($id)['permissions'];
     if (YiiForum::hasPostValue('submit')) {
         $parent = new Role();
         $parent->name = $id;
         $allPermissions = $this->getCachedPermissions();
         $selectedPermissions = YiiForum::getPostValue('selectedPermissions');
         $this->updatePermissions($allPermissions, $selectedPermissions, $existPermissions, $parent, new Permission());
         AuthItem::createCachedRoles();
         return $this->redirect(['index', 'group' => $groupName]);
     } else {
         $allPermissions = [];
         $categories = $this->getCachedPermissionCategories();
         foreach ($categories as $category) {
             $allPermissions[$category['description']] = $this->getCachedPermissionsByCategory($category['name']);
         }
         $locals = [];
         $locals['currentGroup'] = $groupName;
         $locals['model'] = $model;
         $locals['allPermissions'] = $allPermissions;
         $locals['existPermissions'] = $existPermissions;
         return $this->render('permission', $locals);
     }
 }
 public function actionRole($id)
 {
     $auth = \Yii::$app->authManager;
     $existItems = $auth->getAssignments($id);
     $model = [];
     if (YiiForum::hasPostValue('submit')) {
         $allRoles = $this->getCachedRoles();
         $selectedRoles = YiiForum::getPostValue('selectedRoles');
         $this->updateAssignments($allRoles, $selectedRoles, $existItems, $id);
         return $this->redirect(['index']);
     } else {
         $allRoles = [];
         $groups = $this->getCachedRoleGroups();
         foreach ($groups as $group) {
             $allRoles[$group['description']] = $this->getCachedRolesByGroup($group['name']);
         }
         $locals = [];
         $locals['model'] = $model;
         $locals['allRoles'] = $allRoles;
         $locals['existRoles'] = $existItems;
         return $this->render('role', $locals);
     }
 }