public function executeIsfieldAnalyteExisting(\Library\HttpRequest $rq) { $result = $this->InitResponseWS(); $pm = \Applications\PMTool\Helpers\PmHelper::GetCurrentSessionPm($this->user()); $field_analytes = $pm[\Library\Enums\SessionKeys::PmFieldAnalytes]; //Search in session using incoming post $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($this->dataPost['analyte_name'], "field_analyte_name_unit", $field_analytes); if ($match === false) { //Free to edit, nothing found $is_existing = false; } else { //something found, check with id, if id are same //it's basically the same record which we are editing if ($match->field_analyte_id() == $this->dataPost['analyte_id']) { //Free to edit, this record itself $is_existing = false; } else { //different id, must be a different record, restrict $is_existing = true; } } $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::FieldAnalyte, "resx_key" => $this->action(), "step" => $is_existing === false ? "error" : "success")); }
/** * AJAX response for checking if common lab analyte is existing */ public function executeIsCommonAnalyteExisting(\Library\HttpRequest $rq) { // Init result $result = $this->InitResponseWS(); $analyte_id = $this->dataPost['analyte_id']; $analyte_name = $this->dataPost['analyte_name']; $analyte_type = $this->dataPost['analyte_type']; if ($analyte_type === 'lab') { $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($analyte_name, "common_lab_analyte_name", $_SESSION[\Library\Enums\SessionKeys::CommonLabAnalytes]); } elseif ($analyte_type === 'field') { $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($analyte_name, "common_field_analyte_name", $_SESSION[\Library\Enums\SessionKeys::CommonFieldAnalytes]); } if ($match !== false) { if ($analyte_type === 'field') { if ($match->common_field_analyte_id() == $analyte_id) { //The same record which is being edited $analyte_existing = 0; } else { //A different record exists with the name we provided $analyte_existing = 1; } } elseif ($analyte_type === 'lab') { if ($match->common_lab_analyte_id() == $analyte_id) { //The same record which is being edited $analyte_existing = 0; } else { //A different record exists with the name we provided $analyte_existing = 1; } } } else { //Nothing found $analyte_existing = 0; } $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::LabAnalyte, "resx_key" => $this->action(), "step" => $analyte_existing === 1 ? "success" : "error")); }
public function executeIfAllLocationsExist(\Library\HttpRequest $rq) { $result = $this->InitResponseWS(); // Init result //get current project $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user()); //get locations of the current project $sessionLocations = $sessionProject[\Library\Enums\SessionKeys::ProjectLocations]; $postData = $this->dataPost(); $location_names = \Applications\PMTool\Helpers\CommonHelper::StringToArray("\n", $postData["location_names"]); //Loop on the names $redundantLocs = array(); foreach ($location_names as $the_locname) { $location = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject(array('location_name' => $the_locname), new \Applications\PMTool\Models\Dao\Location()); $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($location->location_name(), "location_name", $sessionLocations); if ($match && !empty($match)) { array_push($redundantLocs, $the_locname); } } $result['record_count'] = empty($redundantLocs) ? 0 : count($redundantLocs); $result['duplicate_locations'] = $redundantLocs; $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Location, "resx_key" => $this->action(), "step" => $result['record_count'] > 0 ? "success" : "error")); }
public function executeIfTaskExists(\Library\HttpRequest $rq) { $result = $this->InitResponseWS(); // Init result $taskSession = \Applications\PMTool\Helpers\TaskHelper::GetSessionTasks($this->user()); $task = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Task()); $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($task->task_name(), "task_name", $taskSession, \Library\Enums\SessionKeys::TaskObj); $result['record_count'] = !$match || empty($match) ? 0 : 1; $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Task, "resx_key" => $this->action(), "step" => $result['record_count'] > 0 ? "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")); }
/** * Method which checks for existence of the project name in the database */ public function executeIfProjectExists(\Library\HttpRequest $rq) { $result = $this->InitResponseWS(); // Init result $project = \Applications\PMTool\Helpers\CommonHelper::PrepareUserObject($this->dataPost(), new \Applications\PMTool\Models\Dao\Project()); //Check session if the project name is already used $match = \Applications\PMTool\Helpers\CommonHelper::FindObjectByStringValue($project->project_name(), "project_name", \Applications\PMTool\Helpers\ProjectHelper::GetSessionProjects($this->user()), \Library\Enums\SessionKeys::ProjectObject); $result['record_count'] = !$match || empty($match) ? 0 : 1; $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Project, "resx_key" => $this->action(), "step" => $result['record_count'] > 0 ? "success" : "error")); }