Ejemplo n.º 1
0
 public static function GetLocationList($caller, $sessionProject)
 {
     $result = $caller->InitResponseWS();
     if ($sessionProject !== NULL) {
         //Load interface to query the database for locations
         $location = new \Applications\PMTool\Models\Dao\Location();
         $location->setProject_id($sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id());
         $manager = $caller->managers()->getManagerOf("Location");
         $result[\Library\Enums\SessionKeys::ProjectLocations] = $sessionProject[\Library\Enums\SessionKeys::ProjectLocations] = $manager->selectMany($location, "project_id");
         if (!$result[\Library\Enums\SessionKeys::ProjectLocations]) {
             $result[\Library\Enums\SessionKeys::ProjectLocations] = $sessionProject[\Library\Enums\SessionKeys::ProjectLocations] = array();
         }
         \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($caller->user(), $sessionProject);
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * <p> Retrieve the markers to display on Google Maps and the center position
  * if no items are returned for the Current Project Task Locations</p>
  * <p> This method is called via an AJAX request from the client side. </p>
  * <p> The method receive by inheritance some post data
  * properties JSON object which includes objectTypes as "keys" and nested associative propNames
  * example:
  * "properties": {
  *  "location_obj": {
  *      "objectLatPropName": "location_lat",
  *      "objectLngPropName": "location_long",
  *      "objectActivePropName": "location_active"
  *      }
  *   }
  * For more info:
  * \Applications\PMTool\Helpers\MapHelper::CreateTaskLocationMarkerItems
  * @link
  * </p>
  * <p>
  * @param object $rq <p>
  * The current HttpRequest.
  * </p>
  * @return mixed $result <p>
  * The result is a standard JSON response containing
  * the specific data to the request, e.g.:
  *  - the list markers for a given filter
  *  - the default position used to center the map (this configured in the appsettings.xml)
  */
 public function executeListCurrentProjectTasks(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     $dataPost = $this->dataPost();
     $properties = json_decode($dataPost['properties'], true);
     //get facility location info
     $defaultLocationProperties = $properties['defaultLocation'];
     //unset default location because we don't want to show facility marker
     unset($properties['defaultLocation']);
     //get current sesion project and refresh project's locations then get current session task
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     //get project_id and load locations from DB
     $project_id = $sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id();
     $sessionProject[\Library\Enums\SessionKeys::ProjectLocations] = $locations = \Applications\PMTool\Helpers\LocationHelper::GetLocationListFromDB($this, $project_id);
     //store updated session
     \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($this->user(), $sessionProject);
     $sessionProject[\Library\Enums\SessionKeys::ProjectLocations] = $this->_GetAndStoreLocationsInSession($sessionProject);
     $sessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->app()->user());
     //create two arrays with current project's locations, one for locations linked with the task and other unlinked
     $taskLocations = \Applications\PMTool\Helpers\LocationHelper::GetAndStoreTaskLocations($this, $sessionTask);
     $projectLocations = \Applications\PMTool\Helpers\LocationHelper::GetProjectLocations($this, $sessionProject, $taskLocations);
     $locations = array(\Library\Enums\SessionKeys::TaskLocations => $taskLocations, \Library\Enums\SessionKeys::ProjectLocations => $projectLocations);
     //load marker icons from config
     $icons = \Applications\PMTool\Helpers\MapHelper::GetActiveInactiveIcons($this->app()->relative_path, $this->app()->imageUtil, $this->app()->config());
     if (isset($properties['activeTask']) && $properties['activeTask']) {
         $activeTask = $result["activeTask"] = true;
     } else {
         $activeTask = $result["activeTask"] = false;
     }
     //create google maps marker items
     $projectLocationMarkers = \Applications\PMTool\Helpers\MapHelper::CreateTaskLocationMarkerItems($this, $locations, $properties, $icons, $activeTask);
     $result["noLatLngIcon"] = $icons["taskNoLatLng"];
     $result["activeIcon"] = $icons["task"];
     $result["inactiveIcon"] = $icons["task"];
     $result["items"] = $projectLocationMarkers;
     $result["defaultPosition"] = \Applications\PMTool\Helpers\MapHelper::GetCoordinatesToCenterOverARegion($this->app()->config());
     $result["boundary"] = \Applications\PMTool\Helpers\MapHelper::GetBoundary($sessionProject);
     $result["facility_id"] = $sessionProject[\Library\Enums\SessionKeys::FacilityObject]->facility_id();
     $result["project_id"] = $sessionProject[\Library\Enums\SessionKeys::FacilityObject]->project_id();
     $result["type"] = 'task';
     $noCoordinateMarkers = count(array_filter($projectLocationMarkers, function ($item) {
         return !$item['noLatLng'];
     }));
     if ($noCoordinateMarkers == 0) {
         $defaultLocations = \Applications\PMTool\Helpers\MapHelper::BuildLatAndLongCoordFromGeoObjects(array(\Applications\PMTool\Helpers\CommonHelper::GetValueFromArrayByKey($sessionProject, $defaultLocationProperties['object'])), $defaultLocationProperties['objectLatPropName'], $defaultLocationProperties['objectLngPropName']);
         if (count($defaultLocations) > 0) {
             $result['defaultPosition'] = $defaultLocations[0];
         }
     }
     $result["controls"] = array("markers" => true, "shapes" => true, "ruler" => true);
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Map, "resx_key" => $this->action(), "step" => count($projectLocationMarkers) >= 0 ? "success" : "error"));
 }
 public function executeDelete(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $db_result = FALSE;
     $location_id = intval($this->dataPost["location_id"]);
     //Check if the location to be deleted if the Location manager's
     $location_selected = $this->_GetLocationFromSession($location_id);
     //Load interface to query the database
     if ($location_selected["object"] !== NULL) {
         $manager = $this->managers->getManagerOf($this->module());
         $db_result = $manager->delete($location_selected["object"], "location_id");
         if ($db_result) {
             unset($sessionProject[\Library\Enums\SessionKeys::ProjectLocations][$location_selected["key"]]);
             \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($this->app()->user(), $sessionProject);
         }
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Location, "resx_key" => $this->action(), "step" => $db_result !== FALSE ? "success" : "error"));
 }
