public function executeUpdateItems(\Library\HttpRequest $rq) { $result = $this->InitResponseWS(); // Init result $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user()); $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->user()); $result["rows_affected"] = 0; //Get the service objects from ids received $user_form_ids = str_getcsv($this->dataPost["userFormIds"], ','); $master_form_ids = str_getcsv($this->dataPost["masterFormIds"], ','); $masterForms = $sessionProject[\Library\Enums\SessionKeys::ProjectAvailableForms][\Library\Enums\SessionKeys::ProjectMasterForms]; $userForms = $sessionProject[\Library\Enums\SessionKeys::ProjectAvailableForms][\Library\Enums\SessionKeys::ProjectUserForms]; $matchedMasterFormElements = $this->FindObjectsFromIds(array("filter" => "form_id", "ids" => $master_form_ids, "objects" => $masterForms)); $matchedUserFormElements = $this->FindObjectsFromIds(array("filter" => "form_id", "ids" => $user_form_ids, "objects" => $userForms)); $task_id = $sessionTask[\Library\Enums\SessionKeys::TaskObj]->task_id(); foreach ($matchedMasterFormElements as $form) { $manager = $this->managers->getManagerOf("TaskForm"); $taskForm = new \Applications\PMTool\Models\Dao\Task_template_form(); $taskForm->setTask_id($task_id); $taskForm->setMaster_form_id($form->form_id()); $taskForm->setUser_form_id(null); if ($this->dataPost["action"] == "add") { $manager->add($taskForm); $result["rows_affected"] += 1; } else { if ($this->dataPost["action"] == "remove") { $returnRemove = $manager->deleteByFilters($taskForm, array("task_id" => $task_id, "master_form_id" => $form->form_id())); $result["rows_affected"] += $returnRemove ? 1 : 0; } } } foreach ($matchedUserFormElements as $form) { $manager = $this->managers->getManagerOf("ProjectForm"); $taskForm = new \Applications\PMTool\Models\Dao\Task_template_form(); $taskForm->setTask_id($task_id); $taskForm->setMaster_form_id(null); $taskForm->setUser_form_id($form->form_id()); if ($this->dataPost["action"] == "add") { $returnAdd = $manager->add($taskForm); $result["rows_affected"] += $returnAdd >= 0 ? 1 : 0; } else { if ($this->dataPost["action"] == "remove") { $returnRemove = $manager->deleteByFilters($taskForm, array("task_id" => $task_id, "user_form_id" => $form->form_id())); $result["rows_affected"] += $returnRemove ? 1 : 0; } } } $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Task, "resx_key" => $this->action(), "step" => $result["rows_affected"] > 0 ? "success" : "error")); }
/** * Task copy: Task_template_form * Fetches the related Task_template_form for the * original task and creates the relation with the new * Task created in "copyTaskWithDependencies" */ public static function copyTaskTaskTemplateForm($caller, $source_task_id, $target_task_id) { $ttfDAO = new \Applications\PMTool\Models\Dao\Task_template_form(); $ttfDAO->setTask_id($source_task_id); $dal = $caller->managers()->getManagerOf("Task"); $allTTFs = $dal->selectMany($ttfDAO, "task_id"); if (count($allTTFs) > 0) { //TTs found, loop and remap with the new task id foreach ($allTTFs as $ttf) { $ttfDAO = null; $ttfDAO = new \Applications\PMTool\Models\Dao\Task_template_form(); $ttfDAO->setTask_id($target_task_id); $ttfDAO->setMaster_form_id($ttf->master_form_id()); $ttfDAO->setUser_form_id($ttf->user_form_id()); //Save $id = $dal->add($ttfDAO); } } }
public static function GetTaskForms($caller, $sessionTask) { $result = array(); if ($sessionTask !== NULL) { $taskForm = new \Applications\PMTool\Models\Dao\Task_template_form(); $taskId = $sessionTask[\Library\Enums\SessionKeys::TaskObj]->task_id(); $taskForm->setTask_id($taskId); $manager = $caller->managers()->getManagerOf("TaskForm"); $result = $sessionTask[\Library\Enums\SessionKeys::TaskForms] = $manager->selectMany($taskForm, "task_id"); \Applications\PMTool\Helpers\TaskHelper::SetCurrentSessionTask($caller->user(), $sessionTask); } return $result; }