Пример #1
0
 /**
  * @param JsonData $ids
  * @throws Exception
  */
 public function xGroupActionHandlerAction(JsonData $ids)
 {
     $this->request->restrictAccess('ROLES', 'MANAGE');
     $processed = array();
     $errors = array();
     if (count($ids) == 0) {
         throw new Exception('Empty id\'s list');
     }
     foreach (RoleCategory::find(['id' => ['$in' => $ids]]) as $category) {
         /* @var $category RoleCategory */
         if ($this->request->hasPermissions($category, true)) {
             if ($category->getUsed()) {
                 $errors[] = 'Role category is in use and can\'t be removed.';
             } else {
                 $processed[] = $category->id;
                 $category->delete();
             }
         } else {
             $errors[] = 'Insufficient permissions to remove Role Category';
         }
     }
     $num = count($ids);
     if (count($processed) == $num) {
         $this->response->success('Role Categories successfully removed');
     } else {
         array_walk($errors, function (&$item) {
             $item = '- ' . $item;
         });
         $this->response->warning(sprintf("Successfully removed %d from %d Role Categories. \nFollowing errors occurred:\n%s", count($processed), $num, join($errors, '')));
     }
     $this->response->data(array('processed' => $processed));
 }