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;
 }
 public static function AddPmTechnician($caller, $result)
 {
     $sessionPm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($caller->user());
     $manager = $caller->managers()->getManagerOf($caller->module());
     $data_sent = $caller->dataPost();
     $data_sent["pm_id"] = $sessionPm[\Library\Enums\SessionKeys::PmObject]->pm_id();
     $technicians = array();
     if (array_key_exists("names", $caller->dataPost())) {
         $technicians = self::_PrepareManyTechnicianObjects($data_sent);
     } else {
         array_push($technicians, CommonHelper::PrepareUserObject($data_sent, new \Applications\PMTool\Models\Dao\Technician()));
     }
     $result["dataIn"] = $technicians;
     $result["dataId"] = 0;
     foreach ($technicians as $technician) {
         $result["dataId"] = $manager->add($technician);
         $technician->setTechnician_id($result["dataId"]);
         array_push($sessionPm[\Library\Enums\SessionKeys::PmTechnicians], $technician);
     }
     if ($result["dataId"]) {
         \Applications\PMTool\Helpers\PmHelper::SetSessionPm($caller->user(), $sessionPm);
     }
     return $result;
 }
 public static function AddUser($caller, $user_value, $user_role_id, $user_type = NULL)
 {
     if ($user_type === NULL) {
         $user_type = self::GetTypeFromRoleId($user_role_id);
     }
     $dataPost = $caller->dataPost();
     $userEmail = self::GetEMailForUser($caller, $dataPost, $user_type, $user_value);
     $manager = $caller->managers()->getManagerOf('User');
     $generatedDataPost = array('user_login' => $userEmail, 'user_password' => $userEmail, 'user_email' => $userEmail, 'user_hint' => '', 'user_role_id' => $user_role_id, 'user_type' => $user_type, 'user_value' => $user_value);
     $user = CommonHelper::PrepareUserObject($generatedDataPost, new \Applications\PMTool\Models\Dao\User());
     $protect = new \Library\BL\Core\Encryption();
     $user->setUser_password($protect->Encrypt($caller->app()->config()->get("encryption_key"), $user->user_password()));
     return $manager->add($user);
 }
 public static function AddUser($caller, $user_value, $user_role_id, $user_type = null)
 {
     if ($user_type === null) {
         $user_type = self::GetTypeFromRoleId($user_role_id);
     }
     $dataPost = $caller->dataPost();
     $userEmail = self::GetEmailForUser($caller, $dataPost, $user_type, $user_value);
     $manager = $caller->managers()->getDalInstance('User');
     $generatedDataPost = array('user_login' => $userEmail, 'user_password' => $userEmail, 'user_email' => $userEmail, 'user_hint' => '', 'user_role_id' => $user_role_id, 'user_type' => $user_type, 'user_value' => $user_value);
     $user = CommonHelper::PrepareUserObject($generatedDataPost, new \Puzzlout\Framework\BO\User());
     $protect = new \Puzzlout\Framework\BL\Security\Protect($caller->app()->config());
     $user->setUser_password($protect->HashValue($caller->app()->config()->get("PaswordSalt"), $user->user_password()));
     return $manager->add($user);
 }
 public static function AddAnalyte($caller, $result, $isFieldType, $isCommon)
 {
     $manager = $caller->managers()->getManagerOf($caller->module());
     $dataPost = $caller->dataPost();
     if (!$isCommon) {
         $pm = PmHelper::GetCurrentSessionPm($caller->user());
         $dataPost["pm_id"] = $pm[\Library\Enums\SessionKeys::PmObject]->pm_id();
     }
     $origin = "";
     if (array_key_exists("origin", $dataPost)) {
         $origin = $dataPost["origin"];
     }
     $analytes = array();
     $analyteObj = null;
     if ($isCommon) {
         $analyteObj = $isFieldType ? new \Applications\PMTool\Models\Dao\Common_field_analyte() : new \Applications\PMTool\Models\Dao\Common_lab_analyte();
     } else {
         $analyteObj = $isFieldType ? new \Applications\PMTool\Models\Dao\Field_analyte() : new \Applications\PMTool\Models\Dao\Lab_analyte();
     }
     if (array_key_exists("names", $dataPost)) {
         $analytes = !$isCommon ? self::_PrepareManyAnalyteObjects($dataPost, $isFieldType) : self::_PrepareManyCommonAnalyteObjects($dataPost, $isFieldType);
     } else {
         array_push($analytes, CommonHelper::PrepareUserObject($dataPost, $analyteObj));
     }
     $result["dataIn"] = $analytes;
     $result["dataId"] = 0;
     $result["error"] = array("hasError" => FALSE, "code" => 0, "message" => "");
     $commonSessiongKey = $isFieldType ? \Library\Enums\SessionKeys::CommonFieldAnalytes : \Library\Enums\SessionKeys::CommonLabAnalytes;
     $commonAnalytes = self::GetCommonAnalytes($caller->user(), $commonSessiongKey);
     foreach ($analytes as $analyte) {
         $result["dataId"] = 0;
         $result["dataId"] = $manager->add($analyte);
         if ($result["dataId"] < 0) {
             $result["error"]["hasError"] = TRUE;
             $result["error"]["code"] = $result["dataId"];
             $result["error"]["message"] = "Some items couldn't be added to the database";
         } elseif ($isFieldType && !$isCommon) {
             $analyte->setField_analyte_id($result["dataId"]);
             if (strcmp($origin, "task") === 0) {
                 self::AddProjectAnalyte($caller, $analyte, $dataPost);
             }
             array_push($pm[\Library\Enums\SessionKeys::PmFieldAnalytes], $analyte);
         } elseif (!$isFieldType && !$isCommon) {
             $analyte->setLab_analyte_id($result["dataId"]);
             array_push($pm[\Library\Enums\SessionKeys::PmLabAnalytes], $analyte);
         } elseif ($isFieldType && $isCommon) {
             $analyte->setCommon_field_analyte_id($result["dataId"]);
             array_push($commonAnalytes, $analyte);
         } else {
             $commonSessiongKey = \Library\Enums\SessionKeys::CommonLabAnalytes;
             $analyte->setCommon_lab_analyte_id($result["dataId"]);
             array_push($commonAnalytes, $analyte);
         }
     }
     if ($isCommon) {
         self::SetCommonAnalytes($caller->user(), $commonSessiongKey, $commonAnalytes);
     } else {
         PmHelper::SetSessionPm($caller->user(), $pm);
     }
     return $result;
 }