ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
4 include_once("./Services/DataSet/classes/class.ilDataSet.php");
5 
13 class ilUserDataSet extends ilDataSet
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");
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  case "5.1.0":
57  case "5.2.0":
58  return array(
59  "Id" => "integer",
60  "Username" => "text",
61  "Firstname" => "text",
62  "Lastname" => "text",
63  "Title" => "text",
64  "Birthday" => "text",
65  "Gender" => "text",
66  "Institution" => "text",
67  "Department" => "text",
68  "Street" => "text",
69  "Zipcode" => "text",
70  "City" => "text",
71  "Country" => "text",
72  "SelCountry" => "text",
73  "PhoneOffice" => "text",
74  "PhoneHome" => "text",
75  "PhoneMobile" => "text",
76  "Fax" => "text",
77  "Email" => "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  {
91  switch ($a_version)
92  {
93  case "4.3.0":
94  case "4.5.0":
95  case "5.1.0":
96  case "5.2.0":
97  return array(
98  "UserId" => "integer",
99  "Keyword" => "text",
100  "Value" => "text"
101  );
102  }
103  }
104 
105  if ($a_entity == "personal_data")
106  {
107  switch ($a_version)
108  {
109  case "4.3.0":
110  case "4.5.0":
111  case "5.1.0":
112  case "5.2.0":
113  return array(
114  "Id" => "integer"
115  );
116  }
117  }
118 
119  if ($a_entity == "usr_multi")
120  {
121  switch ($a_version)
122  {
123  case "4.5.0":
124  case "5.1.0":
125  case "5.2.0":
126  return array(
127  "UserId" => "integer",
128  "FieldId" => "text",
129  "Value" => "text"
130  );
131  }
132  }
133  }
134 
135 
142  function getXmlRecord($a_entity, $a_version, $a_set)
143  {
144  global $ilLog;
145 
146  if ($a_entity == "usr_profile")
147  {
148  $tmp_dir = ilUtil::ilTempnam();
149  ilUtil::makeDir($tmp_dir);
150  include_once("./Services/User/classes/class.ilObjUser.php");
151 
152  $im = ilObjUser::_getPersonalPicturePath($a_set["Id"], "small", true,
153  true);
154 
155  if ($im != "")
156  {
157  ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
158  }
159 
160  $this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
161 
162  $a_set["Picture"] = $tmp_dir;
163  }
164 
165  return $a_set;
166  }
167 
174  function afterXmlRecordWriting($a_entity, $a_version, $a_set)
175  {
176  if ($a_entity == "usr_profile")
177  {
178  // cleanup temp dirs for pictures
179  $tmp_dir = $this->temp_picture_dirs[$a_set["Id"]];
180  if ($tmp_dir != "" && is_dir($tmp_dir))
181  {
182  ilUtil::delDir($tmp_dir);
183  }
184  }
185  }
186 
193  function readData($a_entity, $a_version, $a_ids, $a_field = "")
194  {
195  global $ilDB;
196 
197  if (!is_array($a_ids))
198  {
199  $a_ids = array($a_ids);
200  }
201 
202  if ($a_entity == "personal_data")
203  {
204  switch ($a_version)
205  {
206  case "4.3.0":
207  case "4.5.0":
208  case "5.1.0":
209  case "5.2.0":
210  $this->data = array();
211  foreach ($a_ids as $id)
212  {
213  $this->data[] = array("Id" => $id);
214  }
215  break;
216  }
217  }
218 
219  if ($a_entity == "usr_profile")
220  {
221  switch ($a_version)
222  {
223  case "4.3.0":
224  case "4.5.0":
225  case "5.1.0":
226  $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, ".
227  " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, ".
228  " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, ".
229  " delicious, latitude, longitude, loc_zoom".
230  " FROM usr_data u ".
231  "WHERE ".
232  $ilDB->in("u.usr_id", $a_ids, false, "integer"));
233  break;
234 
235  case "5.2.0":
236  $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, ".
237  " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, ".
238  " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, ".
239  " latitude, longitude, loc_zoom".
240  " FROM usr_data u ".
241  "WHERE ".
242  $ilDB->in("u.usr_id", $a_ids, false, "integer"));
243  break;
244  }
245  }
246 
247  if ($a_entity == "usr_setting")
248  {
249  switch ($a_version)
250  {
251  case "4.3.0":
252  case "4.5.0":
253  case "5.1.0":
254  case "5.2.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",
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  {
269  unset(
270  $prefs['public_im_aim'], $prefs['public_im_icq'], $prefs['public_im_jabber'],
271  $prefs['public_im_msn'], $prefs['public_im_skype'], $prefs['public_im_voip'],
272  $prefs['public_im_yahoo'], $prefs['public_delicious']
273  );
274  }
275 
276  $this->data = array();
277  $set = $ilDB->query("SELECT * FROM usr_pref ".
278  " WHERE ".$ilDB->in("keyword", $prefs, false, "text").
279  " AND ".$ilDB->in("usr_id", $a_ids, false, "integer"));
280  while ($rec = $ilDB->fetchAssoc($set))
281  {
282  $this->data[] = array("UserId" => $rec["usr_id"], "Keyword" => $rec["keyword"], "Value" => $rec["value"]);
283  }
284  break;
285  }
286  }
287 
288  if ($a_entity == "usr_multi")
289  {
290  switch ($a_version)
291  {
292  case "4.5.0":
293  case "5.1.0":
294  case "5.2.0":
295  $this->data = array();
296  $set = $ilDB->query("SELECT * FROM usr_data_multi".
297  " WHERE ".$ilDB->in("usr_id", $a_ids, false, "integer"));
298  while ($rec = $ilDB->fetchAssoc($set))
299  {
300  $this->data[] = array("UserId" => $rec["usr_id"], "FieldId" => $rec["field_id"], "Value" => $rec["value"]);
301  }
302  break;
303  }
304  }
305  }
306 
310  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
311  {
312  return false;
313  switch ($a_entity)
314  {
315  case "personal_data":
316  return array (
317  "usr_profile" => array("ids" => $a_rec["Id"]),
318  "usr_setting" => array("ids" => $a_rec["Id"]),
319  "usr_multi" => array("ids" => $a_rec["Id"])
320  );
321  }
322  return false;
323  }
324 
325 
332  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
333  {
334  global $ilSetting, $ilUser;
335 //echo $a_entity;
336 //var_dump($a_rec);
337 
338  switch ($a_entity)
339  {
340  case "personal_data":
341  // only users themselves import their profiles!
342  // thus we can map the import id of the dataset to the current user
343  $a_mapping->addMapping("Services/User", "usr", $a_rec["Id"], $ilUser->getId());
344  break;
345 
346  case "usr_profile":
347  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["Id"]);
348  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
349  {
350  if (!isset($this->users[$usr_id]))
351  {
352  $this->users[$usr_id] = new ilObjUser($usr_id);
353  }
354  $user = $this->users[$usr_id];
355  include_once("./Services/User/classes/class.ilUserProfile.php");
356  $prof = new ilUserProfile();
357  $prof->skipField("username");
358  $prof->skipField("password");
359  $prof->skipField("roles");
360  $prof->skipGroup("settings");
361  $fields = $prof->getStandardFields();
362  foreach ($fields as $k => $f)
363  {
364  $up_k = $this->convertToLeadingUpper($k);
365  // only change fields, when it is possible in profile
367  !$ilSetting->get("usr_settings_disable_".$k) &&
368  $f["method"] != "" && isset($a_rec[$up_k]))
369  {
370  $set_method = "set".substr($f["method"], 3);
371  $user->{$set_method}(ilUtil::secureString($a_rec[$up_k]));
372 // echo "<br>-setting-".$set_method."-".$a_rec[$up_k]."-";
373  }
374  }
375  $user->update();
376 
377  // personal picture
378  $pic_dir = $this->getImportDirectory()."/".str_replace("..", "", $a_rec["Picture"]);
379  if ($pic_dir != "" && is_dir($pic_dir))
380  {
381  $upload_file = $pic_dir."/upload_".$a_rec["Id"]."pic";
382  if (is_file($upload_file))
383  {
384  ilObjUser::_uploadPersonalPicture($upload_file, $user->getId());
385  }
386  }
387  }
388  break;
389 
390  case "usr_setting":
391  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
392  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
393  {
394  if (!isset($this->users[$usr_id]))
395  {
396  $this->users[$usr_id] = new ilObjUser($usr_id);
397  }
398  $user = $this->users[$usr_id];
399  $user->writePref($a_rec["Keyword"], ilUtil::secureString($a_rec["Value"]));
400  }
401  break;
402 
403  case "usr_multi":
404  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
405  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
406  {
407  $this->multi[$usr_id][$a_rec["FieldId"]][] = ilUtil::secureString($a_rec["Value"]);
408  }
409  break;
410  }
411  }
412 }
413 ?>
Add some data
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 ...
static userSettingVisible($a_setting)
Checks whether user setting is visible.
Class ilUserProfile.
importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
Import record.
getImportDirectory()
Get import directory.
convertToLeadingUpper($a_str)
Make xyz_abc a XyzAbc string.
static copyProfilePicturesToDirectory($a_user_id, $a_dir)
Get profile picture direcotory.
$ilUser
Definition: imgupload.php:18
static _uploadPersonalPicture($tmp_file, $obj_id)
Create a personal picture image file from a temporary image file.
Exercise data set class.
Create styles array
The data for the language used.
static _lookupType($a_id, $a_reference=false)
lookup object type
readData($a_entity, $a_version, $a_ids, $a_field="")
Read data.
static makeDir($a_dir)
creates a new directory and inherits all filesystem permissions of the parent directory You may pass ...
getDependencies($a_entity, $a_version, $a_rec, $a_ids)
Determine the dependent sets of data.
static ilTempnam($a_temp_path=null)
Create a temporary file in an ILIAS writable directory.
getXmlNamespace($a_entity, $a_schema_version)
Get xml namespace.
getSupportedVersions()
Get supported versions.
global $ilSetting
Definition: privfeed.php:17
static _getPersonalPicturePath($a_usr_id, $a_size="small", $a_force_pic=false, $a_prevent_no_photo_image=false)
Get path to personal picture.
global $ilDB
static secureString($a_str, $a_strip_html=true, $a_allow="")
Remove unsecure tags.
getXmlRecord($a_entity, $a_version, $a_set)
Get xml record.
A dataset contains in data in a common structure that can be shared and transformed for different pur...
getTypes($a_entity, $a_version)
Get field types for entity.
static delDir($a_dir, $a_clean_only=false)
removes a dir and all its content (subdirs and files) recursively
afterXmlRecordWriting($a_entity, $a_version, $a_set)
After xml record writing hook record.