Пример #1
0
    public function getInput()
    {
        if (is_string($this->value)) {
            // Value is a string - must be a single location
            $this->addLocation(SWG::parseLatLongTuple($this->value));
        } else {
            // Set up our initial location
            if (isset($this->value['start'])) {
                $this->start = SWG::parseLatLongTuple($this->value['start']);
            } else {
                if (isset($this->element['start'])) {
                    $this->start = SWG::parseLatLongTuple($this->element['start']);
                }
            }
            if (isset($this->element['zoom']) && is_numeric($this->element['zoom']) && (int) $this->element['zoom'] > 0) {
                $this->zoom = (int) $this->element['zoom'];
            }
            if (isset($this->value['location'])) {
                $this->location[0] = SWG::parseLatLongTuple($this->value['location']);
                // If we have no explicit start, or the location overrides the default start, use this
                if (empty($this->start) || $this->value['locationOverridesStart']) {
                    $this->start = $this->location[0];
                }
            }
        }
        // Final fallback for starting location
        if (empty($this->start)) {
            $this->start = new LatLng(53.38155556, -1.469722222);
            // Middle of Sheffield
        }
        // Prepare variables for JS
        $jsStartPos = json_encode($this->start);
        $jsZoom = $this->zoom;
        $jsLocations = json_encode($this->locations);
        $jsGridRefFieldIDs = json_encode(explode(",", $this->element['gridRefFields']));
        $jsLocationNameFieldIDs = json_encode(explode(",", $this->element['locationNameFields']));
        $jsPlaceMarker = json_encode(explode(",", $this->element['placeMarkerButtons']));
        $jsMultiLocations = !empty($this->element['multipleLocations']) ? "true" : "false";
        $routes = array();
        foreach ($this->routes as $rt) {
            $routes[] = $rt->sharedProperties();
        }
        $jsRoutes = json_encode($routes);
        // Load the maps JS
        $document = JFactory::getDocument();
        JHtml::_('behavior.framework', true);
        $document->addScript('/libraries/openlayers/OpenLayers.debug.js');
        $document->addScript('/swg/js/maps.js');
        $document->addScript(JURI::base() . "administrator/components/com_swg_events/models/fields/location.js");
        $document->addScriptDeclaration(<<<MAP
\t\t
window.addEvent('domready', function()
{
\tvar mapJS = new JFormFieldLocation("{$this->id}", {$jsStartPos}, {$jsZoom},{$jsMultiLocations}, {$jsLocations}, {$jsGridRefFieldIDs}, {$jsLocationNameFieldIDs}, {$jsRoutes}, {$jsPlaceMarker});
});
MAP
);
        $html = <<<FLD
<div id='{$this->id}_map' style='width:600px;height:400px;'>
\t<div id="{$this->id}_search" class="searchpanel">
\t\t<h4>Search</h4>
\t\t<input type="text" class="searchfield" />
\t\t<input type="button" class="submit" value="Search" />
\t</div>
</div>
<input type='hidden' size='80' name='{$this->name}' id='{$this->id}' value='{$jsLocations}' />
FLD;
        return $html;
    }
