ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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 {
39 $a_value = (float)$a_value;
40 }
41 $this->longitude = $a_value;
42 }
43
44 public function getLongitude()
45 {
46 return $this->longitude;
47 }
48
49 public function setLatitude($a_value = null)
50 {
51 if($a_value !== null)
52 {
53 $a_value = (float)$a_value;
54 }
55 $this->latitude = $a_value;
56 }
57
58 public function getLatitude()
59 {
60 return $this->latitude;
61 }
62
63 public function getZoom()
64 {
65 return $this->zoom;
66 }
67
68 public function setZoom($a_value)
69 {
70 $this->zoom = max(1, abs((int)$a_value));
71 }
72
73
74 // comparison
75
76 public function equals(ilADT $a_adt)
77 {
78 if($this->getDefinition()->isComparableTo($a_adt))
79 {
80 return ($this->getLongitude() == $a_adt->getLongitude() &&
81 $this->getLatitude() == $a_adt->getLatitude());
82 }
83 }
84
85 public function isLarger(ilADT $a_adt)
86 {
87 // return null?
88 }
89
90 public function isSmaller(ilADT $a_adt)
91 {
92 // return null?
93 }
94
95
96 // null
97
98 public function isNull()
99 {
100 return ($this->getLongitude() === null && $this->getLatitude() === null);
101 }
102
103
104 // validation
105
106 public function isValid()
107 {
108 $valid = parent::isValid();
109
110 // zoom?
111
112 $long = $this->getLongitude();
113 $lat = $this->getLatitude();
114 if($long !== null && $lat !== null)
115 {
116 // 0 - (+-)180
117 if($long < -180 || $long > 180)
118 {
119 $this->addValidationError(self::ADT_VALIDATION_ERROR_LONGITUDE);
120 $valid = false;
121 }
122 // 0 - (+-)90
123 if($lat < -90 || $lat > 90)
124 {
125 $this->addValidationError(self::ADT_VALIDATION_ERROR_LATITUDE);
126 $valid = false;
127 }
128 }
129
130 return $valid;
131 }
132
133
134 // check
135
136 public function translateErrorCode($a_code)
137 {
138 global $lng;
139
140 // $lng->txt("msg_wrong_format");
141
142 switch($a_code)
143 {
145 return $lng->txt("adt_error_longitude");
146
148 return $lng->txt("adt_error_latitude");
149
150 default:
151 // all other / unknown "codes"
152 return parent::translateErrorCode($a_code);
153 }
154 }
155
156 public function getCheckSum()
157 {
158 if(!$this->isNull())
159 {
160 return md5($this->getLongitude().
161 "#".$this->getLatitude().
162 "#".$this->getZoom());
163 }
164 }
165}
166
167?>
ADT definition base class.
const ADT_VALIDATION_ERROR_LONGITUDE
setLatitude($a_value=null)
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:99
$valid
global $lng
Definition: privfeed.php:40