1: <?php
2:
3: namespace Genetsis\core\activityid;
4: use Exception;
5:
6: 7: 8: 9: 10: 11: 12:
13: class Location
14: {
15:
16: private $id = null;
17:
18: private $display_name = null;
19:
20: private $position = null;
21:
22: private $address = null;
23:
24: 25: 26:
27: public function getAddress()
28: {
29: return $this->address;
30: }
31:
32: 33: 34:
35: public function setAddress($address)
36: {
37: $this->address = $address;
38: }
39:
40: 41: 42:
43: public function getDisplayName()
44: {
45: return $this->display_name;
46: }
47:
48: 49: 50:
51: public function setDisplayName($display_name)
52: {
53: $this->display_name = $display_name;
54: }
55:
56: 57: 58:
59: public function getId()
60: {
61: return $this->id;
62: }
63:
64: 65: 66:
67: public function setId($id)
68: {
69: $this->id = $id;
70: }
71:
72: 73: 74:
75: public function getPosition()
76: {
77: return $this->position;
78: }
79:
80: 81: 82:
83: public function setPosition($position)
84: {
85: $this->position = $position;
86: }
87:
88: 89: 90: 91: 92: 93: 94: 95: 96:
97: public static function checkLocation($request)
98: {
99:
100: if (self::checkParam($request->getDisplayName())) {
101: throw new Exception('Location Display Name is mandatory.');
102: }
103:
104: if ((self::checkParam($request->getAddress())) && ((self::checkParam($request->getPosition())))) {
105: throw new Exception('Address or Position are mandatory in a Location.');
106: }
107:
108: $location = array(
109: 'id' => $request->getId(),
110: 'objectType' => ObjectType::PLACE,
111: 'displayName' => $request->getDisplayName(),
112: );
113:
114: if (!self::checkParam($request->getAddress())) {
115: if (self::checkParam($request->getAddress()->getPostalCode())) {
116: throw new Exception('Address Postal Code is mandatory.');
117: }
118:
119: $address = array(
120: 'postalCode' => $request->getAddress()->getPostalCode(),
121: 'formatted' => $request->getAddress()->getFormatted(),
122: 'streetAddress' => $request->getAddress()->getStreet(),
123: 'locality' => $request->getAddress()->getLocality(),
124: 'region' => $request->getAddress()->getRegion(),
125: 'country' => $request->getAddress()->getCountry(),
126: );
127: $location['address'] = $address;
128: }
129:
130: if (!self::checkParam($request->getPosition())) {
131: if (self::checkParam($request->getPosition()->getLatitude())) {
132: throw new Exception('Latitude is mandatory.');
133: }
134:
135: if (self::checkParam($request->getPosition()->getLongitude())) {
136: throw new Exception('Longitude is mandatory.');
137: }
138:
139: $position = array(
140: 'latitude' => $request->getPosition()->getLatitude(),
141: 'longitude' => $request->getPosition()->getLongitude(),
142: 'altitude' => $request->getPosition()->getAltitude(),
143: );
144: $location['position'] = $position;
145: }
146:
147: return $location;
148: }
149:
150: 151: 152: 153: 154: 155:
156: private static function checkParam($param)
157: {
158: return empty($param);
159: }
160: }