/** * @see ProjectItemFactoryInterface::create() * @param integer $project_id * @param integer $item_id * @param integer $gid * @param string $keywords * @param string $description * @return bool */ public static function create($project_id, $item_id, $gid, $keywords = null, $description = null, $parent_item_id = null, $status_id = null) { global $transaction; if ($transaction->is_in_transction() == true and is_numeric($project_id) and is_numeric($item_id)) { if (self::$project_instance_array[$project_id]) { $project = self::$project_instance_array[$project_id]; } else { $project = new Project($project_id); self::$project_instance_array[$project_id] = $project; } $project_item = new ProjectItem($project_id); $project_item->set_gid($gid); if (!$status_id) { $project_item->set_status_id($project->get_current_status_id()); } else { $project_item->set_status_id($status_id); } $project_item->set_parent_item_id($parent_item_id); if ($project_item->set_item_id($item_id) == false) { return false; } if ($project_item->link_item() == false) { return false; } $project_item->set_item_status(); if (($class_name = $project_item->is_classified()) == true) { if ($project_item->set_class($class_name) == false) { return false; } } $description_required = $project_item->is_description(); $keywords_required = $project_item->is_keywords(); if ($description_required == true xor $keywords_required == true) { if ($description_required == false and $keywords_required == true) { $project_item->set_information(null, $keywords); } else { $project_item->set_information($description, null); } } else { if ($description_required == true and $keywords_required == true) { $project_item->set_information($description, $keywords); } } if ($project_item->create_log_entry() == false) { return false; } else { ProjectTask::check_over_time_tasks($project_id); return true; } } else { return false; } }
/** * @see ProjectInterface::create() * @param integer $organisation_unit_id * @param integer $parent_project_id * @param string $name * @param integer $owner_id * @param integer $template_id * @param string $description * @return integer * @throws ProjectCreateException * @throws ProjectCreateProjectExistsException * @throws ProjectCreateStatusException * @throws ProjectCreateFolderException * @throws ProjectCreateStatusFolderException * @throws ProjectCreateStatusSubFolderException * @throws ProjectCreateSupplementaryFolderException * @throws ProjectCreateDescriptionException * @throws ProjectCreateMasterDataException * @throws ProjectCreatePermissionUserException * @throws ProjectCreatePermissionLeaderException * @throws ProjectCreatePermissionGroupException * @throws ProjectCreatePermissionOrganisationUnitException * @throws ProjectCreatePermissionQualityManagerException */ public function create($organisation_unit_id, $parent_project_id, $name, $owner_id, $template_id, $description) { global $transaction; if ($organisation_unit_id xor $parent_project_id) { if ($name and $owner_id and $template_id and $description and $this->project) { if ($organisation_unit_id) { $organisation_unit = new OrganisationUnit($organisation_unit_id); if ($organisation_unit->is_permission($owner_id)) { if (self::exist_project_name($organisation_unit_id, null, $name) == true) { throw new ProjectCreateProjectExistsException("Project already exists in this Organisation Unit"); } } else { throw new ProjectCreateException("Cannot access on this Organisation Unit"); } } else { if (self::exist_project_name(null, $parent_project_id, $name) == true) { throw new ProjectCreateProjectExistsException("Project already exists in this Project"); } } $transaction_id = $transaction->begin(); $user = new User($owner_id); $project_user = new ProjectUserData($owner_id); $project_quota = $project_user->get_quota(); // Create Project if (($project_id = $this->project->create($organisation_unit_id, $parent_project_id, $name, $owner_id, $template_id, $project_quota)) == null) { if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateException("Could not create Project in DB"); } else { self::__construct($project_id); $project_template = new ProjectTemplate($template_id); $project_all_status_array = $project_template->get_all_status(); $project_has_project_status = new ProjectHasProjectStatus_Access(null); if ($project_has_project_status->create($project_id, $project_all_status_array[0]) != true) { if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateStatusException("Could not create status"); } if ($organisation_unit_id) { $base_folder_id = constant("PROJECT_FOLDER_ID"); } else { $base_folder_id = ProjectFolder::get_folder_by_project_id($parent_project_id); } $base_folder = Folder::get_instance($base_folder_id); $path = new Path($base_folder->get_path()); $path->add_element($project_id); $project_folder = new ProjectFolder(null); if (($folder_id = $project_folder->create($project_id, $base_folder_id)) == null) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateFolderException("Could not create main folder"); } // Create Supplementary Folder $supplementary_path = new Path($path->get_path_string()); $supplementary_path->add_element("supplementary"); $supplementary_folder = Folder::get_instance(null); if ($supplementary_folder->create("supplementary", $folder_id, $supplementary_path->get_path_string(), $owner_id, null) == null) { $project_folder->delete(); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateSupplementaryFolderException("Could not create supplementary folder"); } // Status Folder $folder_array = array(); foreach ($project_all_status_array as $key => $value) { $project_status_array = $project_template->get_status_requirements($value); if (is_array($project_status_array) and count($project_status_array) >= 1) { foreach ($project_status_array as $status_key => $status_value) { if (!in_array($value, $folder_array)) { array_push($folder_array, $value); } } } } foreach ($folder_array as $key => $value) { $projet_status_folder = new ProjectStatusFolder(null); if (($status_folder_id = $projet_status_folder->create($project_id, $value)) == null) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateStatusFolderException("Could not create status folder"); } $project_status = new ProjectStatus($value); $project_status_requirements = $project_template->get_status_requirements($value); // Create Subfolder $sub_folder_array = array(); foreach ($project_status_requirements as $sub_key => $sub_value) { if (($sub_value['type'] == "file" or $sub_value['type'] == "value") and $sub_value['folder']) { if (array_search(trim($sub_value['folder']), $sub_folder_array) === false) { array_push($sub_folder_array, trim($sub_value['folder'])); } } } if (is_array($sub_folder_array) and count($sub_folder_array) >= 1) { foreach ($sub_folder_array as $sub_key => $sub_value) { $folder_name = strtolower(trim($sub_value)); $folder_name = str_replace(" ", "-", $folder_name); $folder_path = new Path($projet_status_folder->get_path()); $folder_path->add_element($folder_name); $sub_folder = Folder::get_instance(null); if ($sub_folder->create($sub_value, $status_folder_id, $folder_path->get_path_string(), $user->get_user_id(), null) == null) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateStatusSubFolderException("Could not create status sub folder"); } } } } // Create Project Description $value = Value::get_instance(null); if ($value->create($folder_id, $owner_id, 2, $description) == null) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateDescriptionException("Could not create description value"); } $project_item = new ProjectItem($project_id); $project_item->set_gid(1); $project_item->set_status_id(1); $project_item->set_item_id($value->get_item_id()); if ($project_item->link_item() == false) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateDescriptionException("Could not create description item link"); } if ($project_item->set_required(true) == false) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateDescriptionException("Could not create description item role"); } // Create Project Master Data if ($this->template_data_array and is_numeric($this->template_data_type_id)) { $value = Value::get_instance(null); if ($value->create($folder_id, $owner_id, $this->template_data_type_id, $this->template_data_array) == null) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateMasterDataException("Could not create master-data value"); } $project_item = new ProjectItem($project_id); $project_item->set_gid(1); $project_item->set_status_id(1); $project_item->set_item_id($value->get_item_id()); if ($project_item->link_item() == false) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateMasterDataException("Could not create master-data item link"); } if ($project_item->set_required(true) == false) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreateMasterDataException("Could not create master-data item role"); } } // Permissions if ($organisation_unit_id) { $organisation_unit = new OrganisationUnit($organisation_unit_id); try { $project_permission = new ProjectPermissionUser(null); $project_permission->create($owner_id, $project_id, (int) Registry::get_value("project_user_default_permission"), null, 1); } catch (ProjectPermissionUserException $e) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreatePermissionUserException("Could not create user/owner permission"); } $leader_array = $organisation_unit->list_leaders(); if (is_array($leader_array) and count($leader_array) >= 1) { foreach ($leader_array as $key => $value) { try { $project_permission = new ProjectPermissionUser(null); $project_permission->create($value, $project_id, (int) Registry::get_value("project_leader_default_permission"), null, 2); } catch (ProjectPermissionUserException $e) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreatePermissionLeaderException("Could not create leader permission"); } } } try { $project_permission = new ProjectPermissionOrganisationUnit(null); $project_permission->create($organisation_unit_id, $project_id, (int) Registry::get_value("project_organisation_unit_default_permission"), null, 3); } catch (ProjectPermissionOrganisationUnitException $e) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreatePermissionOrganisationUnitException("Could not create Organisation Unit permission"); } $quality_manager_array = $organisation_unit->list_quality_managers(); if (is_array($quality_manager_array) and count($quality_manager_array) >= 1) { foreach ($quality_manager_array as $key => $value) { try { $project_permission = new ProjectPermissionUser(null); $project_permission->create($value, $project_id, (int) Registry::get_value("project_quality_manager_default_permission"), null, 5); } catch (ProjectPermissionUserException $e) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreatePermissionQualityManagerException("Could not create quality-manager permission"); } } } $group_array = $organisation_unit->list_groups(); if (is_array($group_array) and count($group_array) >= 1) { foreach ($group_array as $key => $value) { try { $project_permission = new ProjectPermissionGroup(null); $project_permission->create($value, $project_id, (int) Registry::get_value("project_group_default_permission"), null, 4); } catch (ProjectPermissionGroupException $e) { $project_folder->delete(true, true); if ($transaction_id != null) { $transaction->rollback($transaction_id, false); } throw new ProjectCreatePermissionGroupException("Could not create group permissions"); } } } } self::__construct($project_id); if ($transaction_id != null) { $transaction->commit($transaction_id); } return $project_id; } } else { throw new ProjectCreateException("Needed values are missing"); } } else { throw new ProjectCreateException("Project target is ambiguous"); } }
/** * @param string $alias * @throws BaseModuleDialogMethodNotFoundException * @throws BaseModuleDialogClassNotFoundException * @throws BaseModuleDialogFileNotFoundException * @throws BaseModuleDialogMissingException * @throws ProjectSecurityAccessDeniedException * @throws BaseModuleDialogNotFoundException * @throws ItemAddIOClassNotFoundException * @throws ItemAddIOFileNotFoundException * @throws ItemHandlerClassNotFoundException * @throws ItemPositionIDMissingException * @throws ItemParentIDMissingException * @throws ItemParentTypeMissingException * @throws ProjectStatusWithoutExtensionException * @throws BaseExtensionClassNotFoundException * @throws BaseExtensionFileNotFoundException * @throws BaseExtensionNotFoundException * @throws BaseExtensionMissingException */ public static function io_handler($alias) { global $project_security, $session, $transaction; if (isset($_GET['project_id']) and is_numeric($_GET['project_id'])) { $project_security = new ProjectSecurity($_GET['project_id']); if ($_GET['run'] != "new_subproject") { require_once "io/project_common.io.php"; ProjectCommon_IO::tab_header(); } } else { $project_security = new ProjectSecurity(null); } if (isset($_GET['run'])) { switch ($_GET['run']) { case "new": case "new_subproject": require_once "io/project.io.php"; ProjectIO::create(); break; case "myprojects": case "workon": case "accessdata": case "analyse": require_once "io/project.io.php"; ProjectIO::list_user_related_projects(null); break; case "userprojects": require_once "io/project.io.php"; ProjectIO::list_user_related_projects($_GET['id']); break; case "organ_unit": require_once "io/project.io.php"; ProjectIO::list_organisation_unit_related_projects(); break; case "detail": require_once "io/project.io.php"; ProjectIO::detail(); break; case "structure": require_once "io/project.io.php"; ProjectIO::structure(); break; // Project Log // Project Log case "log": require_once "io/project_log.io.php"; ProjectLogIO::list_project_related_logs(); break; // Tasks and Schedule // Tasks and Schedule case "add_task": require_once "io/project_task.io.php"; ProjectTaskIO::add(); break; case "schedule": case "show_tasks": require_once "io/project_task.io.php"; ProjectTaskIO::show(); break; case "task_detail": require_once "io/project_task.io.php"; ProjectTaskIO::detail(); break; case "task_delete": require_once "io/project_task.io.php"; ProjectTaskIO::delete(); break; case "task_edit_start": require_once "io/project_task.io.php"; ProjectTaskIO::edit_start(); break; case "task_edit_end": require_once "io/project_task.io.php"; ProjectTaskIO::edit_end(); break; // Administration // Administration case "admin": require_once "io/project_admin.io.php"; ProjectAdminIO::menu(); break; case "admin_rename": require_once "io/project_admin.io.php"; ProjectAdminIO::rename(); break; case "admin_chown": require_once "io/project_admin.io.php"; ProjectAdminIO::chown(); break; case "admin_move": require_once "io/project_admin.io.php"; ProjectAdminIO::move(); break; case "admin_quota": require_once "io/project_admin.io.php"; ProjectAdminIO::quota(); break; // Administration - Permission // Administration - Permission case "admin_permission": require_once "io/project_admin.io.php"; $project_admin_io = new ProjectAdminIO(); ProjectAdminIO::permission(); break; case "admin_permission_add_user": require_once "io/project_admin.io.php"; ProjectAdminIO::permission_add_user(); break; case "admin_permission_add_group": require_once "io/project_admin.io.php"; ProjectAdminIO::permission_add_group(); break; case "admin_permission_add_ou": require_once "io/project_admin.io.php"; ProjectAdminIO::permission_add_organisation_unit(); break; case "admin_permission_edit": require_once "io/project_admin.io.php"; ProjectAdminIO::permission_edit(); break; case "admin_permission_delete": require_once "io/project_admin.io.php"; ProjectAdminIO::permission_delete(); break; // Item Lister // Item Lister case "item_list": if ($project_security->is_access(1, false) == true) { if ($_GET['dialog']) { if ($_GET['dialog'] == "data") { $path_stack_array = array(); $folder_id = ProjectFolder::get_folder_by_project_id($_GET['project_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']("project", $_GET['project_id'], true); } else { throw new BaseModuleDialogMethodNotFoundException(); } } else { throw new BaseModuleDialogClassNotFoundException(); } } else { throw new BaseModuleDialogFileNotFoundException(); } } else { throw new BaseModuleDialogMissingException(); } } else { throw new ProjectSecurityAccessDeniedException(); } break; // Item Add // Item Add case "item_add": case "item_edit": if ($project_security->is_access(3, 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'])) { $project = new Project($_GET['project_id']); $project_item = new ProjectItem($_GET['project_id']); $project_item->set_status_id($project->get_current_status_id()); $project_item->set_gid($_GET['key']); $description_required = $project_item->is_description_required(); $keywords_required = $project_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 { $current_status_requirements = $project->get_current_status_requirements($project->get_current_status_id()); if ($_GET['run'] == "item_add") { $module_dialog['class']::$module_dialog['method']($current_status_requirements[$_GET['key']]['type_id'], $current_status_requirements[$_GET['key']]['category_id'], "Project", $_GET['project_id'], $_GET['key']); } elseif ($_GET['run'] == "item_edit") { $module_dialog['class']::$module_dialog['method']($current_status_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 ProjectSecurityAccessDeniedException(); } break; // Sub Item Add and Edit // Sub Item Add and Edit case "sub_item_add": case "sub_item_edit": if ($project_security->is_access(3, 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"); } elseif ($_GET['run'] == "sub_item_edit") { $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 ProjectSecurityAccessDeniedException(); } break; // Extension /** * @todo type filter */ // Extension /** * @todo type filter */ case "extension": if ($_GET['extension']) { $extension_id = Extension::get_id_by_identifier($_GET['extension']); if ($extension_id) { $extension = new Extension($extension_id); $main_file = constant("EXTENSION_DIR") . "/" . $extension->get_folder() . "/" . $extension->get_main_file(); $main_class = $extension->get_class(); if (file_exists($main_file)) { require_once $main_file; if (class_exists($main_class)) { $project = new Project($_GET['project_id']); $project_item = new ProjectItem($_GET['project_id']); $project_status_requirements = $project->get_current_status_requirements(); if (is_array($project_status_requirements) and count($project_status_requirements) >= 1) { foreach ($project_status_requirements as $key => $value) { if ($value['element_type'] == "extension" and $value['extension'] == $_GET['extension']) { if (is_array($value['filter']) and count($value['filter']) >= 1) { $filter_array = $value['filter']; } else { $filter_array = null; } break; } } } else { throw new ProjectStatusWithoutExtensionException(); } if ($filter_array) { $item_array = array(); foreach ($filter_array as $key => $value) { if (is_numeric($value['status'])) { $item_array = array_merge($item_array, $project_item->get_project_status_items($value['status'], true)); } } } else { $item_array = $project_item->get_project_items(true); } $event_identifier = uniqid("", true); if ($session->is_value("PROJECT_EXTENSION_EVENT_IDENTIFIER_ARRAY")) { $project_extension_event_identifier_array = $session->read_value("PROJECT_EXTENSION_EVENT_IDENTIFIER_ARRAY"); $project_extension_event_identifier_array[$event_identifier] = $_GET['project_id']; } else { $project_extension_event_identifier_array = array(); $project_extension_event_identifier_array[$event_identifier] = $_GET['project_id']; } $session->write_value("PROJECT_EXTENSION_EVENT_IDENTIFIER_ARRAY", $project_extension_event_identifier_array); $main_class::set_event_identifier($event_identifier); $main_class::set_target_folder_id(ProjectStatusFolder::get_folder_by_project_id_and_project_status_id($_GET['project_id'], $project->get_current_status_id())); $main_class::push_data($item_array); } else { throw new BaseExtensionClassNotFoundException(); } } else { throw new BaseExtensionFileNotFoundException(); } } else { throw new BaseExtensionNotFoundException(); } } else { throw new BaseExtensionMissingException(); } break; // Common Dialogs // Common Dialogs case "common_dialog": require_once "core/modules/base/common.request.php"; CommonRequest::common_dialog(); break; // Default // Default default: require_once "io/project.io.php"; ProjectIO::list_user_related_projects(null); break; } } else { require_once "io/project.io.php"; ProjectIO::list_user_related_projects(null); } }