ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilADTLocation.php
Go to the documentation of this file.
1<?php
2
3class ilADTLocation extends ilADT
4{
5 protected $longitude; // [float]
6 protected $latitude; // [float]
7 protected $zoom; // [int]
8
11
12
13 // definition
14
15 protected function isValidDefinition(ilADTDefinition $a_def)
16 {
17 return ($a_def instanceof ilADTLocationDefinition);
18 }
19
20
21 // default
22
23 public function reset()
24 {
25 parent::reset();
26
27 $this->setZoom(9);
28 $this->setLatitude();
29 $this->setLongitude();
30 }
31
32
33 // properties
34
35 public function setLongitude($a_value = null)
36 {
37 if ($a_value !== null) {
38 $a_value = (float) $a_value;
39 }
40 $this->longitude = $a_value;
41 }
42
43 public function getLongitude()
44 {
45 return $this->longitude;
46 }
47
48 public function setLatitude($a_value = null)
49 {
50 if ($a_value !== null) {
51 $a_value = (float) $a_value;
52 }
53 $this->latitude = $a_value;
54 }
55
56 public function getLatitude()
57 {
58 return $this->latitude;
59 }
60
61 public function getZoom()
62 {
63 return $this->zoom;
64 }
65
66 public function setZoom($a_value)
67 {
68 $this->zoom = max(1, abs((int) $a_value));
69 }
70
71
72 // comparison
73
74 public function equals(ilADT $a_adt)
75 {
76 if ($this->getDefinition()->isComparableTo($a_adt)) {
77 return ($this->getLongitude() == $a_adt->getLongitude() &&
78 $this->getLatitude() == $a_adt->getLatitude());
79 }
80 }
81
82 public function isLarger(ilADT $a_adt)
83 {
84 // return null?
85 }
86
87 public function isSmaller(ilADT $a_adt)
88 {
89 // return null?
90 }
91
92
93 // null
94
95 public function isNull()
96 {
97 return ($this->getLongitude() === null && $this->getLatitude() === null);
98 }
99
100
101 // validation
102
103 public function isValid()
104 {
105 $valid = parent::isValid();
106
107 // zoom?
108
109 $long = $this->getLongitude();
110 $lat = $this->getLatitude();
111 if ($long !== null && $lat !== null) {
112 // 0 - (+-)180
113 if ($long < -180 || $long > 180) {
114 $this->addValidationError(self::ADT_VALIDATION_ERROR_LONGITUDE);
115 $valid = false;
116 }
117 // 0 - (+-)90
118 if ($lat < -90 || $lat > 90) {
119 $this->addValidationError(self::ADT_VALIDATION_ERROR_LATITUDE);
120 $valid = false;
121 }
122 }
123
124 return $valid;
125 }
126
127
128 // check
129
130 public function translateErrorCode($a_code)
131 {
132 global $DIC;
133
134 $lng = $DIC['lng'];
135
136 // $lng->txt("msg_wrong_format");
137
138 switch ($a_code) {
140 return $lng->txt("adt_error_longitude");
141
143 return $lng->txt("adt_error_latitude");
144
145 default:
146 // all other / unknown "codes"
147 return parent::translateErrorCode($a_code);
148 }
149 }
150
151 public function getCheckSum()
152 {
153 if (!$this->isNull()) {
154 return md5($this->getLongitude() .
155 "#" . $this->getLatitude() .
156 "#" . $this->getZoom());
157 }
158 }
159
160
161 // stdClass
162
163 public function exportStdClass()
164 {
165 if (!$this->isNull()) {
166 $obj = new stdClass();
167 $obj->lat = $this->getLatitude();
168 $obj->long = $this->getLongitude();
169 $obj->zoom = $this->getZoom();
170 return $obj;
171 }
172 }
173
174 public function importStdClass($a_std)
175 {
176 if (is_object($a_std)) {
177 $this->setLatitude($a_std->lat);
178 $this->setLongitude($a_std->long);
179 $this->setZoom($a_std->zoom);
180 }
181 }
182}
An exception for terminatinating execution or to throw for unit testing.
ADT definition base class.
const ADT_VALIDATION_ERROR_LONGITUDE
setLatitude($a_value=null)
importStdClass($a_std)
Import value from stdClass.
exportStdClass()
Export value as stdClass.
setLongitude($a_value=null)
isValidDefinition(ilADTDefinition $a_def)
Check if definition is valid for ADT.
getCheckSum()
Get unique checksum.
translateErrorCode($a_code)
Translate error-code to human-readable message.
isLarger(ilADT $a_adt)
Check if given ADT is larger than self.
isNull()
Is currently null.
reset()
Init property defaults.
isSmaller(ilADT $a_adt)
Check if given ADT is smaller than self.
const ADT_VALIDATION_ERROR_LATITUDE
isValid()
Is currently valid.
equals(ilADT $a_adt)
Check if given ADT equals self.
ADT base class.
Definition: class.ilADT.php:12
addValidationError($a_error_code)
Add validation error code.
getDefinition()
Get definition.
Definition: class.ilADT.php:97
$valid
global $DIC
Definition: goto.php:24
$lng