ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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");
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  // for all user ids get data from usr_pref and mail options, create records user_id/name/value
226  $prefs = array("date_format", "day_end", "day_start", "hide_own_online_status", "hits_per_page", "language",
227  "public_birthday", "puplic_city", "public_country", "public_delicious", "public_department", "public_email",
228  "public_fax", "public_gender", "public_hobby", "public_im_aim", "public_im_icq", "public_im_jabber",
229  "public_im_msn", "public_im_skype", "public_im_voip", "public_im_yahoo", "public_institution", "public_location",
230  "public_matriculation", "public_phone_home", "public_phone_mobile", "public_phone_office", "public_profile",
231  "public_sel_country", "public_street", "public_title", "public_upload", "public_zipcode",
232  "screen_reader_optimization", "show_users_online",
233  "store_last_visited", "time_format", "user_tz", "weekstart");
234  $this->data = array();
235  $set = $ilDB->query("SELECT * FROM usr_pref ".
236  " WHERE ".$ilDB->in("keyword", $prefs, false, "text").
237  " AND ".$ilDB->in("usr_id", $a_ids, false, "integer"));
238  while ($rec = $ilDB->fetchAssoc($set))
239  {
240  $this->data[] = array("UserId" => $rec["usr_id"], "Keyword" => $rec["keyword"], "Value" => $rec["value"]);
241  }
242 
243  /*
244  require_once 'Services/Mail/classes/class.ilMailOptions.php';
245  $mailOptions = new ilMailOptions($ilUser->getId());
246 
247  /*$this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, ".
248  " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, ".
249  " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, ".
250  " delicious, latitude, longitude".
251  " FROM usr_data u ".
252  "WHERE ".
253  $ilDB->in("u.usr_id", $a_ids, false, "integer"));*/
254  break;
255  }
256  }
257 
258  if ($a_entity == "usr_multi")
259  {
260  switch ($a_version)
261  {
262  case "4.5.0":
263  $this->data = array();
264  $set = $ilDB->query("SELECT * FROM usr_data_multi".
265  " WHERE ".$ilDB->in("usr_id", $a_ids, false, "integer"));
266  while ($rec = $ilDB->fetchAssoc($set))
267  {
268  $this->data[] = array("UserId" => $rec["usr_id"], "FieldId" => $rec["field_id"], "Value" => $rec["value"]);
269  }
270  break;
271  }
272  }
273  }
274 
278  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
279  {
280  return false;
281  switch ($a_entity)
282  {
283  case "personal_data":
284  return array (
285  "usr_profile" => array("ids" => $a_rec["Id"]),
286  "usr_setting" => array("ids" => $a_rec["Id"]),
287  "usr_multi" => array("ids" => $a_rec["Id"])
288  );
289  }
290  return false;
291  }
292 
293 
300  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
301  {
302  global $ilSetting, $ilUser;
303 //echo $a_entity;
304 //var_dump($a_rec);
305 
306  switch ($a_entity)
307  {
308  case "personal_data":
309  // only users themselves import their profiles!
310  // thus we can map the import id of the dataset to the current user
311  $a_mapping->addMapping("Services/User", "usr", $a_rec["Id"], $ilUser->getId());
312  break;
313 
314  case "usr_profile":
315  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["Id"]);
316  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
317  {
318  if (!isset($this->users[$usr_id]))
319  {
320  $this->users[$usr_id] = new ilObjUser($usr_id);
321  }
322  $user = $this->users[$usr_id];
323  include_once("./Services/User/classes/class.ilUserProfile.php");
324  $prof = new ilUserProfile();
325  $prof->skipField("username");
326  $prof->skipField("password");
327  $prof->skipField("roles");
328  $prof->skipGroup("settings");
329  $fields = $prof->getStandardFields();
330  foreach ($fields as $k => $f)
331  {
332  $up_k = $this->convertToLeadingUpper($k);
333  // only change fields, when it is possible in profile
335  !$ilSetting->get("usr_settings_disable_".$k) &&
336  $f["method"] != "" && isset($a_rec[$up_k]))
337  {
338  $set_method = "set".substr($f["method"], 3);
339  $user->{$set_method}(ilUtil::secureString($a_rec[$up_k]));
340 // echo "<br>-setting-".$set_method."-".$a_rec[$up_k]."-";
341  }
342  }
343  $user->update();
344 
345  // personal picture
346  $pic_dir = $this->getImportDirectory()."/".str_replace("..", "", $a_rec["Picture"]);
347  if ($pic_dir != "" && is_dir($pic_dir))
348  {
349  $upload_file = $pic_dir."/upload_".$a_rec["Id"]."pic";
350  if (is_file($upload_file))
351  {
352  ilObjUser::_uploadPersonalPicture($upload_file, $user->getId());
353  }
354  }
355  }
356  break;
357 
358  case "usr_setting":
359  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
360  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
361  {
362  if (!isset($this->users[$usr_id]))
363  {
364  $this->users[$usr_id] = new ilObjUser($usr_id);
365  }
366  $user = $this->users[$usr_id];
367  $user->writePref($a_rec["Keyword"], ilUtil::secureString($a_rec["Value"]));
368  }
369  break;
370 
371  case "usr_multi":
372  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
373  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
374  {
375  $this->multi[$usr_id][$a_rec["FieldId"]][] = ilUtil::secureString($a_rec["Value"]);
376  }
377  break;
378  }
379  }
380 }
381 ?>