Ejemplo n.º 1
0
 /**
  * @see DataBrowserInterface::count_data_browser_array()
  * @param integer $folder_id
  * @param integer $virtual_folder_id
  * @return integer
  */
 public static function count_data_browser_array($folder_id, $virtual_folder_id)
 {
     global $user;
     if ($folder_id and !$virtual_folder_id or !$folder_id and !$virtual_folder_id) {
         if ($folder_id == null) {
             $new_folder_id = UserFolder::get_folder_by_user_id($user->get_user_id());
             if ($new_folder_id != null) {
                 self::$folder_id = $new_folder_id;
             } else {
                 // Exception
             }
         } else {
             self::$folder_id = $folder_id;
         }
         $folder = Folder::get_instance(self::$folder_id);
         return Data_Wrapper_Access::count_list_data_entity_childs($folder->get_data_entity_id());
     } elseif (!$folder_id and $virtual_folder_id) {
         $virtual_folder = new VirtualFolder($virtual_folder_id);
         return Data_Wrapper_Access::count_list_data_entity_childs($virtual_folder->get_data_entity_id());
     } else {
         // Exception
     }
 }
 /**
  * @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 or $event_object instanceof SampleFolderCreateEvent or $event_object instanceof ProjectFolderCreateEvent) {
         $sample_virtual_folder = new SampleVirtualFolder(null);
         if (($virtual_folder_id = $sample_virtual_folder->create($event_object->get_folder_id(), "samples")) == null) {
             return false;
         }
         $sample_virtual_folder = new SampleVirtualFolder($virtual_folder_id);
         if ($sample_virtual_folder->set_sample_vfolder() == false) {
             return false;
         }
     }
     if ($event_object instanceof VirtualFolderDeleteEvent) {
         $sample_virtual_folder = new SampleVirtualFolder($event_object->get_virtual_folder_id());
         if ($sample_virtual_folder->is_sample_vfolder() == true) {
             $virtual_folder_is_sample = new VirtualFolderIsSample_Access($event_object->get_virtual_folder_id());
             if ($virtual_folder_is_sample->delete() == false) {
                 return false;
             }
         }
     }
     if ($event_object instanceof SampleItemLinkEvent or $event_object instanceof ProjectItemLinkEvent) {
         if (($sample_id = Sample::get_entry_by_item_id($event_object->get_item_id())) != null) {
             $sample_folder_id = SampleFolder::get_folder_by_sample_id($sample_id);
             $folder = Folder::get_instance($event_object->get_folder_id());
             $child_array = $folder->get_children();
             if (is_array($child_array) and count($child_array) >= 1) {
                 foreach ($child_array as $key => $value) {
                     if (($virtual_folder_id = VirtualFolder::get_virtual_folder_id_by_data_entity_id($value)) != null) {
                         $sample_virtual_folder = new SampleVirtualFolder($virtual_folder_id);
                         if ($sample_virtual_folder->is_sample_vfolder() == true) {
                             if ($sample_virtual_folder->link_folder($sample_folder_id) == false) {
                                 return false;
                             }
                         }
                     }
                 }
             }
         }
     }
     return true;
 }
 /**
  * @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();
     }
 }
Ejemplo n.º 4
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;
     }
 }
Ejemplo n.º 5
0
 /**
  * @see SampleSecurityInterface::delete_organisation_unit()
  * @param integer $entry_id
  * @return bool
  */
 public function delete_organisation_unit($entry_id)
 {
     global $transaction;
     if ($this->sample_id and is_numeric($entry_id)) {
         $transaction_id = $transaction->begin();
         $sample_has_organisation_unit = new SampleHasOrganisationUnit_Access($entry_id);
         $organisation_unit_id = $sample_has_organisation_unit->get_organisation_unit_id();
         $success = $sample_has_organisation_unit->delete();
         if ($success == true) {
             $sample_folder_id = SampleFolder::get_folder_by_sample_id($this->sample_id);
             $folder_id = OrganisationUnitFolder::get_folder_by_organisation_unit_id($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 SampleVirtualFolder($value);
                 if ($virtual_folder->is_sample_vfolder() == true) {
                     $virtual_folder_id = $value;
                 }
             }
             if ($virtual_folder_id) {
                 $virtual_folder = new VirtualFolder($virtual_folder_id);
                 if ($virtual_folder->unlink_folder($sample_folder_id) == false) {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             }
             $organisation_unit = new OrganisationUnit($organisation_unit_id);
             $group_array = $organisation_unit->list_groups();
             if (is_array($group_array) and count($group_array) >= 1) {
                 foreach ($group_array as $key => $value) {
                     $folder_id = GroupFolder::get_folder_by_group_id($value);
                     $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 SampleVirtualFolder($value);
                         if ($virtual_folder->is_sample_vfolder() == true) {
                             $virtual_folder_id = $value;
                         }
                     }
                     if (is_numeric($virtual_folder_id)) {
                         $virtual_folder = new VirtualFolder($virtual_folder_id);
                         if ($virtual_folder->unlink_folder($sample_folder_id) == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         }
                     }
                 }
             }
             if ($transaction_id != null) {
                 $transaction->commit($transaction_id);
             }
             return true;
         } else {
             if ($transaction_id != null) {
                 $transaction->rollback($transaction_id);
             }
             return false;
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 6
0
 /**
  * @see DataPathInterface::get_stack_path()
  * @return string
  */
 public function get_stack_path()
 {
     if ($this->check_stack() == true or $this->path == null) {
         $return_string = "";
         foreach ($this->path_stack_array as $key => $value) {
             if ($value['virtual'] == false) {
                 if ($value['id'] != 1) {
                     $folder = Folder::get_instance($value['id']);
                     $return_string = $return_string . "/" . $folder->get_name();
                 }
             } else {
                 $virtual_folder = new VirtualFolder($value['id']);
                 $return_string = $return_string . "/<span class='underline'>" . $virtual_folder->get_name() . "</span>";
             }
         }
         return $return_string;
     } else {
         return $this->get_path();
     }
 }
Ejemplo n.º 7
0
 /**
  * @see FolderInterface::delete()
  * @param bool $recursive
  * @param bool $content
  * @return bool
  */
 public function delete($recursive, $content)
 {
     global $transaction;
     if ($this->folder_id and $this->folder) {
         $transaction_id = $transaction->begin();
         $subfolder_array = $this->get_subfolder_array();
         if (is_array($subfolder_array) and $recursive == false or $content == false and $recursive == true) {
             return false;
         } else {
             if ($recursive == true and $content == true) {
                 if (is_array($subfolder_array)) {
                     foreach ($subfolder_array as $key => $value) {
                         $folder = Folder::get_instance($value);
                         if ($folder->delete(true, true) == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         } else {
                             if ($transaction_id != null) {
                                 // Avoids Ghost-Folders
                                 $transaction->commit($transaction_id);
                                 $transaction_id = $transaction->begin();
                             }
                         }
                     }
                 }
             }
             // Folder-Content
             $data_entity_array = $this->get_children("without_linked");
             if (is_array($data_entity_array) and count($data_entity_array) >= 1) {
                 foreach ($data_entity_array as $key => $value) {
                     // Files
                     if (($file_id = File::get_file_id_by_data_entity_id($value)) != null) {
                         $file = File::get_instance($file_id);
                         $file_delete = $file->delete();
                         if ($file_delete == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         } else {
                             if ($transaction_id != null) {
                                 // Avoids Ghost-Files
                                 $transaction->commit($transaction_id);
                                 $transaction_id = $transaction->begin();
                             }
                         }
                     }
                     // Values
                     if (($value_id = Value::get_value_id_by_data_entity_id($value)) != null) {
                         $value_obj = Value::get_instance($value_id);
                         if ($value_obj->delete() == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         }
                     }
                     // Virtual Folders
                     if (($virtual_folder_id = VirtualFolder::get_virtual_folder_id_by_data_entity_id($value)) != null) {
                         $virtual_folder = new VirtualFolder($virtual_folder_id);
                         if ($virtual_folder->delete() == false) {
                             if ($transaction_id != null) {
                                 $transaction->rollback($transaction_id);
                             }
                             return false;
                         }
                     }
                 }
             }
             // Linked Folder-Content (e.g. from sub-items)
             $data_entity_array = $this->get_children("linked_only");
             if (is_array($data_entity_array) and count($data_entity_array) >= 1) {
                 foreach ($data_entity_array as $key => $value) {
                     if ($this->unset_child($value) == false) {
                         if ($transaction_id != null) {
                             $transaction->rollback($transaction_id);
                         }
                         return false;
                     }
                 }
             }
             $path = constant("BASE_DIR") . "/" . $this->folder->get_path();
             if (file_exists($path)) {
                 $garbage_file_array = scandir($path);
                 if (is_array($garbage_file_array) and count($garbage_file_array) >= 3) {
                     foreach ($garbage_file_array as $key => $value) {
                         if ($key != 0 and $key != 1) {
                             unlink($path . "/" . $value);
                         }
                     }
                 }
             }
             $linked_virtual_folder_array = $this->get_parent_virtual_folders();
             if (is_array($linked_virtual_folder_array) and count($linked_virtual_folder_array)) {
                 foreach ($linked_virtual_folder_array as $key => $value) {
                     if ($this->unset_child_of($value) == false) {
                         if ($transaction_id != null) {
                             $transaction->rollback($transaction_id);
                         }
                         return false;
                     }
                 }
             }
             if (parent::delete() == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
             $folder_delete_event = new FolderDeleteEvent($folder_id);
             $event_handler = new EventHandler($folder_delete_event);
             if ($event_handler->get_success() == false) {
                 if ($transaction_id != null) {
                     $transaction->rollback($transaction_id);
                 }
                 return false;
             }
             if (file_exists($path)) {
                 if (rmdir($path)) {
                     if ($this->folder->delete() == true) {
                         if ($transaction_id != null) {
                             $transaction->commit($transaction_id);
                         }
                         return true;
                     } else {
                         if ($transaction_id != null) {
                             $transaction->rollback($transaction_id);
                         }
                         return false;
                     }
                 } else {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             } else {
                 if ($this->folder->delete() == true) {
                     if ($transaction_id != null) {
                         $transaction->commit($transaction_id);
                     }
                     return true;
                 } else {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             }
         }
     } else {
         return false;
     }
 }
Ejemplo n.º 8
0
 /**
  * @see DataEntityInterface::get_parent_virtual_folder_ids()
  * @return array
  */
 public final function get_parent_virtual_folder_ids()
 {
     if ($this->data_entity_id) {
         $parent_array = DataEntityHasDataEntity_Access::list_data_entity_pid_by_data_entity_cid($this->data_entity_id);
         $result_array = array();
         if (count($parent_array) >= 1) {
             foreach ($parent_array as $key => $value) {
                 if (($virtual_folder_id = VirtualFolder::get_virtual_folder_id_by_data_entity_id($value)) != null) {
                     array_push($result_array, $virtual_folder_id);
                 }
             }
             return $result_array;
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
 /**
  * @see ProjectVirtualFolderInterface::__construct()
  * @param integer $virtual_folder_id
  */
 function __construct($virtual_folder_id)
 {
     parent::__construct($virtual_folder_id);
 }