public function executeDelete(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $db_result = FALSE;
     $analyte_id = intval($this->dataPost["itemId"]);
     $analyte = \Applications\PMTool\Helpers\CommonHelper::FindIndexInObjectListById($analyte_id, "field_analyte_id", $pm, \Library\Enums\SessionKeys::PmFieldAnalytes);
     if ($analyte["object"] !== NULL) {
         $manager = $this->managers->getManagerOf($this->module());
         $db_result = $manager->delete($analyte["object"], "field_analyte_id");
         if ($db_result) {
             unset($pm[\Library\Enums\SessionKeys::PmFieldAnalytes][$analyte["key"]]);
             \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->user(), $pm);
         }
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::FieldAnalyte, "resx_key" => $this->action(), "step" => $db_result !== FALSE ? "success" : "error"));
 }
 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 function executeIfProviderExists(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     // Init result
     $pmSession = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     //Check if already list exists in Session
     $service = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Service());
     if (!array_key_exists(\Library\Enums\SessionKeys::PmServices, $pmSession)) {
         //No, we have to query db and then populate the list into Session
         $manager = $this->managers->getManagerOf($this->module());
         $allServiceProviders = $manager->selectMany($service, "", true);
         $pmSession[\Library\Enums\SessionKeys::PmServices] = $allServiceProviders;
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->user(), $pmSession);
     }
     //Now check if Service provider already exists
     $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($service->service_name(), "service_name", $pmSession[\Library\Enums\SessionKeys::PmServices]);
     $result['record_count'] = !$match || empty($match) ? 0 : 1;
     //While editing, check if comparing with self
     if (!empty($match) && $service->service_id() !== '') {
         if ($match->service_id() == $service->service_id()) {
             $result['record_count'] = 0;
         }
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Service, "resx_key" => $this->action(), "step" => $result['record_count'] > 0 ? "success" : "error"));
 }
 public static function UpdateTechnicians($caller)
 {
     $result = $caller->InitResponseWS();
     // Init result
     $dataPost = $caller->dataPost();
     $rows_affected = 0;
     //Get the technician objects from ids received
     $result["technician_ids"] = str_getcsv($dataPost["technician_ids"], ',');
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($caller->user());
     $technicians = $sessionPm[\Library\Enums\SessionKeys::PmTechnicians];
     $matchedElements = $caller->FindObjectsFromIds(array("filter" => "technician_id", "ids" => $result["technician_ids"], "objects" => $technicians));
     $result["rows_affected"] = 0;
     foreach ($matchedElements as $technician) {
         $technician->setTechnician_active($dataPost["action"] === "active" ? TRUE : FALSE);
         $manager = $caller->managers()->getManagerOf($caller->module());
         $result["rows_affected"] += $manager->edit($technician, "technician_id") ? 1 : 0;
         self::DeleteTechnician($caller, "TaskTechnician", $technician, "technician_id");
     }
     \Applications\PMTool\Helpers\PmHelper::SetSessionPm($caller->user(), $sessionPm);
     return $result;
 }
Ejemplo n.º 5
0
 public function executeEdit(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     //Init PDO
     $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user());
     $this->dataPost["pm_id"] = $pm[\Library\Enums\SessionKeys::PmObject]->pm_id();
     $service = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Service());
     $result["data"] = $service;
     $manager = $this->managers->getManagerOf($this->module);
     $result_edit = $manager->edit($service, "service_id");
     if ($result_edit) {
         $match = \Applications\PMTool\Helpers\CommonHelper::FindIndexInObjectListById($service->service_id(), "service_id", $pm, \Library\Enums\SessionKeys::PmServices);
         $pm[\Library\Enums\SessionKeys::PmServices][$match["key"]] = $service;
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->user(), $pm);
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Service, "resx_key" => $this->action(), "step" => $result_edit ? "success" : "error"));
 }