Ejemplo n.º 4
0
 /**
  * Task Copy: Main method
  * Copies the task corresponding to the passed task id
  * and based on that copies all other dependencies into
  * the new task thus created
  */
 public static function copyTaskWithDependencies($caller, $source_task_id, $new_task_name, $usr)
 {
     $taskDAO = new \Applications\PMTool\Models\Dao\Task();
     $taskDAO->setTask_id($source_task_id);
     $dal = $caller->managers()->getManagerOf("Task");
     $source_task = $dal->selectMany($taskDAO, "task_id");
     //Create new task out of this
     $taskDAO = null;
     $taskDAO = new \Applications\PMTool\Models\Dao\Task();
     $taskDAO->setProject_id($source_task[0]->project_id());
     $taskDAO->setTask_name($new_task_name);
     $taskDAO->setTask_deadline($source_task[0]->task_deadline());
     $taskDAO->setTask_instructions($source_task[0]->task_instructions());
     $taskDAO->setTask_trigger_cal($source_task[0]->task_trigger_cal());
     $taskDAO->setTask_trigger_cal_value($source_task[0]->task_trigger_cal_value());
     $taskDAO->setTask_trigger_pm($source_task[0]->task_trigger_pm());
     $taskDAO->setTask_trigger_ext($source_task[0]->task_trigger_ext());
     $taskDAO->setTask_active($source_task[0]->task_active());
     $taskDAO->setTask_req_form($source_task[0]->task_req_form());
     $taskDAO->setTask_req_field_analyte($source_task[0]->task_req_field_analyte());
     $taskDAO->setTask_req_lab_analyte($source_task[0]->task_req_lab_analyte());
     $taskDAO->setTask_req_service($source_task[0]->task_req_service());
     $taskDAO->setTask_start_date($source_task[0]->task_start_date());
     $taskDAO->setTask_activated($source_task[0]->task_activated());
     $new_task_id = $dal->add($taskDAO);
     //Copy the relations too
     //FieldAnalyteLocation
     TaskHelper::copyTaskFieldAnalyteLocation($caller, $source_task_id, $new_task_id);
     //LabAnalyteLocation
     TaskHelper::copyTaskLabAnalyteLocation($caller, $source_task_id, $new_task_id);
     //TaskCocInfo
     TaskHelper::copyTaskTaskCocInfo($caller, $source_task_id, $new_task_id);
     //TaskFieldAnalyte
     TaskHelper::copyTaskTaskFieldAnalyte($caller, $source_task_id, $new_task_id);
     //TaskLabAnalyte
     TaskHelper::copyTaskTaskLabAnalyte($caller, $source_task_id, $new_task_id);
     //Task_location
     TaskHelper::copyTaskTaskLocation($caller, $source_task_id, $new_task_id);
     //Task_service
     TaskHelper::copyTaskTaskService($caller, $source_task_id, $new_task_id);
     //Task_technician
     TaskHelper::copyTaskTaskTechnician($caller, $source_task_id, $new_task_id);
     //Task_template_form
     TaskHelper::copyTaskTaskTemplateForm($caller, $source_task_id, $new_task_id);
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($usr);
     $taskDAO->setTask_id($new_task_id);
     array_push($sessionProject[\Library\Enums\SessionKeys::ProjectTasks], \Library\Enums\SessionKeys::TaskKey . $taskDAO->task_id());
     if ($new_task_id > 0) {
         \Applications\PMTool\Helpers\TaskHelper::AddSessionTask($usr, $taskDAO);
         \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($usr, $sessionProject);
     }
     return $new_task_id;
 }
