public static function UpdateTaskLocations($caller) { $result = $caller->InitResponseWS(); // Init result $dataPost = $caller->dataPost(); $result["rows_affected"] = 0; $result["location_ids"] = str_getcsv($dataPost["location_ids"], ','); $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($caller->user()); $task_locations = array(); foreach ($result["location_ids"] as $id) { $task_location = new \Applications\PMTool\Models\Dao\Task_location(); $task_location->setLocation_id($id); $task_location->setTask_id($sessionTask[\Library\Enums\SessionKeys::TaskObj]->task_id()); $task_location->setTask_location_status(0); $dal = $caller->managers()->getManagerOf($caller->module()); if ($dataPost["action"] === "add") { $result["rows_affected"] += $dal->add($task_location) >= 0 ? 1 : 0; //At the same time create the relationship in "field_analyte_location" \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::CreateFALocationRelationForFT($caller, $sessionTask[\Library\Enums\SessionKeys::TaskObj]->task_id(), $id); } else { $result["rows_affected"] += $dal->delete($task_location, "location_id") ? 1 : 0; } array_push($task_locations, $task_location); } $sessionTask[\Library\Enums\SessionKeys::TaskLocations] = $task_locations; \Applications\PMTool\Helpers\TaskHelper::SetSessionTask($caller->user(), $sessionTask); return $result; }
/** * Task copy: Task_location * Fetches the related Task_location for the * original task and creates the relation with the new * Task created in "copyTaskWithDependencies" */ public static function copyTaskTaskLocation($caller, $source_task_id, $target_task_id) { $tlDAO = new \Applications\PMTool\Models\Dao\Task_location(); $tlDAO->setTask_id($source_task_id); $dal = $caller->managers()->getManagerOf("Task"); $allTls = $dal->selectMany($tlDAO, "task_id"); if (count($allTls) > 0) { //fals found, loop and remap with the new task id foreach ($allTls as $tl) { $tlDAO = null; $tlDAO = new \Applications\PMTool\Models\Dao\Task_location(); $tlDAO->setTask_id($target_task_id); $tlDAO->setLocation_id($tl->location_id()); $tlDAO->setTask_location_status($tl->task_location_status()); //Save $id = $dal->add($tlDAO); } } }