Exemplo n.º 1
0
 /**
  * @param Category $category
  * @return bool
  */
 public function canDelete(Category $category)
 {
     if ($this->user instanceof Organization) {
         return false;
     }
     if ($this->user->getIsAdmin()) {
         return true;
     }
     if (!$this->user->getIsReadOnly()) {
         $permissions = new Permissions();
         foreach ($category->getPermissions() as $value) {
             if ($value->getType() == 1) {
                 $permissions = $value;
             }
         }
         if ($permissions->getDelete()) {
             return true;
         }
         foreach ($category->getPermissions() as $value) {
             if ($value->getType() == 2) {
                 foreach ($this->memberships as $membership) {
                     if ($value->getOrganization() == $membership->getOrganization()) {
                         $permissions = $value;
                         if ($permissions->getDelete()) {
                             return true;
                         }
                     }
                 }
             }
             if ($value->getType() == 3) {
                 if ($value->getUser() == $this->user) {
                     $permissions = $value;
                     if ($permissions->getDelete()) {
                         return true;
                     }
                 }
             }
         }
     }
 }