ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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");
28 }
29
36 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 {
52 switch ($a_version)
53 {
54 case "4.3.0":
55 case "4.5.0":
56 return array(
57 "Id" => "integer",
58 "Username" => "text",
59 "Firstname" => "text",
60 "Lastname" => "text",
61 "Title" => "text",
62 "Birthday" => "text",
63 "Gender" => "text",
64 "Institution" => "text",
65 "Department" => "text",
66 "Street" => "text",
67 "Zipcode" => "text",
68 "City" => "text",
69 "Country" => "text",
70 "SelCountry" => "text",
71 "PhoneOffice" => "text",
72 "PhoneHome" => "text",
73 "PhoneMobile" => "text",
74 "Fax" => "text",
75 "Email" => "text",
76 "Hobby" => "text",
77 "ReferralComment" => "text",
78 "Matriculation" => "text",
79 "Delicious" => "text",
80 "Latitude" => "text",
81 "Longitude" => "text",
82 "Picture" => "directory"
83 );
84 }
85 }
86
87 if ($a_entity == "usr_setting")
88 {
89 switch ($a_version)
90 {
91 case "4.3.0":
92 case "4.5.0":
93 return array(
94 "UserId" => "integer",
95 "Keyword" => "text",
96 "Value" => "text"
97 );
98 }
99 }
100
101 if ($a_entity == "personal_data")
102 {
103 switch ($a_version)
104 {
105 case "4.3.0":
106 case "4.5.0":
107 return array(
108 "Id" => "integer"
109 );
110 }
111 }
112
113 if ($a_entity == "usr_multi")
114 {
115 switch ($a_version)
116 {
117 case "4.5.0":
118 return array(
119 "UserId" => "integer",
120 "FieldId" => "text",
121 "Value" => "text"
122 );
123 }
124 }
125 }
126
127
134 function getXmlRecord($a_entity, $a_version, $a_set)
135 {
136 global $ilLog;
137
138 if ($a_entity == "usr_profile")
139 {
140 $tmp_dir = ilUtil::ilTempnam();
141 ilUtil::makeDir($tmp_dir);
142 include_once("./Services/User/classes/class.ilObjUser.php");
143 ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
144
145 $this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
146
147 $a_set["Picture"] = $tmp_dir;
148 }
149
150 return $a_set;
151 }
152
159 function afterXmlRecordWriting($a_entity, $a_version, $a_set)
160 {
161 if ($a_entity == "usr_profile")
162 {
163 // cleanup temp dirs for pictures
164 $tmp_dir = $this->temp_picture_dirs[$a_set["Id"]];
165 if ($tmp_dir != "" && is_dir($tmp_dir))
166 {
167 ilUtil::delDir($tmp_dir);
168 }
169 }
170 }
171
178 function readData($a_entity, $a_version, $a_ids, $a_field = "")
179 {
180 global $ilDB;
181
182 if (!is_array($a_ids))
183 {
184 $a_ids = array($a_ids);
185 }
186
187 if ($a_entity == "personal_data")
188 {
189 switch ($a_version)
190 {
191 case "4.3.0":
192 case "4.5.0":
193 $this->data = array();
194 foreach ($a_ids as $id)
195 {
196 $this->data[] = array("Id" => $id);
197 }
198 break;
199 }
200 }
201
202 if ($a_entity == "usr_profile")
203 {
204 switch ($a_version)
205 {
206 case "4.3.0":
207 case "4.5.0":
208 $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, ".
209 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, ".
210 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, ".
211 " delicious, latitude, longitude".
212 " FROM usr_data u ".
213 "WHERE ".
214 $ilDB->in("u.usr_id", $a_ids, false, "integer"));
215 break;
216 }
217 }
218
219 if ($a_entity == "usr_setting")
220 {
221 switch ($a_version)
222 {
223 case "4.3.0":
224 case "4.5.0":
225 case "5.1.0":
226 // for all user ids get data from usr_pref and mail options, create records user_id/name/value
227 $prefs = array("date_format", "day_end", "day_start", "bs_allow_to_contact_me", "hide_own_online_status", "hits_per_page", "language",
228 "public_birthday", "puplic_city", "public_country", "public_delicious", "public_department", "public_email",
229 "public_fax", "public_gender", "public_hobby", "public_im_aim", "public_im_icq", "public_im_jabber",
230 "public_im_msn", "public_im_skype", "public_im_voip", "public_im_yahoo", "public_institution", "public_location",
231 "public_matriculation", "public_phone_home", "public_phone_mobile", "public_phone_office", "public_profile",
232 "public_sel_country", "public_street", "public_title", "public_upload", "public_zipcode",
233 "screen_reader_optimization", "show_users_online",
234 "store_last_visited", "time_format", "user_tz", "weekstart",
235 "session_reminder_enabled", "session_reminder_lead_time", "usr_starting_point",
236 "char_selector_availability", "char_selector_definition");
237 $this->data = array();
238 $set = $ilDB->query("SELECT * FROM usr_pref ".
239 " WHERE ".$ilDB->in("keyword", $prefs, false, "text").
240 " AND ".$ilDB->in("usr_id", $a_ids, false, "integer"));
241 while ($rec = $ilDB->fetchAssoc($set))
242 {
243 $this->data[] = array("UserId" => $rec["usr_id"], "Keyword" => $rec["keyword"], "Value" => $rec["value"]);
244 }
245
246 /*
247 require_once 'Services/Mail/classes/class.ilMailOptions.php';
248 $mailOptions = new ilMailOptions($ilUser->getId());
249
250 /*$this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, ".
251 " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, ".
252 " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, ".
253 " delicious, latitude, longitude".
254 " FROM usr_data u ".
255 "WHERE ".
256 $ilDB->in("u.usr_id", $a_ids, false, "integer"));*/
257 break;
258 }
259 }
260
261 if ($a_entity == "usr_multi")
262 {
263 switch ($a_version)
264 {
265 case "4.5.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 {
271 $this->data[] = array("UserId" => $rec["usr_id"], "FieldId" => $rec["field_id"], "Value" => $rec["value"]);
272 }
273 break;
274 }
275 }
276 }
277
281 protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
282 {
283 return false;
284 switch ($a_entity)
285 {
286 case "personal_data":
287 return array (
288 "usr_profile" => array("ids" => $a_rec["Id"]),
289 "usr_setting" => array("ids" => $a_rec["Id"]),
290 "usr_multi" => array("ids" => $a_rec["Id"])
291 );
292 }
293 return false;
294 }
295
296
303 function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
304 {
305 global $ilSetting, $ilUser;
306//echo $a_entity;
307//var_dump($a_rec);
308
309 switch ($a_entity)
310 {
311 case "personal_data":
312 // only users themselves import their profiles!
313 // thus we can map the import id of the dataset to the current user
314 $a_mapping->addMapping("Services/User", "usr", $a_rec["Id"], $ilUser->getId());
315 break;
316
317 case "usr_profile":
318 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["Id"]);
319 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
320 {
321 if (!isset($this->users[$usr_id]))
322 {
323 $this->users[$usr_id] = new ilObjUser($usr_id);
324 }
325 $user = $this->users[$usr_id];
326 include_once("./Services/User/classes/class.ilUserProfile.php");
327 $prof = new ilUserProfile();
328 $prof->skipField("username");
329 $prof->skipField("password");
330 $prof->skipField("roles");
331 $prof->skipGroup("settings");
332 $fields = $prof->getStandardFields();
333 foreach ($fields as $k => $f)
334 {
335 $up_k = $this->convertToLeadingUpper($k);
336 // only change fields, when it is possible in profile
338 !$ilSetting->get("usr_settings_disable_".$k) &&
339 $f["method"] != "" && isset($a_rec[$up_k]))
340 {
341 $set_method = "set".substr($f["method"], 3);
342 $user->{$set_method}(ilUtil::secureString($a_rec[$up_k]));
343// echo "<br>-setting-".$set_method."-".$a_rec[$up_k]."-";
344 }
345 }
346 $user->update();
347
348 // personal picture
349 $pic_dir = $this->getImportDirectory()."/".str_replace("..", "", $a_rec["Picture"]);
350 if ($pic_dir != "" && is_dir($pic_dir))
351 {
352 $upload_file = $pic_dir."/upload_".$a_rec["Id"]."pic";
353 if (is_file($upload_file))
354 {
355 ilObjUser::_uploadPersonalPicture($upload_file, $user->getId());
356 }
357 }
358 }
359 break;
360
361 case "usr_setting":
362 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
363 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
364 {
365 if (!isset($this->users[$usr_id]))
366 {
367 $this->users[$usr_id] = new ilObjUser($usr_id);
368 }
369 $user = $this->users[$usr_id];
370 $user->writePref($a_rec["Keyword"], ilUtil::secureString($a_rec["Value"]));
371 }
372 break;
373
374 case "usr_multi":
375 $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
376 if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
377 {
378 $this->multi[$usr_id][$a_rec["FieldId"]][] = ilUtil::secureString($a_rec["Value"]);
379 }
380 break;
381 }
382 }
383}
384?>
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)
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.
_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 ...
global $ilSetting
Definition: privfeed.php:40
global $ilDB
global $ilUser
Definition: imgupload.php:15