/**
  * @see ProjectPermissionOrganisationUnitInterface::delete()
  * @return bool
  * @throws ProjectPermissionOrganisationUnitDeleteException
  * @throws ProjectPermisisonOrganisationUnitDeleteVirtualFolderException
  */
 public function delete()
 {
     global $transaction;
     if ($this->permission_id and $this->project_permission) {
         $transaction_id = $transaction->begin();
         $project_id = $this->project_permission->get_project_id();
         $project_folder_id = ProjectFolder::get_folder_by_project_id($project_id);
         $permission_string = strrev(decbin($this->project_permission->get_permission()));
         if (ProjectPermission_Access::count_entries_with_project_id_and_organisation_unit_id($project_id, $this->project_permission->get_organisation_unit_id()) <= 1) {
             $folder_id = OrganisationUnitFolder::get_folder_by_organisation_unit_id($this->project_permission->get_organisation_unit_id());
             $virtual_folder = new VirtualFolder(null);
             $virtual_folder_array = $virtual_folder->list_entries_by_folder_id($folder_id);
             foreach ($virtual_folder_array as $key => $value) {
                 $virtual_folder = new ProjectVirtualFolder($value);
                 if ($virtual_folder->is_project_vfolder() == true) {
                     $virtual_folder_id = $value;
                 }
             }
             if ($virtual_folder_id) {
                 $virtual_folder = new VirtualFolder($virtual_folder_id);
                 if ($virtual_folder->unlink_folder($project_folder_id) == false) {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     throw new ProjectPermissionOrganisationUnitDeleteVirtualFolderException();
                 }
             }
         }
         if (parent::delete() == true) {
             if ($transaction_id != null) {
                 $transaction->commit($transaction_id);
             }
             return true;
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             throw new ProjectPermissionOrganisationUnitDeleteException();
         }
     } else {
         throw new ProjectPermissionOrganisationUnitDeleteException();
     }
 }
예제 #2
0
 /**
  * @see ProjectPermissionInterface::set_permission()
  * @param integer $permission
  * @return bool
  */
 public function set_permission($permission)
 {
     if (is_numeric($permission) and $this->project_permission and $this->permission_id) {
         if (($user_id = $this->project_permission->get_user_id()) != null) {
             $current_permission_string = strrev(decbin($this->project_permission->get_permission()));
             $new_permission_string = strrev(decbin($permission));
             $project_folder_id = ProjectFolder::get_folder_by_project_id($this->project_permission->get_project_id());
             if ($current_permission_string[2] == 0 and $current_permission_string[3] == 0 and $current_permission_string[7] == 0) {
                 $folder_id = UserFolder::get_folder_by_user_id($user_id);
                 $virtual_folder = new VirtualFolder(null);
                 $virtual_folder_array = $virtual_folder->list_entries_by_folder_id($folder_id);
                 foreach ($virtual_folder_array as $key => $value) {
                     $virtual_folder = new ProjectVirtualFolder($value);
                     if ($virtual_folder->is_project_vfolder() == true) {
                         $virtual_folder_id = $value;
                     }
                 }
                 if (is_numeric($virtual_folder_id)) {
                     $virtual_folder = new VirtualFolder($virtual_folder_id);
                     if ($virtual_folder->link_folder($project_folder_id) == false) {
                         if ($transaction_id != null) {
                             $transaction->rollback($transaction_id);
                         }
                         return null;
                     }
                 }
             }
         }
         return $this->project_permission->set_permission($permission);
     } else {
         return false;
     }
 }
 /**
  * @see EventListenerInterface::listen_events()
  * @param object $event_object
  * @return bool
  */
 public static function listen_events($event_object)
 {
     if ($event_object instanceof UserFolderCreateEvent or $event_object instanceof GroupFolderCreateEvent or $event_object instanceof OrganisationUnitFolderCreateEvent) {
         $project_virtual_folder = new ProjectVirtualFolder(null);
         if (($virtual_folder_id = $project_virtual_folder->create($event_object->get_folder_id(), "projects")) == null) {
             return false;
         }
         $project_virtual_folder = new ProjectVirtualFolder($virtual_folder_id);
         if ($project_virtual_folder->set_project_vfolder() == false) {
             return false;
         }
     }
     if ($event_object instanceof VirtualFolderDeleteEvent) {
         $project_virtual_folder = new ProjectVirtualFolder($event_object->get_virtual_folder_id());
         if ($project_virtual_folder->is_project_vfolder() == true) {
             $virtual_folder_is_project = new VirtualFolderIsProject_Access($event_object->get_virtual_folder_id());
             if ($virtual_folder_is_project->delete() == false) {
                 return false;
             }
         }
     }
     return true;
 }