ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
Location.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
22
24use ILIAS\User\Profile\Fields\NoOverrides;
28
29class Location implements FieldDefinition
30{
31 use NoOverrides;
32
33 public function getIdentifier(): string
34 {
35 return 'location';
36 }
37
38 public function getLabel(Language $lng): string
39 {
40 return $lng->txt($this->getIdentifier());
41 }
42
43 public function getSection(): AvailableSections
44 {
45 return AvailableSections::PersonalData;
46 }
47
48 public function hiddenInLists(): bool
49 {
50 return true;
51 }
52
53 public function visibleInCoursesForcedTo(): ?bool
54 {
55 return false;
56 }
57
58 public function visibleInGroupsForcedTo(): ?bool
59 {
60 return false;
61 }
62
63 public function visibleInStudyProgrammesForcedTo(): ?bool
64 {
65 return false;
66 }
67
68 public function requiredForcedTo(): ?bool
69 {
70 return false;
71 }
72
73 public function searchableForcedTo(): ?bool
74 {
75 return false;
76 }
77
78 public function exportForcedTo(): ?bool
79 {
80 return false;
81 }
82
83 public function availableInCertificatesForcedTo(): ?bool
84 {
85 return false;
86 }
87
88 public function getLegacyInput(
91 ?\ilObjUser $user = null
93 $latitude = !empty($user?->getLatitude())
94 ? (float) $user->getLatitude()
95 : null;
96 $longitude = !empty($user?->getLongitude())
97 ? (float) $user->getLongitude()
98 : null;
99 $zoom = $user?->getLocationZoom();
100
101 if ($latitude === null && $longitude === null && $zoom === 0) {
103 $latitude = (float) $def['latitude'];
104 $longitude = (float) $def['longitude'];
105 $zoom = (int) $def['zoom'];
106 }
107
108 $street = $user?->getStreet() ?? '';
109 if ($street === '') {
110 $street = $lng->txt('street');
111 }
112 $city = $user?->getCity() ?? '';
113 if ($city === '') {
114 $city = $lng->txt('city');
115 }
116 $country = $user?->getCountry() ?? '';
117 if ($country === '') {
118 $country = $lng->txt('country');
119 }
120
121 $loc_prop = new \ilLocationInputGUI(
122 $lng->txt('location'),
123 'location'
124 );
125 $loc_prop->setLatitude($latitude);
126 $loc_prop->setLongitude($longitude);
127 $loc_prop->setZoom($zoom);
128 $loc_prop->setAddress($street . ', ' . $city . ', ' . $country);
129 return $loc_prop;
130 }
131
132 public function addValueToUserObject(
133 \ilObjUser $user,
134 mixed $input,
135 ?\ilPropertyFormGUI $form = null
136 ): \ilObjUser {
137 if (($input['latitude'] ?? 0.0) !== 0.0) {
138 $user->setLatitude((string) $input['latitude']);
139 }
140 if (($input['longitude'] ?? 0.0) !== 0.0) {
141 $user->setLongitude((string) $input['longitude']);
142 }
143
144 $user->setLocationZoom($input['zoom'] ?? null);
145
146 return $user;
147 }
148
149 public function retrieveValueFromUser(\ilObjUser $user): array
150 {
151 return [
152 'latitude' => $user->getLatitude(),
153 'longitude' => $user->getLongitude(),
154 'zoom' => $user?->getLocationZoom()
155 ];
156 }
157}
getLegacyInput(Language $lng, Context $context, ?\ilObjUser $user=null)
You don't need to add a post_var to the input as the User will handle this for you,...
Definition: Location.php:88
addValueToUserObject(\ilObjUser $user, mixed $input, ?\ilPropertyFormGUI $form=null)
Definition: Location.php:132
This class represents a property in a property form.
static getDefaultSettings()
Get default longitude, latitude and zoom.
User class.
setLatitude(?string $latitude)
This class represents a property form user interface.
global $lng
Definition: privfeed.php:31
if(!file_exists('../ilias.ini.php'))
$context
Definition: webdav.php:31