Ejemplo n.º 1
0
 /**
  * <p> Retrieve the markers to display on Google Maps and the center position
  * if no items are returned for the Current Project 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::CreateLocationMarkerItems
  * @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 executeListCurrentProjectLocations(\Library\HttpRequest $rq)
 {
     $result = $this->InitResponseWS();
     //get datapost and decode properties string to array
     $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
     $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);
     //load marker icons from config
     $icons = \Applications\PMTool\Helpers\MapHelper::GetActiveInactiveIcons($this->app()->relative_path, $this->app()->imageUtil, $this->app()->config());
     //create google maps marker items
     $projectLocationMarkers = \Applications\PMTool\Helpers\MapHelper::CreateLocationMarkerItems($locations, $properties, $icons);
     $result["noLatLngIcon"] = $icons["noLatLng"];
     $result["activeIcon"] = $icons["locationActive"];
     $result["inactiveIcon"] = $icons["locationInactive"];
     $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"] = "location";
     $result["activeTask"] = false;
     $result["controls"] = array("markers" => true, "shapes" => true, "ruler" => true);
     $result["activeControl"] = "pan";
     $noCoordinateMarkers = count(array_filter($projectLocationMarkers, function ($marker) {
         return !$marker['noLatLng'];
     }));
     //if there are no markers try to set default position to facility location
     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];
         }
     }
     $this->SendResponseWS($result, array("resx_file" => \Applications\PMTool\Resources\Enums\ResxFileNameKeys::Map, "resx_key" => $this->action(), "step" => count($projectLocationMarkers) >= 0 ? "success" : "error"));
 }