ILIAS  release_8 Revision v8.24
class.ilUserDataSet.php
Go to the documentation of this file.
1<?php
2
23{
24 protected array $temp_picture_dirs = array(); // Missing array type.
25 public array $multi = array(); // Missing array type.
26 protected array $users; // Missing array type.
27
28 public function getSupportedVersions(): array // Missing array type.
29 {
30 return array("4.3.0", "4.5.0", "5.1.0", "5.2.0", "5.3.0");
31 }
32
33 protected function getXmlNamespace(string $a_entity, string $a_schema_version): string
34 {
35 return "https://www.ilias.de/xml/Services/User/" . $a_entity;
36 }
37
38 protected function getTypes(string $a_entity, string $a_version): array // Missing array type.
39 {
40 // user profile type
41 if ($a_entity == "usr_profile") {
42 switch ($a_version) {
43 case "4.3.0":
44 case "4.5.0":
45 case "5.1.0":
46 case "5.2.0":
47 case "5.3.0":
48 return array(
49 "Id" => "integer",
50 "Username" => "text",
51 "Firstname" => "text",
52 "Lastname" => "text",
53 "Title" => "text",
54 "Birthday" => "text",
55 "Gender" => "text",
56 "Institution" => "text",
57 "Department" => "text",
58 "Street" => "text",
59 "Zipcode" => "text",
60 "City" => "text",
61 "Country" => "text",
62 "SelCountry" => "text",
63 "PhoneOffice" => "text",
64 "PhoneHome" => "text",
65 "PhoneMobile" => "text",
66 "Fax" => "text",
67 "Email" => "text",
68 "SecondEmail" => "text",
69 "Hobby" => "text",
70 "ReferralComment" => "text",
71 "Matriculation" => "text",
72 "Latitude" => "text",
73 "Longitude" => "text",
74 "LocZoom" => "text",
75 "Picture" => "directory"
76 );
77 }
78 }
79
80 if ($a_entity == "usr_setting") {
81 switch ($a_version) {
82 case "4.3.0":
83 case "4.5.0":
84 case "5.1.0":
85 case "5.2.0":
86 case "5.3.0":
87 return array(
88 "UserId" => "integer",
89 "Keyword" => "text",
90 "Value" => "text"
91 );
92 }
93 }
94
95 if ($a_entity == "personal_data") {
96 switch ($a_version) {
97 case "4.3.0":
98 case "4.5.0":
99 case "5.1.0":
100 case "5.2.0":
101 case "5.3.0":
102 return array(
103 "Id" => "integer"
104 );
105 }
106 }
107
108 if ($a_entity == "usr_multi") {
109 switch ($a_version) {
110 case "4.5.0":
111 case "5.1.0":
112 case "5.2.0":
113 case "5.3.0":
114 return array(
115 "UserId" => "integer",
116 "FieldId" => "text",
117 "Value" => "text"
118 );
119 }
120 }
121 return [];
122 }
123
124 public function getXmlRecord(string $a_entity, string $a_version, array $a_set): array // Missing array type.
125 {
126 global $DIC;
127
128 if ($a_entity == "usr_profile") {
129 $tmp_dir = ilFileUtils::ilTempnam();
130 ilFileUtils::makeDir($tmp_dir);
131
133 $a_set["Id"],
134 "small",
135 true,
136 true
137 );
138
139 if ($im != "") {
140 ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
141 }
142
143 $this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
144
145 $a_set["Picture"] = $tmp_dir;
146 }
147
148 return $a_set;
149 }
150
151 public function afterXmlRecordWriting(string $a_entity, string $a_version, array $a_set): void // Missing array type.
152 {
153 if ($a_entity == "usr_profile") {
154 // cleanup temp dirs for pictures
155 $tmp_dir = $this->temp_picture_dirs[$a_set["Id"]];
156 if ($tmp_dir != "" && is_dir($tmp_dir)) {
157 ilFileUtils::delDir($tmp_dir);
158 }
159 }
160 }
161
162 public function readData(string $a_entity, string $a_version, array $a_ids): void // Missing array type.
163 {
164 global $DIC;
165
166 $ilDB = $DIC['ilDB'];
167
168 if (!is_array($a_ids)) {
169 $a_ids = array($a_ids);
170 }
171
172 if ($a_entity == "personal_data") {
173 switch ($a_version) {
174 case "4.3.0":
175 case "4.5.0":
176 case "5.1.0":
177 case "5.2.0":
178 case "5.3.0":
179 $this->data = array();
180 foreach ($a_ids as $id) {
181 $this->data[] = array("Id" => $id);
182 }
183 break;
184 }
185 }
186
187 if ($a_entity == "usr_profile") {
188 switch ($a_version) {
189 case "4.3.0":
190 case "4.5.0":
191 case "5.1.0":
192 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
193 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, " .
194 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, " .
195 " delicious, latitude, longitude, loc_zoom" .
196 " FROM usr_data u " .
197 "WHERE " .
198 $ilDB->in("u.usr_id", $a_ids, false, "integer"));
199 break;
200
201 case "5.2.0":
202 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
203 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, " .
204 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, " .
205 " latitude, longitude, loc_zoom" .
206 " FROM usr_data u " .
207 "WHERE " .
208 $ilDB->in("u.usr_id", $a_ids, false, "integer"));
209 break;
210 case "5.3.0":
211 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
212 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, " .
213 " phone_office, phone_home, phone_mobile, fax, email, second_email, hobby, referral_comment, matriculation, " .
214 " latitude, longitude, loc_zoom" .
215 " FROM usr_data u " .
216 "WHERE " .
217 $ilDB->in("u.usr_id", $a_ids, false, "integer"));
218 break;
219 }
220 }
221
222 if ($a_entity == "usr_setting") {
223 switch ($a_version) {
224 case "4.3.0":
225 case "4.5.0":
226 case "5.1.0":
227 case "5.2.0":
228 case "5.3.0":
229 // for all user ids get data from usr_pref and mail options, create records user_id/name/value
230 $prefs = array("date_format", "day_end", "day_start", "bs_allow_to_contact_me", "chat_osc_accept_msg", "hide_own_online_status", "hits_per_page", "language",
231 "public_birthday", "puplic_city", "public_country", "public_delicious", "public_department", "public_email", "public_second_email",
232 "public_fax", "public_gender", "public_hobby", "public_im_aim", "public_im_icq", "public_im_jabber",
233 "public_im_msn", "public_im_skype", "public_im_voip", "public_im_yahoo", "public_institution", "public_location",
234 "public_matriculation", "public_phone_home", "public_phone_mobile", "public_phone_office",
235 "public_profile", "public_sel_country", "public_street", "public_title", "public_upload", "public_zipcode",
236 "screen_reader_optimization", "show_users_online",
237 "store_last_visited", "time_format", "user_tz", "weekstart",
238 "session_reminder_enabled", "session_reminder_lead_time", "usr_starting_point",
239 "char_selector_availability", "char_selector_definition", "chat_broadcast_typing");
240
241 if (version_compare($a_version, '5.2.0', '>=')) {
242 unset(
243 $prefs['public_im_aim'], $prefs['public_im_icq'], $prefs['public_im_jabber'],
244 $prefs['public_im_msn'], $prefs['public_im_skype'], $prefs['public_im_voip'],
245 $prefs['public_im_yahoo'], $prefs['public_delicious']
246 );
247 }
248
249 $this->data = array();
250 $set = $ilDB->query("SELECT * FROM usr_pref " .
251 " WHERE " . $ilDB->in("keyword", $prefs, false, "text") .
252 " AND " . $ilDB->in("usr_id", $a_ids, false, "integer"));
253 while ($rec = $ilDB->fetchAssoc($set)) {
254 $this->data[] = array("UserId" => $rec["usr_id"], "Keyword" => $rec["keyword"], "Value" => $rec["value"]);
255 }
256 break;
257 }
258 }
259
260 if ($a_entity == "usr_multi") {
261 switch ($a_version) {
262 case "4.5.0":
263 case "5.1.0":
264 case "5.2.0":
265 case "5.3.0":
266 $this->data = array();
267 $set = $ilDB->query("SELECT * FROM usr_data_multi" .
268 " WHERE " . $ilDB->in("usr_id", $a_ids, false, "integer"));
269 while ($rec = $ilDB->fetchAssoc($set)) {
270 $this->data[] = array("UserId" => $rec["usr_id"], "FieldId" => $rec["field_id"], "Value" => $rec["value"]);
271 }
272 break;
273 }
274 }
275 }
276
277 public function importRecord(
278 string $a_entity,
279 array $a_types,
280 array $a_rec,
281 ilImportMapping $a_mapping,
282 string $a_schema_version
283 ): void {
284 global $DIC;
285
286 $ilSetting = $DIC['ilSetting'];
287 $ilUser = $DIC['ilUser'];
288
289 switch ($a_entity) {
290 case "personal_data":
291 // only users themselves import their profiles!
292 // thus we can map the import id of the dataset to the current user
293 $a_mapping->addMapping("Services/User", "usr", $a_rec["Id"], $ilUser->getId());
294 break;
295
296 case "usr_profile":
297 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["Id"]);
298 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
299 if (!isset($this->users[$usr_id])) {
300 $this->users[$usr_id] = new ilObjUser($usr_id);
301 }
302 $user = $this->users[$usr_id];
303 $prof = new ilUserProfile();
304 $prof->skipField("username");
305 $prof->skipField("password");
306 $prof->skipField("roles");
307 $prof->skipGroup("settings");
308 $fields = $prof->getStandardFields();
309 foreach ($fields as $k => $f) {
310 $up_k = $this->convertToLeadingUpper($k);
311 // only change fields, when it is possible in profile
313 !$ilSetting->get("usr_settings_disable_" . $k) &&
314 ($f["method"] ?? "") != "" && isset($a_rec[$up_k])) {
315 $set_method = "set" . substr($f["method"], 3);
316 $user->{$set_method}(ilUtil::secureString($a_rec[$up_k]));
317 }
318 }
319
320 $user->setLatitude($a_rec["Latitude"] ?? null);
321 $user->setLongitude($a_rec["Longitude"] ?? null);
322 $zoom = isset($a_rec["LocZoom"]) ? (int) $a_rec["LocZoom"] : null;
323 $user->setLocationZoom($zoom);
324
325 $user->update();
326
327 // personal picture
328 $pic_dir = $this->getImportDirectory() . "/" . str_replace("..", "", $a_rec["Picture"]);
329 if ($pic_dir != "" && is_dir($pic_dir)) {
330 $upload_file = $pic_dir . "/usr_" . $a_rec["Id"] . ".jpg";
331 if (!is_file($upload_file)) {
332 $upload_file = $pic_dir . "/upload_" . $a_rec["Id"] . "pic";
333 }
334 if (is_file($upload_file)) {
335 ilObjUser::_uploadPersonalPicture($upload_file, $user->getId());
336 }
337 }
338 }
339 break;
340
341 case "usr_setting":
342 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
343 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
344 if (!isset($this->users[$usr_id])) {
345 $this->users[$usr_id] = new ilObjUser($usr_id);
346 }
347 $user = $this->users[$usr_id];
348 $user->writePref($a_rec["Keyword"], ilUtil::secureString($a_rec["Value"]));
349 }
350 break;
351
352 case "usr_multi":
353 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
354 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
355 $this->multi[$usr_id][$a_rec["FieldId"]][] = ilUtil::secureString($a_rec["Value"]);
356 }
357 break;
358 }
359 }
360}
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
convertToLeadingUpper(string $a_str)
Make xyz_abc a XyzAbc string.
getDirectDataFromQuery(string $a_query, bool $a_convert_to_leading_upper=true, bool $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
static makeDir(string $a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
static ilTempnam(?string $a_temp_path=null)
Returns a unique and non existing Path for e temporary file or directory.
static delDir(string $a_dir, bool $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
addMapping(string $a_comp, string $a_entity, string $a_old_id, string $a_new_id)
getMapping(string $a_comp, string $a_entity, string $a_old_id)
User class.
static _uploadPersonalPicture(string $tmp_file, int $obj_id)
Create a personal picture image file from a temporary image file.
static _getPersonalPicturePath(int $a_usr_id, string $a_size="small", bool $a_force_pic=false, bool $a_prevent_no_photo_image=false, bool $html_export=false)
static copyProfilePicturesToDirectory(int $a_user_id, string $a_dir)
static _lookupType(int $id, bool $reference=false)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getXmlNamespace(string $a_entity, string $a_schema_version)
afterXmlRecordWriting(string $a_entity, string $a_version, array $a_set)
getXmlRecord(string $a_entity, string $a_version, array $a_set)
Get xml record for version.
getTypes(string $a_entity, string $a_version)
Get (abstract) types for (abstract) field names.
importRecord(string $a_entity, array $a_types, array $a_rec, ilImportMapping $a_mapping, string $a_schema_version)
Needs to be overwritten for import use case.
readData(string $a_entity, string $a_version, array $a_ids)
Read data from DB.
Class ilUserProfile.
static userSettingVisible(string $a_setting)
Checks whether user setting is visible.
static secureString(string $a_str, bool $a_strip_html=true, string $a_allow="")
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
global $ilSetting
Definition: privfeed.php:17