/** * Task copy: Task_technician * Fetches the related Task_technician for the * original task and creates the relation with the new * Task created in "copyTaskWithDependencies" */ public static function copyTaskTaskTechnician($caller, $source_task_id, $target_task_id) { $ttDAO = new \Applications\PMTool\Models\Dao\Task_technician(); $ttDAO->setTask_id($source_task_id); $dal = $caller->managers()->getManagerOf("Task"); $allTTs = $dal->selectMany($ttDAO, "task_id"); if (count($allTTs) > 0) { //TTs found, loop and remap with the new task id foreach ($allTTs as $tt) { $tsDAO = null; $ttDAO = new \Applications\PMTool\Models\Dao\Task_technician(); $ttDAO->setTask_id($target_task_id); $ttDAO->setTechnician_id($tt->technician_id()); $ttDAO->setIs_lead_tech($tt->is_lead_tech()); //Save $id = $dal->add($ttDAO); } } }
public function executeUpdateItems(\Library\HttpRequest $rq) { $result = $this->InitResponseWS(); // Init result $rows_affected = 0; $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->app()->user()); //Get the technician objects from ids received $technician_ids = str_getcsv($this->dataPost["technician_ids"], ','); $matchedElements = $this->FindObjectsFromIds(array("filter" => "technician_id", "ids" => $technician_ids, "objects" => $pm[\Library\Enums\SessionKeys::PmTechnicians])); foreach ($matchedElements as $technician) { //With the line below, you will update the item $pm[\Library\Enums\SessionKeys::PmTechnicians] //Therefore, you just need to save the variable $pm at the end of the processing $active = $this->dataPost["action"] === "active" ? TRUE : FALSE; $technician->setTechnician_active($active); $manager = $this->managers->getManagerOf($this->module); $rows_affected += $manager->edit($technician, "technician_id") ? 1 : 0; $task_technician = new \Applications\PMTool\Models\Dao\Task_technician(); $task_technician->setTechnician_id($technician->technician_id()); $manager = $this->managers->getManagerOf('TaskTechnician'); $manager->delete($task_technician, 'technician_id'); } if ($rows_affected === count($technician_ids)) { \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->app()->user(), $pm); } $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Technician, "resx_key" => $this->action(), "step" => $rows_affected === count($technician_ids) ? "success" : "error")); }
public static function UpdateTaskTechnicians($caller) { $result = $caller->InitResponseWS(); // Init result $dataPost = $caller->dataPost(); $result["rows_affected"] = 0; $result["technician_ids"] = str_getcsv($dataPost["technician_ids"], ','); $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($caller->user()); $task_technicians = array(); foreach ($result["technician_ids"] as $id) { $task_technician = new \Applications\PMTool\Models\Dao\Task_technician(); $task_technician->setTechnician_id($id); $task_technician->setTask_id($sessionTask[\Library\Enums\SessionKeys::TaskObj]->task_id()); $dal = $caller->managers()->getManagerOf($caller->module()); if ($dataPost["action"] === "add") { $result["rows_affected"] += $dal->add($task_technician) >= 0 ? 1 : 0; } else { $result["rows_affected"] += $dal->delete($task_technician, "technician_id") ? 1 : 0; } array_push($task_technicians, $task_technician); } $sessionTask[\Library\Enums\SessionKeys::TaskTechnicians] = $task_technicians; \Applications\PMTool\Helpers\TaskHelper::SetSessionTask($caller->user(), $sessionTask); return $result; }