/**
  * Fetches the relationship between location and analyte
  * for the passed Task and Analyte Type
  */
 public static function GetAnalyteMatrixForTask($caller, $task_id, $analyte_type = 'Lab')
 {
     $id_map = array();
     if ($analyte_type === 'Lab') {
         //LAB analyte
         $matrixDAO = new \Applications\PMTool\Models\Dao\Lab_analyte_location();
         $matrixDAO->setTask_id($task_id);
         $dal = $caller->managers()->getManagerOf("TaskLabAnalyte");
         $relation_data = $dal->selectMany($matrixDAO, "task_id");
     } else {
         //FIELD Analyte
         $matrixDAO = new \Applications\PMTool\Models\Dao\Field_analyte_location();
         $matrixDAO->setTask_id($task_id);
         $dal = $caller->managers()->getManagerOf("FieldLabAnalyte");
         $relation_data = $dal->selectMany($matrixDAO, "task_id");
     }
     if (!empty($relation_data) && is_array($relation_data)) {
         foreach ($relation_data as $relation) {
             if ($analyte_type === 'Lab') {
                 $id_str = $relation->location_id() . '_' . $relation->lab_analyte_id();
             } else {
                 $id_str = $relation->location_id() . '_' . $relation->field_analyte_id();
             }
             array_push($id_map, $id_str);
         }
     }
     return $id_map;
 }
Esempio n. 2
0
 /**
  * Task copy: Lab_analyte_location
  * Fetches the related Lab_analyte_location for the
  * original task and creates the relation with the new
  * Task created in "copyTaskWithDependencies"
  */
 public static function copyTaskLabAnalyteLocation($caller, $source_task_id, $target_task_id)
 {
     $lalDAO = new \Applications\PMTool\Models\Dao\Lab_analyte_location();
     $lalDAO->setTask_id($source_task_id);
     $dal = $caller->managers()->getManagerOf("Task");
     $allLals = $dal->selectMany($lalDAO, "task_id");
     if (count($allLals) > 0) {
         //fals found, loop and remap with the new task id
         foreach ($allLals as $lal) {
             $lalDAO = null;
             $lalDAO = new \Applications\PMTool\Models\Dao\Lab_analyte_location();
             $lalDAO->setTask_id($target_task_id);
             $lalDAO->setLab_analyte_id($lal->lab_analyte_id());
             $lalDAO->setLocation_id($lal->location_id());
             //Save
             $dal->add($lalDAO);
         }
     }
 }