Ejemplo n.º 5
0
 public function executeDelete(\Library\HttpRequest $rq)
 {
     // Init result
     $result = $this->InitResponseWS();
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($this->app()->user());
     $db_result = FALSE;
     $task_id = intval($this->dataPost["task_id"]);
     //Check if the task to be deleted if the Task manager's
     $task_selected = \Applications\PMTool\Helpers\TaskHelper::GetSessionTask($this->app()->user(), $task_id);
     //Load interface to query the database
     if ($task_selected !== NULL) {
         $manager = $this->managers->getManagerOf($this->module());
         if ($manager->delete($task_selected[\Library\Enums\SessionKeys::TaskObj], "task_id")) {
             $sessionTasks = \Applications\PMTool\Helpers\TaskHelper::GetSessionTasks($this->app()->user());
             unset($sessionTasks[\Library\Enums\SessionKeys::TaskKey . $task_id]);
             \Applications\PMTool\Helpers\TaskHelper::SetSessionTasks($this->app()->user(), $sessionTasks);
             $index = \Applications\PMTool\Helpers\CommonHelper::FindIndexInIdListById(\Library\Enums\SessionKeys::TaskKey . $task_id, $sessionProject[\Library\Enums\SessionKeys::ProjectTasks]);
             $db_result = $index === NULL ? FALSE : TRUE;
             unset($sessionProject[\Library\Enums\SessionKeys::ProjectTasks][$index]);
             \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($this->app()->user(), $sessionProject);
             $currentSessionTask = \Applications\PMTool\Helpers\TaskHelper::GetCurrentSessionTask($this->app()->user());
             if ($currentSessionTask[\Library\Enums\SessionKeys::TaskObj]->task_id() == $task_id) {
                 \Applications\PMTool\Helpers\TaskHelper::UnsetCurrentSessionTask($this->app()->user());
             }
         }
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Task, "resx_key" => $this->action(), "step" => $db_result !== FALSE ? "success" : "error"));
 }
Ejemplo n.º 6
0
 private static function ProcessListAnalytes($caller, $result, $params)
 {
     $result["arrayOfValues"] = str_getcsv($params["dataPost"]["arrayOfValues"], ',');
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($caller->user());
     foreach ($result["arrayOfValues"] as $id) {
         $setMethodObjId = "set" . ucfirst($params["objPropId"]);
         $params["object"]->{$setMethodObjId}($id);
         $params["object"]->setProject_id($sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id());
         $dal = $caller->managers()->getManagerOf($caller->module());
         if ($params["dataPost"]["action"] === "add") {
             $analyte = $params["objPropId"] === "field_analyte_id" ? new \Applications\PMTool\Models\Dao\Project_field_analyte() : new \Applications\PMTool\Models\Dao\Project_lab_analyte();
             $analyte->setProject_id($sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id());
             $setMethodObjId = "set" . ucfirst($params["objPropId"]);
             $analyte->{$setMethodObjId}($id);
             $newId = $dal->add($analyte);
             $result["rows_affected"] += 1;
             $sessionProjectAnalytes = $sessionProject[$params["sessionKey"]];
             array_push($sessionProjectAnalytes, $analyte);
             $sessionProject[$params["sessionKey"]] = $sessionProjectAnalytes;
         } else {
             $result["rows_affected"] += $dal->delete($params["object"], $params["objPropId"]) ? 1 : 0;
             //TODO: remove object deleted from array list
             $propId = $params["objPropId"];
             $match = CommonHelper::FindIndexInObjectListById($params["object"]->{$propId}(), $params["objPropId"], $sessionProject, $params["sessionKey"]);
             unset($sessionProject[$params["sessionKey"]][$match["key"]]);
         }
     }
     \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($caller->user(), $sessionProject);
     return $result;
 }
Ejemplo n.º 7
0
 public static function UpdateProjectServices($caller)
 {
     $result = $caller->InitResponseWS();
     // Init result
     $dataPost = $caller->dataPost();
     $result["rows_affected"] = 0;
     $result["service_ids"] = str_getcsv($dataPost["arrayOfValues"], ',');
     $sessionProject = \Applications\PMTool\Helpers\ProjectHelper::GetCurrentSessionProject($caller->user());
     $project_services = array();
     foreach ($result["service_ids"] as $id) {
         $project_service = new \Applications\PMTool\Models\Dao\Project_service();
         $project_service->setService_id($id);
         $project_service->setProject_id($sessionProject[\Library\Enums\SessionKeys::ProjectObject]->project_id());
         $dal = $caller->managers()->getManagerOf($caller->module());
         if ($dataPost["action"] === "add") {
             $result["rows_affected"] += $dal->add($project_service) >= 0 ? 1 : 0;
         } else {
             $result["rows_affected"] += $dal->delete($project_service, "service_id") ? 1 : 0;
         }
         array_push($project_services, $project_service);
     }
     $sessionProject[\Library\Enums\SessionKeys::ProjectServices] = $project_services;
     \Applications\PMTool\Helpers\ProjectHelper::SetUserSessionProject($caller->user(), $sessionProject);
     return $result;
 }