ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
class.ilADTLocationSearchBridgeSingle.php
Go to the documentation of this file.
1<?php
2
3require_once "Services/ADT/classes/Bridges/class.ilADTSearchBridgeSingle.php";
4
6{
7 protected $radius; // [int]
8
9 protected function isValidADTDefinition(ilADTDefinition $a_adt_def)
10 {
11 return ($a_adt_def instanceof ilADTLocationDefinition);
12 }
13
14
15 // table2gui / filter
16
17 public function loadFilter()
18 {
19 $value = $this->readFilter();
20 if($value !== null)
21 {
22 // :TODO:
23 // $this->getADT()->setDate(new ilDateTime($value, IL_CAL_DATETIME));
24 }
25 }
26
27
28 // form
29
30 public function addToForm()
31 {
32 global $lng;
33
34 $adt = $this->getADT();
35
36 $default = false;
37 if($adt->isNull())
38 {
39 // see ilPersonalProfileGUI::addLocationToForm()
40
41 // use installation default
42 include_once("./Services/Maps/classes/class.ilMapUtil.php");
44 $adt->setLatitude($def["latitude"]);
45 $adt->setLongitude($def["longitude"]);
46 $adt->setZoom($def["zoom"]);
47
48 $default = true;
49 }
50
51 $optional = new ilCheckboxInputGUI($this->getTitle(), $this->addToElementId("tgl"));
52
53 if(!$default && !$adt->isNull())
54 {
55 $optional->setChecked(true);
56 }
57
58 $loc = new ilLocationInputGUI($lng->txt("location"), $this->getElementId());
59 $loc->setLongitude($adt->getLongitude());
60 $loc->setLatitude($adt->getLatitude());
61 $loc->setZoom($adt->getZoom());
62 $optional->addSubItem($loc);
63
64 $rad = new ilNumberInputGUI($lng->txt("form_location_radius"), $this->addToElementId("rad"));
65 $rad->setSize(4);
66 $rad->setSuffix($lng->txt("form_location_radius_km"));
67 $rad->setValue($this->radius);
68 $rad->setRequired(true);
69 $optional->addSubItem($rad);
70
71 $this->addToParentElement($optional);
72 }
73
74 protected function shouldBeImportedFromPost($a_post)
75 {
76 return (bool)$a_post["tgl"];
77 }
78
79 public function importFromPost(array $a_post = null)
80 {
81 $post = $this->extractPostValues($a_post);
82
83 if($post && $this->shouldBeImportedFromPost($post))
84 {
85 $item = $this->getForm()->getItemByPostVar($this->getElementId());
86 $item->setLongitude($post["longitude"]);
87 $item->setLatitude($post["latitude"]);
88 $item->setZoom($post["zoom"]);
89
90 $this->radius = (int)$post["rad"];
91
92 $this->getADT()->setLongitude($post["longitude"]);
93 $this->getADT()->setLatitude($post["latitude"]);
94 $this->getADT()->setZoom($post["zoom"]);
95 }
96 else
97 {
98 // optional empty is valid
99 $this->force_valid = true;
100
101 $this->getADT()->setLongitude(null);
102 $this->getADT()->setLatitude(null);
103 $this->getADT()->setZoom(null);
104 $this->radius = null;
105 }
106 }
107
108 public function isValid()
109 {
110 return (parent::isValid() && ((int)$this->radius || (bool)$this->force_valid));
111 }
112
113
114 // bounding
115
124 protected function getBoundingBox($a_latitude, $a_longitude, $a_radius)
125 {
126 $earth_radius = 6371;
127
128 // http://www.d-mueller.de/blog/umkreissuche-latlong-und-der-radius/
129 $max_lat = $a_latitude + rad2deg($a_radius/$earth_radius);
130 $min_lat = $a_latitude - rad2deg($a_radius/$earth_radius);
131 $max_long = $a_longitude + rad2deg($a_radius/$earth_radius/cos(deg2rad($a_latitude)));
132 $min_long = $a_longitude - rad2deg($a_radius/$earth_radius/cos(deg2rad($a_latitude)));
133
134 return array(
135 "lat" => array("min"=>$min_lat, "max"=>$max_lat)
136 ,"long" => array("min"=>$min_long, "max"=>$max_long)
137 );
138 }
139
140
141 // db
142
143 public function getSQLCondition($a_element_id)
144 {
145 global $ilDB;
146
147 if(!$this->isNull() && $this->isValid())
148 {
149 $box = $this->getBoundingBox($this->getADT()->getLatitude(), $this->getADT()->getLongitude(), $this->radius);
150
151 $res = array();
152 $res[] = $a_element_id."_lat >= ".$ilDB->quote($box["lat"]["min"], "float");
153 $res[] = $a_element_id."_lat <= ".$ilDB->quote($box["lat"]["max"], "float");
154 $res[] = $a_element_id."_long >= ".$ilDB->quote($box["long"]["min"], "float");
155 $res[] = $a_element_id."_long <= ".$ilDB->quote($box["long"]["max"], "float");
156
157 return "(".implode(" AND ", $res).")";
158 }
159 }
160
161
162 // import/export
163
164 public function getSerializedValue()
165 {
166 if(!$this->isNull() && $this->isValid())
167 {
168 return serialize(array(
169 "lat" => $this->getADT()->getLatitude()
170 ,"long" => $this->getADT()->getLongitude()
171 ,"radius" => (int)$this->radius
172 ));
173 }
174 }
175
176 public function setSerializedValue($a_value)
177 {
178 $a_value = unserialize($a_value);
179 if(is_array($a_value))
180 {
181 $this->getADT()->setLatitude($a_value["lat"]);
182 $this->getADT()->setLongitude($a_value["long"]);
183 $this->radius = (int)$a_value["radius"];
184 }
185 }
186
187}
188
189?>
ADT definition base class.
getSQLCondition($a_element_id)
Get SQL condition for current value(s)
getSerializedValue()
Get current value(s) in serialized form (for easy persisting)
setSerializedValue($a_value)
Set current value(s) in serialized form (for easy persisting)
getBoundingBox($a_latitude, $a_longitude, $a_radius)
Get bounding box for location circum search.
shouldBeImportedFromPost($a_post)
Check if incoming values should be imported at all.
isValidADTDefinition(ilADTDefinition $a_adt_def)
Check if given ADT definition is valid.
importFromPost(array $a_post=null)
Import values from (search) form request POST data.
readFilter()
Load value(s) from filter store (in session)
extractPostValues(array $a_post=null)
Extract data from (post) values.
addToElementId($a_add)
Add sub-element.
addToParentElement(ilFormPropertyGUI $a_field)
Add form field to parent element.
getElementId()
Get element id.
This class represents a checkbox property in a property form.
This class represents a location property in a property form.
static getDefaultSettings()
Get default longitude, latitude and zoom.
This class represents a number property in a property form.
global $lng
Definition: privfeed.php:40
global $ilDB