public static function AddTaskAnalyte($caller, \Applications\PMTool\Models\Dao\Project_field_analyte $analyte, $dataPost) { $taskFieldData = new \Applications\PMTool\Models\Dao\Task_field_analyte(); $dal = $caller->managers()->getManagerOf($caller->module()); $taskFieldData->setField_analyte_id($analyte->field_analyte_id()); $taskFieldData->setTask_id($dataPost["originid"]); $result = $dal->add($taskFieldData); //Set up task field_analyte_location relationship \Applications\PMTool\Helpers\TaskAnalyteMatrixHelper::CreateLocationFARelationForFT($caller, $dataPost["originid"], $analyte->field_analyte_id()); if ($result < 0) { throw new \Exception("Task field data wasn't added for project field data => \n\r" . var_dump($analyte), $result, NULL); } }
/** * Task copy: Task_field_analyte * Fetches the related Task_field_analyte for the * original task and creates the relation with the new * Task created in "copyTaskWithDependencies" */ public static function copyTaskTaskFieldAnalyte($caller, $source_task_id, $target_task_id) { $tfaDAO = new \Applications\PMTool\Models\Dao\Task_field_analyte(); $tfaDAO->setTask_id($source_task_id); $dal = $caller->managers()->getManagerOf("Task"); $allTfas = $dal->selectMany($tfaDAO, "task_id"); if (count($allTfas) > 0) { //fals found, loop and remap with the new task id foreach ($allTfas as $tfa) { $tfaDAO = null; $tfaDAO = new \Applications\PMTool\Models\Dao\Task_field_analyte(); $tfaDAO->setTask_id($target_task_id); $tfaDAO->setField_analyte_id($tfa->field_analyte_id()); //Save $dal->add($tfaDAO); } } }
/** * Creates a new relation in the "field_analyte_location" table based on * the passed task_id, location_id */ public static function CreateFALocationRelationForFT($caller, $task_id, $location_id) { //Get the Field data for this task id //FIELD Analyte $tfaDAO = new \Applications\PMTool\Models\Dao\Task_field_analyte(); $tfaDAO->setTask_id($task_id); $dal = $caller->managers()->getManagerOf("TaskFieldAnalyte"); $relation_data = $dal->selectMany($tfaDAO, "task_id"); //Loop on the above and start preparing data for "field_analyte_location" if (count($relation_data) > 0) { $manager = $caller->managers()->getManagerOf('FieldAnalyteLocation'); foreach ($relation_data as $fa_rec) { //Check if the relationship is not already existing if (!$manager->ifMatrixDataExistsFor($task_id, $location_id, $fa_rec->field_analyte_id())) { //Add to the "field_analyte_location" table $data = array('task_id' => $task_id, 'location_id' => $location_id, 'field_analyte_id' => $fa_rec->field_analyte_id(), 'field_analyte_location_result' => ''); //Init PDO $field_analyte_location = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($data, new \Applications\PMTool\Models\Dao\Field_analyte_location()); $result_save_relation = $manager->add($field_analyte_location); } } } }