ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilUserDataSet.php
Go to the documentation of this file.
1<?php
2/* Copyright (c) 1998-2010 ILIAS open source, Extended GPL, see docs/LICENSE */
3
4include_once("./Services/DataSet/classes/class.ilDataSet.php");
5
14{
15 protected $temp_picture_dirs = array();
16
17 public $multi = array();
18
25 public function getSupportedVersions()
26 {
27 return array("4.3.0", "4.5.0", "5.1.0", "5.2.0", "5.3.0");
28 }
29
36 public function getXmlNamespace($a_entity, $a_schema_version)
37 {
38 return "http://www.ilias.de/xml/Services/User/" . $a_entity;
39 }
40
47 protected function getTypes($a_entity, $a_version)
48 {
49 // user profile type
50 if ($a_entity == "usr_profile") {
51 switch ($a_version) {
52 case "4.3.0":
53 case "4.5.0":
54 case "5.1.0":
55 case "5.2.0":
56 case "5.3.0":
57 return array(
58 "Id" => "integer",
59 "Username" => "text",
60 "Firstname" => "text",
61 "Lastname" => "text",
62 "Title" => "text",
63 "Birthday" => "text",
64 "Gender" => "text",
65 "Institution" => "text",
66 "Department" => "text",
67 "Street" => "text",
68 "Zipcode" => "text",
69 "City" => "text",
70 "Country" => "text",
71 "SelCountry" => "text",
72 "PhoneOffice" => "text",
73 "PhoneHome" => "text",
74 "PhoneMobile" => "text",
75 "Fax" => "text",
76 "Email" => "text",
77 "SecondEmail" => "text",
78 "Hobby" => "text",
79 "ReferralComment" => "text",
80 "Matriculation" => "text",
81 "Latitude" => "text",
82 "Longitude" => "text",
83 "LocZoom" => "text",
84 "Picture" => "directory"
85 );
86 }
87 }
88
89 if ($a_entity == "usr_setting") {
90 switch ($a_version) {
91 case "4.3.0":
92 case "4.5.0":
93 case "5.1.0":
94 case "5.2.0":
95 case "5.3.0":
96 return array(
97 "UserId" => "integer",
98 "Keyword" => "text",
99 "Value" => "text"
100 );
101 }
102 }
103
104 if ($a_entity == "personal_data") {
105 switch ($a_version) {
106 case "4.3.0":
107 case "4.5.0":
108 case "5.1.0":
109 case "5.2.0":
110 case "5.3.0":
111 return array(
112 "Id" => "integer"
113 );
114 }
115 }
116
117 if ($a_entity == "usr_multi") {
118 switch ($a_version) {
119 case "4.5.0":
120 case "5.1.0":
121 case "5.2.0":
122 case "5.3.0":
123 return array(
124 "UserId" => "integer",
125 "FieldId" => "text",
126 "Value" => "text"
127 );
128 }
129 }
130 }
131
132
139 public function getXmlRecord($a_entity, $a_version, $a_set)
140 {
141 global $ilLog;
142
143 if ($a_entity == "usr_profile") {
144 $tmp_dir = ilUtil::ilTempnam();
145 ilUtil::makeDir($tmp_dir);
146 include_once("./Services/User/classes/class.ilObjUser.php");
147
148 $im = ilObjUser::_getPersonalPicturePath(
149 $a_set["Id"],
150 "small",
151 true,
152 true
153 );
154
155 if ($im != "") {
156 ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
157 }
158
159 $this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
160
161 $a_set["Picture"] = $tmp_dir;
162 }
163
164 return $a_set;
165 }
166
173 public function afterXmlRecordWriting($a_entity, $a_version, $a_set)
174 {
175 if ($a_entity == "usr_profile") {
176 // cleanup temp dirs for pictures
177 $tmp_dir = $this->temp_picture_dirs[$a_set["Id"]];
178 if ($tmp_dir != "" && is_dir($tmp_dir)) {
179 ilUtil::delDir($tmp_dir);
180 }
181 }
182 }
183
190 public function readData($a_entity, $a_version, $a_ids, $a_field = "")
191 {
192 global $ilDB;
193
194 if (!is_array($a_ids)) {
195 $a_ids = array($a_ids);
196 }
197
198 if ($a_entity == "personal_data") {
199 switch ($a_version) {
200 case "4.3.0":
201 case "4.5.0":
202 case "5.1.0":
203 case "5.2.0":
204 case "5.3.0":
205 $this->data = array();
206 foreach ($a_ids as $id) {
207 $this->data[] = array("Id" => $id);
208 }
209 break;
210 }
211 }
212
213 if ($a_entity == "usr_profile") {
214 switch ($a_version) {
215 case "4.3.0":
216 case "4.5.0":
217 case "5.1.0":
218 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
219 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, " .
220 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, " .
221 " delicious, latitude, longitude, loc_zoom" .
222 " FROM usr_data u " .
223 "WHERE " .
224 $ilDB->in("u.usr_id", $a_ids, false, "integer"));
225 break;
226
227 case "5.2.0":
228 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
229 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, " .
230 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, " .
231 " latitude, longitude, loc_zoom" .
232 " FROM usr_data u " .
233 "WHERE " .
234 $ilDB->in("u.usr_id", $a_ids, false, "integer"));
235 break;
236 case "5.3.0":
237 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, " .
238 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, " .
239 " phone_office, phone_home, phone_mobile, fax, email, second_email, hobby, referral_comment, matriculation, " .
240 " latitude, longitude, loc_zoom" .
241 " FROM usr_data u " .
242 "WHERE " .
243 $ilDB->in("u.usr_id", $a_ids, false, "integer"));
244 break;
245 }
246 }
247
248 if ($a_entity == "usr_setting") {
249 switch ($a_version) {
250 case "4.3.0":
251 case "4.5.0":
252 case "5.1.0":
253 case "5.2.0":
254 case "5.3.0":
255 // for all user ids get data from usr_pref and mail options, create records user_id/name/value
256 $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",
257 "public_birthday", "puplic_city", "public_country", "public_delicious", "public_department", "public_email", "public_second_email",
258 "public_fax", "public_gender", "public_hobby", "public_im_aim", "public_im_icq", "public_im_jabber",
259 "public_im_msn", "public_im_skype", "public_im_voip", "public_im_yahoo", "public_institution", "public_location",
260 "public_matriculation", "public_phone_home", "public_phone_mobile", "public_phone_office",
261 "public_profile", "public_sel_country", "public_street", "public_title", "public_upload", "public_zipcode",
262 "screen_reader_optimization", "show_users_online",
263 "store_last_visited", "time_format", "user_tz", "weekstart",
264 "session_reminder_enabled", "session_reminder_lead_time", "usr_starting_point",
265 "char_selector_availability", "char_selector_definition");
266
267 if (version_compare($a_version, '5.2.0', '>=')) {
268 unset(
269 $prefs['public_im_aim'], $prefs['public_im_icq'], $prefs['public_im_jabber'],
270 $prefs['public_im_msn'], $prefs['public_im_skype'], $prefs['public_im_voip'],
271 $prefs['public_im_yahoo'], $prefs['public_delicious']
272 );
273 }
274
275 $this->data = array();
276 $set = $ilDB->query("SELECT * FROM usr_pref " .
277 " WHERE " . $ilDB->in("keyword", $prefs, false, "text") .
278 " AND " . $ilDB->in("usr_id", $a_ids, false, "integer"));
279 while ($rec = $ilDB->fetchAssoc($set)) {
280 $this->data[] = array("UserId" => $rec["usr_id"], "Keyword" => $rec["keyword"], "Value" => $rec["value"]);
281 }
282 break;
283 }
284 }
285
286 if ($a_entity == "usr_multi") {
287 switch ($a_version) {
288 case "4.5.0":
289 case "5.1.0":
290 case "5.2.0":
291 case "5.3.0":
292 $this->data = array();
293 $set = $ilDB->query("SELECT * FROM usr_data_multi" .
294 " WHERE " . $ilDB->in("usr_id", $a_ids, false, "integer"));
295 while ($rec = $ilDB->fetchAssoc($set)) {
296 $this->data[] = array("UserId" => $rec["usr_id"], "FieldId" => $rec["field_id"], "Value" => $rec["value"]);
297 }
298 break;
299 }
300 }
301 }
302
306 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
307 {
308 return false;
309 switch ($a_entity) {
310 case "personal_data":
311 return array(
312 "usr_profile" => array("ids" => $a_rec["Id"]),
313 "usr_setting" => array("ids" => $a_rec["Id"]),
314 "usr_multi" => array("ids" => $a_rec["Id"])
315 );
316 }
317 return false;
318 }
319
320
327 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
328 {
329 global $ilSetting, $ilUser;
330 //echo $a_entity;
331 //var_dump($a_rec);
332
333 switch ($a_entity) {
334 case "personal_data":
335 // only users themselves import their profiles!
336 // thus we can map the import id of the dataset to the current user
337 $a_mapping->addMapping("Services/User", "usr", $a_rec["Id"], $ilUser->getId());
338 break;
339
340 case "usr_profile":
341 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["Id"]);
342 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
343 if (!isset($this->users[$usr_id])) {
344 $this->users[$usr_id] = new ilObjUser($usr_id);
345 }
346 $user = $this->users[$usr_id];
347 include_once("./Services/User/classes/class.ilUserProfile.php");
348 $prof = new ilUserProfile();
349 $prof->skipField("username");
350 $prof->skipField("password");
351 $prof->skipField("roles");
352 $prof->skipGroup("settings");
353 $fields = $prof->getStandardFields();
354 foreach ($fields as $k => $f) {
355 $up_k = $this->convertToLeadingUpper($k);
356 // only change fields, when it is possible in profile
358 !$ilSetting->get("usr_settings_disable_" . $k) &&
359 $f["method"] != "" && isset($a_rec[$up_k])) {
360 $set_method = "set" . substr($f["method"], 3);
361 $user->{$set_method}(ilUtil::secureString($a_rec[$up_k]));
362 }
363 }
364
365 $user->setLatitude($a_rec["Latitude"]);
366 $user->setLongitude($a_rec["Longitude"]);
367 $user->setLocationZoom($a_rec["LocZoom"]);
368
369 $user->update();
370
371 // personal picture
372 $pic_dir = $this->getImportDirectory() . "/" . str_replace("..", "", $a_rec["Picture"]);
373 if ($pic_dir != "" && is_dir($pic_dir)) {
374 $upload_file = $pic_dir . "/upload_" . $a_rec["Id"] . "pic";
375 if (is_file($upload_file)) {
376 ilObjUser::_uploadPersonalPicture($upload_file, $user->getId());
377 }
378 }
379 }
380 break;
381
382 case "usr_setting":
383 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
384 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
385 if (!isset($this->users[$usr_id])) {
386 $this->users[$usr_id] = new ilObjUser($usr_id);
387 }
388 $user = $this->users[$usr_id];
389 $user->writePref($a_rec["Keyword"], ilUtil::secureString($a_rec["Value"]));
390 }
391 break;
392
393 case "usr_multi":
394 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
395 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr") {
396 $this->multi[$usr_id][$a_rec["FieldId"]][] = ilUtil::secureString($a_rec["Value"]);
397 }
398 break;
399 }
400 }
401}
An exception for terminatinating execution or to throw for unit testing.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getDirectDataFromQuery($a_query, $a_convert_to_leading_upper=true, $a_set=true)
Get data from query.This is a standard procedure, all db field names are directly mapped to abstract ...
getImportDirectory()
Get import directory.
convertToLeadingUpper($a_str)
Make xyz_abc a XyzAbc string.
static copyProfilePicturesToDirectory($a_user_id, $a_dir)
Get profile picture direcotory.
static _uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
static _lookupType($a_id, $a_reference=false)
lookup object type
Exercise data set class.
afterXmlRecordWriting($a_entity, $a_version, $a_set)
After xml record writing hook record.
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
getSupportedVersions()
Get supported versions.
getTypes($a_entity, $a_version)
Get field types for entity.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record.
Class ilUserProfile.
static userSettingVisible($a_setting)
Checks whether user setting is visible.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
if(!array_key_exists('StateId', $_REQUEST)) $id
global $ilSetting
Definition: privfeed.php:17
global $ilDB
$this data['403_header']
$ilUser
Definition: imgupload.php:18