ILIAS  trunk Revision v12.0_alpha-1338-g8f7e531aa3c
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 availableInCertificatesForcedTo(): ?bool
79 {
80 return false;
81 }
82
83 public function getLegacyInput(
85 Context $context,
86 ?\ilObjUser $user = null
88 $latitude = !empty($user?->getLatitude())
89 ? (float) $user->getLatitude()
90 : null;
91 $longitude = !empty($user?->getLongitude())
92 ? (float) $user->getLongitude()
93 : null;
94 $zoom = $user?->getLocationZoom();
95
96 if ($latitude === null && $longitude === null && $zoom === 0) {
98 $latitude = (float) $def['latitude'];
99 $longitude = (float) $def['longitude'];
100 $zoom = (int) $def['zoom'];
101 }
102
103 $street = $user?->getStreet() ?? '';
104 if ($street === '') {
105 $street = $lng->txt('street');
106 }
107 $city = $user?->getCity() ?? '';
108 if ($city === '') {
109 $city = $lng->txt('city');
110 }
111 $country = $user?->getCountry() ?? '';
112 if ($country === '') {
113 $country = $lng->txt('country');
114 }
115
116 $loc_prop = new \ilLocationInputGUI(
117 $lng->txt('location'),
118 'location'
119 );
120 $loc_prop->setLatitude($latitude);
121 $loc_prop->setLongitude($longitude);
122 $loc_prop->setZoom($zoom);
123 $loc_prop->setAddress($street . ', ' . $city . ', ' . $country);
124 return $loc_prop;
125 }
126
127 public function addValueToUserObject(
128 \ilObjUser $user,
129 mixed $input,
130 ?\ilPropertyFormGUI $form = null
131 ): \ilObjUser {
132 if (($input['latitude'] ?? 0.0) !== 0.0) {
133 $user->setLatitude((string) $input['latitude']);
134 }
135 if (($input['longitude'] ?? 0.0) !== 0.0) {
136 $user->setLongitude((string) $input['longitude']);
137 }
138
139 $user->setLocationZoom($input['zoom'] ?? null);
140
141 return $user;
142 }
143
144 public function retrieveValueFromUser(\ilObjUser $user): array
145 {
146 return [
147 'latitude' => $user->getLatitude(),
148 'longitude' => $user->getLongitude(),
149 'zoom' => $user?->getLocationZoom()
150 ];
151 }
152}
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:83
addValueToUserObject(\ilObjUser $user, mixed $input, ?\ilPropertyFormGUI $form=null)
Definition: Location.php:127
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:26
if(!file_exists('../ilias.ini.php'))