public function executeAdd(\Library\HttpRequest $rq) { // Init result sent to client (e.g. browser) $result = $this->InitResponseWS(); //Get the current PM Session $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->app()->user()); $dataPost = $this->dataPost(); $dataPost["pm_id"] = $pm === NULL ? NULL : $pm[\Library\Enums\SessionKeys::PmObject]->pm_id(); $origin = $originId = ""; if (array_key_exists("origin", $dataPost)) { $postUserData = (array) $dataPost["userData"]; $postUserData["pm_id"] = $dataPost["pm_id"]; $origin = $dataPost["origin"]; $originId = $dataPost["originid"]; } else { $postUserData = $dataPost; } //Store the pm_id in the dataPost... //.. and build the object to query the DB $technician = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($postUserData, new \Applications\PMTool\Models\Dao\Technician()); $technician->setTechnician_document(""); $result["dataIn"] = $technician; //Load interface to query the database $manager = $this->managers->getManagerOf($this->module); $result["dataId"] = $manager->add($technician); if ($pm !== NULL) { //Update the object with last inserted Id $technician->setTechnician_id($result["dataId"]); if ($technician->technician_id() > 0 && \Library\Utility\StringHelper::Equals($origin, "task") && !\Library\Utility\StringHelper::IsNullOrEmpty($originId)) { \Applications\PMTool\Helpers\TechnicianHelper::AddTaskTechnician($this, $originId, $technician->technician_id()); } //Update the PM Session array_push($pm[\Library\Enums\SessionKeys::PmTechnicians], $technician); //And update the Sessiom \Applications\PMTool\Helpers\PmHelper::SetSessionPm($this->app()->user(), $pm); } //add user record for FT if (intval($result["dataId"]) > 0) { $this->dataPost['user_email'] = $postUserData['technician_email']; $userId = \Applications\PMTool\Helpers\UserHelper::AddUser($this, $result["dataId"], \Library\Enums\UserRole::Technician); } //Send the response to browser $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Technician, "resx_key" => $this->action(), "step" => intval($result["dataId"]) > 0 && $userId > 0 ? "success" : "error")); }
public static function AddProjectLocation($caller, $result) { $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($caller->user()); $manager = $caller->managers()->getManagerOf($caller->module()); $dataPost = $caller->dataPost(); $dataPost["project_id"] = $sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id(); $origin = $originId = ""; if (array_key_exists("origin", $dataPost)) { $postUserData = (array) $dataPost["userData"]; $postUserData["project_id"] = $dataPost["project_id"]; $origin = $dataPost["origin"]; $originId = $dataPost["originid"]; } else { $postUserData = $dataPost; } $locations = array(); if (array_key_exists("names", $dataPost)) { $locations = self::_PrepareManyLocationObjects($dataPost); } elseif (array_key_exists("userData", $dataPost) && array_key_exists("names", $dataPost["userData"])) { $locations = self::_PrepareManyLocationObjects($dataPost, TRUE); } else { array_push($locations, CommonHelper::PrepareUserObject($postUserData, new \Applications\PMTool\Models\Dao\Location())); } $result["dataIn"] = $locations; $result["dataId"] = 0; foreach ($locations as $location) { $result["dataId"] = $manager->add($location); $location->setLocation_id($result["dataId"]); if ($location->location_id() > 0 && \Library\Utility\StringHelper::Equals($origin, "task") && !\Library\Utility\StringHelper::IsNullOrEmpty($originId)) { $result["dataId"] = self::AddTaskLocation($caller, $originId, $location->location_id()); } array_push($sessionProject[\Library\Enums\SessionKeys::ProjectLocations], $location); } if ($result["dataId"]) { \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($caller->user(), $sessionProject); } return $result; }