Пример #2
0
 public function __set($name, $value)
 {
     switch ($name) {
         case "name":
         case "description":
         case "bookingsInfo":
         case "clipartFilename":
         case "cost":
         case "location":
             $this->{$name} = $value;
             break;
         case "okToPublish":
         case "showNormal":
         case "showNewMember":
             $this->{$name} = (bool) $value;
             break;
         case "start":
         case "newMemberStart":
         case "end":
         case "newMemberEnd":
             if (!empty($value) && is_numeric($value)) {
                 $this->{$name} = $value;
             } else {
                 if ($value == "") {
                     $this->{$name} = null;
                 } else {
                     var_dump($name);
                     var_dump($value);
                 }
             }
             break;
         case "latLng":
             if ($value instanceof LatLng) {
                 $this->{$name} = $value;
             } else {
                 if (is_string($value)) {
                     // Is it in JSON?
                     if (substr($value, 0, 2) == "[{") {
                         $value = json_decode($value);
                         $value = $value[0];
                         $this->{$name} = new LatLng($value->lat, $value->lon);
                     } else {
                         $this->{$name} = SWG::parseLatLongTuple($this->value);
                     }
                 } else {
                     if (is_array($value)) {
                         // Convert to LatLng - deliberate fallthrough
                         if (isset($value['lat']) && isset($value['lng'])) {
                             if (is_numeric($value['lat']) && isset($value['lng']) && is_numeric($value['lng'])) {
                                 $this->{$name} = new LatLng($value['lat'], $value['lng']);
                             } else {
                                 if ($value['lat'] == "" && $value['lng'] == "") {
                                     $this->{$name} = null;
                                 }
                             }
                         }
                     } else {
                         if ($value == null) {
                             $this->{$name} = null;
                         }
                     }
                 }
             }
             break;
         case "postcode":
             // Geolocate this postcode
             // TODO: This will wipe any existing latLng...
             // Get the postcode passed in
             if (preg_match("/^([A-Z]{1,2}[0-9]{1,2}[A-Z]?[ ]?[0-9][A-Z]{2})\$/", $value)) {
                 $postcode = str_replace(" ", "", $value);
                 $curl = curl_init("http://www.uk-postcodes.com/postcode/" . $postcode . ".json");
                 curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                 $res = json_decode(curl_exec($curl));
                 if (isset($res->geo)) {
                     $this->latLng = new LatLng($res->geo->lat, $res->geo->lng);
                 }
             }
             $this->postcode = $value;
             break;
         default:
             // All others - fall through to Event
             parent::__set($name, $value);
     }
 }
Пример #3
0
 public function __set($name, $value)
 {
     switch ($name) {
         case "name":
         case "placeName":
         case "area":
         case "description":
         case "url":
         case "contact":
         case "bookingsOpen":
         case "cost":
             $this->{$name} = $value;
             break;
         case "places":
             $this->{$name} = (int) $value;
             break;
         case "okToPublish":
         case "challenge":
         case "swg":
             $this->{$name} = (bool) $value;
             break;
         case "start":
             if (!empty($value)) {
                 $this->{$name} = $value;
                 // Calculate the payment due date.
                 // Payment is due by the end of the month before the date 2 weeks before the weekend
                 // Looks like "last day of -1 month" is only supported by PHP 5.3, so let's do this the old-fashioned way
                 $threeWeeksBefore = $value - 86400 * 14;
                 // Looks like "last day of -1 month" is only supported by PHP 5.3, so let's do this the old-fashioned way
                 $this->paymentDue = strtotime(strftime("%Y-%m-01", $threeWeeksBefore)) - 86400;
             } else {
                 $this->{$name} = null;
                 $this->paymentDue = null;
             }
             break;
         case "endDate":
             if (!empty($value)) {
                 $this->{$name} = $value;
             } else {
                 $this->{$name} = null;
             }
             break;
         case "latLng":
             if ($value instanceof LatLng) {
                 $this->{$name} = $value;
             } else {
                 if (is_string($value)) {
                     // Is it in JSON?
                     if (substr($value, 0, 2) == "[{") {
                         $value = json_decode($value);
                         $value = $value[0];
                         $this->{$name} = new LatLng($value->lat, $value->lon);
                     } else {
                         $this->{$name} = SWG::parseLatLongTuple($this->value);
                     }
                 } else {
                     if (is_array($value)) {
                         // Convert to LatLng
                         if (isset($value['lat']) && isset($value['lng'])) {
                             if (is_numeric($value['lat']) && is_numeric($value['lng'])) {
                                 $this->{$name} = new LatLng($value['lat'], $value['lng']);
                             } else {
                                 $this->{$name} = null;
                             }
                         }
                     }
                 }
             }
             break;
         default:
             // All others - fall through to Event
             parent::__set($name, $value);
     }
 }