Example #1
0
 /**
  * @see SampleItemInterface::link_item()
  * @return bool
  */
 public function link_item()
 {
     global $transaction;
     if ($this->item_id and $this->sample_id) {
         $transaction_id = $transaction->begin();
         if (($sample_folder_id = SampleFolder::get_folder_by_sample_id($this->sample_id)) != null) {
             $sample_has_item = new SampleHasItem_Access(null);
             if (is_numeric($this->gid)) {
                 $primary_key = $sample_has_item->create($this->sample_id, $this->item_id, $this->gid);
                 if ($this->parent == true) {
                     $sample_has_item->set_parent(true);
                 } else {
                     $sample_has_item->set_parent(false);
                 }
             } else {
                 $primary_key = $sample_has_item->create($this->sample_id, $this->item_id, null);
             }
             if ($this->parent_item_id) {
                 if ($sample_has_item->set_parent_item_id($this->parent_item_id) == false) {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 }
             }
             if ($primary_key != null) {
                 $sample_item_link_event = new SampleItemLinkEvent($this->item_id, $sample_folder_id);
                 $event_handler = new EventHandler($sample_item_link_event);
                 if ($event_handler->get_success() == false) {
                     if ($transaction_id != null) {
                         $transaction->rollback($transaction_id);
                     }
                     return false;
                 } else {
                     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 {
         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 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 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;
     }
 }
 /**
  * @see ValueVarCaseInterface::is_case()
  * @param integer $folder_id
  * @return bool
  */
 public static function is_case($folder_id)
 {
     if (is_numeric($folder_id)) {
         if (($sample_id = SampleFolder::get_sample_id_by_folder_id($folder_id)) != null) {
             return $sample_id;
         } else {
             return false;
         }
     } else {
         return false;
     }
 }
Example #5
0
 /**
  * @param string $alias
  * @throws SampleSecurityAccessDeniedException
  * @throws BaseModuleDialogMethodNotFoundException
  * @throws BaseModuleDialogClassNotFoundException
  * @throws BaseModuleDialogFileNotFoundException
  * @throws BaseModuleDialogMissingException
  * @throws BaseModuleDialogNotFoundException
  * @throws ItemAddIOClassNotFoundException
  * @throws ItemAddIOFileNotFoundException
  * @throws ItemHandlerClassNotFoundException
  * @throws ItemPositionIDMissingException
  * @throws ItemParentIDMissingException
  * @throws ItemParentTypeMissingException
  */
 public static function io_handler($alias)
 {
     global $sample_security, $session, $transaction;
     if ($_GET['sample_id']) {
         $sample_security = new SampleSecurity($_GET['sample_id']);
         require_once "io/sample_common.io.php";
         SampleCommon_IO::tab_header();
     } else {
         $sample_security = new SampleSecurity(null);
     }
     switch ($_GET['run']) {
         case "new":
         case "new_subsample":
             require_once "io/sample.io.php";
             SampleIO::create();
             break;
         case "clone":
             require_once "io/sample.io.php";
             SampleIO::clone_sample();
             break;
         case "organ_unit":
             require_once "io/sample.io.php";
             SampleIO::list_organisation_unit_related_samples();
             break;
         case "detail":
             require_once "io/sample.io.php";
             SampleIO::detail();
             break;
         case "move":
             require_once "io/sample.io.php";
             SampleIO::move();
             break;
         case "set_availability":
             require_once "io/sample.io.php";
             SampleIO::set_availability();
             break;
         case "location_history":
             require_once "io/sample.io.php";
             SampleIO::location_history();
             break;
             // Administration
         // Administration
         case "delete":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::delete();
             break;
         case "rename":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::rename();
             break;
         case "admin_permission_user":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::user_permission();
             break;
         case "admin_permission_user_add":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::user_permission_add();
             break;
         case "admin_permission_user_delete":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::user_permission_delete();
             break;
         case "admin_permission_ou":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::ou_permission();
             break;
         case "admin_permission_ou_add":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::ou_permission_add();
             break;
         case "admin_permission_ou_delete":
             require_once "io/sample_admin.io.php";
             SampleAdminIO::ou_permission_delete();
             break;
             // Item Lister
         // Item Lister
         case "item_list":
             if ($sample_security->is_access(1, false) == true) {
                 if ($_GET['dialog']) {
                     if ($_GET['dialog'] == "data") {
                         $path_stack_array = array();
                         $folder_id = SampleFolder::get_folder_by_sample_id($_GET['sample_id']);
                         $folder = Folder::get_instance($folder_id);
                         $init_array = $folder->get_object_id_path();
                         foreach ($init_array as $key => $value) {
                             $temp_array = array();
                             $temp_array['virtual'] = false;
                             $temp_array['id'] = $value;
                             array_unshift($path_stack_array, $temp_array);
                         }
                         if (!$_GET['folder_id']) {
                             $session->write_value("stack_array", $path_stack_array, true);
                         }
                     }
                     $module_dialog = ModuleDialog::get_by_type_and_internal_name("item_list", $_GET['dialog']);
                     if (file_exists($module_dialog['class_path'])) {
                         require_once $module_dialog['class_path'];
                         if (class_exists($module_dialog['class'])) {
                             if (method_exists($module_dialog['class'], $module_dialog['method'])) {
                                 $module_dialog['class']::$module_dialog['method']("sample", $_GET['sample_id'], true, false);
                             } else {
                                 throw new BaseModuleDialogMethodNotFoundException();
                             }
                         } else {
                             throw new BaseModuleDialogClassNotFoundException();
                         }
                     } else {
                         throw new BaseModuleDialogFileNotFoundException();
                     }
                 } else {
                     throw new BaseModuleDialogMissingException();
                 }
             } else {
                 throw new SampleSecurityAccessDeniedException();
             }
             break;
         case "item_add":
         case "item_edit":
             if ($sample_security->is_access(2, false) == true) {
                 if ($_GET['dialog']) {
                     if ($_GET['run'] == "item_add") {
                         $module_dialog = ModuleDialog::get_by_type_and_internal_name("item_add", $_GET['dialog']);
                     } elseif ($_GET['run'] == "item_edit") {
                         $module_dialog = ModuleDialog::get_by_type_and_internal_name("item_edit", $_GET['dialog']);
                     }
                     if (is_array($module_dialog) and $module_dialog['class_path']) {
                         if (file_exists($module_dialog['class_path'])) {
                             require_once $module_dialog['class_path'];
                             if (class_exists($module_dialog['class'])) {
                                 if (method_exists($module_dialog['class'], $module_dialog['method'])) {
                                     $sample_item = new SampleItem($_GET['sample_id']);
                                     $sample_item->set_gid($_GET['key']);
                                     $description_required = $sample_item->is_description_required();
                                     $keywords_required = $sample_item->is_keywords_required();
                                     if ($description_required and !$_POST['description'] and !$_GET['idk_unique_id'] or $keywords_required and !$_POST['keywords'] and !$_GET['idk_unique_id']) {
                                         require_once "core/modules/item/io/item.io.php";
                                         ItemIO::information(http_build_query($_GET), $description_required, $keywords_required);
                                     } else {
                                         $sample = new Sample($_GET['sample_id']);
                                         $current_requirements = $sample->get_requirements();
                                         if ($_GET['run'] == "item_add") {
                                             $module_dialog['class']::$module_dialog['method']($current_requirements[$_GET['key']]['type_id'], $current_requirements[$_GET['key']]['category_id'], "Sample", $_GET['sample_id'], $_GET['key']);
                                         } elseif ($_GET['run'] == "item_edit") {
                                             $module_dialog['class']::$module_dialog['method']($current_requirements[$_GET['key']]['fulfilled'][0]['item_id']);
                                         }
                                     }
                                 } else {
                                     throw new BaseModuleDialogMethodNotFoundException();
                                 }
                             } else {
                                 throw new BaseModuleDialogClassNotFoundException();
                             }
                         } else {
                             throw new BaseModuleDialogFileNotFoundException();
                         }
                     } else {
                         throw new BaseModuleDialogNotFoundException();
                     }
                 } else {
                     throw new BaseModuleDialogMissingException();
                 }
             } else {
                 throw new SampleSecurityAccessDeniedException();
             }
             break;
             // Sub Item Add
         // Sub Item Add
         case "sub_item_add":
         case "sub_item_edit":
             if ($sample_security->is_access(2, false) == true) {
                 if ($_GET['parent']) {
                     if (is_numeric($_GET['parent_id'])) {
                         if (is_numeric($_GET['key'])) {
                             $item_handling_class = Item::get_handling_class_by_type($_GET['parent']);
                             if (class_exists($item_handling_class)) {
                                 $item_io_handling_class = $item_handling_class::get_item_add_io_handling_class();
                                 if (file_exists("core/modules/" . $item_io_handling_class[0])) {
                                     require_once "core/modules/" . $item_io_handling_class[0];
                                     if (class_exists($item_io_handling_class[1])) {
                                         if ($_GET['run'] == "sub_item_add") {
                                             $item_io_handling_class[1]::item_add_edit_handler("add");
                                         } else {
                                             $item_io_handling_class[1]::item_add_edit_handler("edit");
                                         }
                                     } else {
                                         throw new ItemAddIOClassNotFoundException();
                                     }
                                 } else {
                                     throw new ItemAddIOFileNotFoundException();
                                 }
                             } else {
                                 throw new ItemHandlerClassNotFoundException();
                             }
                         } else {
                             throw new ItemPositionIDMissingException();
                         }
                     } else {
                         throw new ItemParentIDMissingException();
                     }
                 } else {
                     throw new ItemParentTypeMissingException();
                 }
             } else {
                 throw new SampleSecurityAccessDeniedException();
             }
             break;
             // Parent Item Lister
         // Parent Item Lister
         case "parent_item_list":
             if ($sample_security->is_access(1, false) == true) {
                 if ($_GET['dialog']) {
                     $sample = new Sample($_GET['sample_id']);
                     $item_id = $sample->get_item_id();
                     $module_dialog = ModuleDialog::get_by_type_and_internal_name("parent_item_list", $_GET['dialog']);
                     if (file_exists($module_dialog['class_path'])) {
                         require_once $module_dialog['class_path'];
                         if (class_exists($module_dialog['class'])) {
                             if (method_exists($module_dialog['class'], $module_dialog['method'])) {
                                 $module_dialog['class']::$module_dialog['method']($item_id);
                             } else {
                                 throw new BaseModuleDialogMethodNotFoundException();
                             }
                         } else {
                             throw new BaseModuleDialogClassNotFoundException();
                         }
                     } else {
                         throw new BaseModuleDialogFileNotFoundException();
                     }
                 } else {
                     throw new BaseModuleDialogMissingException();
                 }
             } else {
                 throw new SampleSecurityAccessDeniedException();
             }
             break;
             // Common Dialogs
         // Common Dialogs
         case "common_dialog":
             require_once "core/modules/base/common.request.php";
             CommonRequest::common_dialog();
             break;
         default:
             require_once "io/sample.io.php";
             SampleIO::list_user_related_samples();
             break;
     }
 }
Example #6
0
 /**
  * @see ItemHolderInterface::get_item_holder_value()
  * @param string $address
  * @param integer $position_id
  * @return mixed
  */
 public final function get_item_holder_value($address, $position_id = null)
 {
     if ($this->sample_id and $this->sample) {
         switch ($address) {
             case "folder_id":
                 $folder_id = SampleFolder::get_folder_by_sample_id($this->sample_id);
                 $sub_folder_id = $this->get_sub_folder($folder_id, $position_id);
                 if (is_numeric($sub_folder_id)) {
                     $folder_id = $sub_folder_id;
                 }
                 return $folder_id;
                 break;
             case "organisation_unin_id":
                 return $this->get_organisation_unit_id();
                 break;
             default:
                 return null;
                 break;
         }
     } else {
         return null;
     }
 }