/** * Returns the master form record * This method could accept a template object * or simply master form ID. Both of this is * passed through the variable $template. * * The flag $templateIsId decides what is passed */ public static function GetFormFromTaskTemplateFrom($caller, $template, $templateIsId = false) { $masterformDAO = new \Applications\PMTool\Models\Dao\Master_form(); if ($templateIsId) { $masterformDAO->setForm_id($template); } else { $masterformDAO->setForm_id($template->master_form_id()); } $dal = $caller->managers()->getManagerOf("Task"); return $dal->selectMany($masterformDAO, "form_id"); }
public function executeDelete(\Library\HttpRequest $rq) { // Init result $result = $this->InitResponseWS(); $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user()); $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user()); $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user()); $db_result = FALSE; $form_id = intval($this->dataPost["form_id"]); if ($this->dataPost["form_type"] == "user_form") { //Check if the service to be deleted is the Project manager's $form_selected = \Applications\PMTool\Helpers\FormHelper::GetAUserForm($this->user(), $form_id); //Load interface to query the database if ($form_selected !== NULL) { $manager = $this->managers->getManagerOf("UserForm"); $manager->setRootDirectory($this->app()->config()->get(\Library\Enums\AppSettingKeys::RootDocumentUpload)); $manager->setWebDirectory($this->app()->config()->get(\Library\Enums\AppSettingKeys::BaseUrl) . $this->app()->config()->get(\Library\Enums\AppSettingKeys::RootUploadsFolderPath)); $db_result = $manager->deleteWithFile($form_selected, "form_id"); if ($db_result) { //since we don't have foreign keys set because this is a relationship between 3 tables we must manually delete all project_form records, we also need to manually remove task forms //remove project forms from session $relationProjectForms = \Applications\PMTool\Helpers\FormHelper::GetProjectForms($this, $sessionProject); $filteredProjectForms = \Applications\PMTool\Helpers\FormHelper::FilterFormsByGivenId($relationProjectForms, 'user_form_id', $form_id); $sessionProject[\Library\Enums\SessionKeys::ProjectForms] = $filteredProjectForms; if ($sessionTask !== FALSE) { $relationTaskForms = \Applications\PMTool\Helpers\FormHelper::GetTaskForms($this, $sessionTask); $filteredTaskForms = \Applications\PMTool\Helpers\FormHelper::FilterFormsByGivenId($relationTaskForms, 'user_form_id', $form_id); $sessionTask[\Library\Enums\SessionKeys::TaskForms] = $filteredTaskForms; \Applications\PMTool\Helpers\TaskHelper::SetCurrentSessionTask($this->user(), $sessionTask); } //delete from db $projectForm = new \Applications\PMTool\Models\Dao\Project_form(); $projectForm->setUser_form_id($form_id); $manager = $this->managers->getManagerOf("ProjectForm"); $manager->delete($projectForm, "user_form_id"); $taskForm = new \Applications\PMTool\Models\Dao\Task_template_form(); $taskForm->setUser_form_id($form_id); $manager = $this->managers->getManagerOf("TaskForm"); $manager->delete($taskForm, "user_form_id"); //remove user forms from session $match = \Applications\PMTool\Helpers\CommonHelper::FindIndexInObjectListById($form_selected->form_id(), "form_id", $sessionProject[\Library\Enums\SessionKeys::ProjectAvailableForms], \Library\Enums\SessionKeys::ProjectUserForms); unset($sessionProject[\Library\Enums\SessionKeys::ProjectAvailableForms][\Library\Enums\SessionKeys::ProjectUserForms][$match["key"]]); \Applications\PMTool\Helpers\ProjectHelper::SetCurrentSessionProject($this->user(), $sessionProject); } } } elseif ($this->dataPost["form_type"] == "master_form") { //delete from db //Project form $projectForm = new \Applications\PMTool\Models\Dao\Project_form(); $projectForm->setMaster_form_id($form_id); $manager = $this->managers->getManagerOf("ProjectForm"); $manager->delete($projectForm, "master_form_id"); //Task template form $taskForm = new \Applications\PMTool\Models\Dao\Task_template_form(); $taskForm->setMaster_form_id($form_id); $manager = $this->managers->getManagerOf("TaskForm"); $manager->delete($taskForm, "master_form_id"); //Now for the master form $masterFormDAO = new \Applications\PMTool\Models\Dao\Master_form(); $masterFormDAO->setForm_id($form_id); $dal = $this->managers()->getManagerOf("MasterForm"); $matchingForms = $dal->selectMany($masterFormDAO, "form_id"); $db_result = $dal->deleteWithFileV2($matchingForms[0], "form_id"); } $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Form, "resx_key" => $this->action(), "step" => $db_result !== FALSE ? "success" : "error")); }