ILIAS  Release_4_4_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 
23  public function getSupportedVersions()
24  {
25  return array("4.3.0");
26  }
27 
34  function getXmlNamespace($a_entity, $a_schema_version)
35  {
36  return "http://www.ilias.de/xml/Services/User/".$a_entity;
37  }
38 
45  protected function getTypes($a_entity, $a_version)
46  {
47  // user profile type
48  if ($a_entity == "usr_profile")
49  {
50  switch ($a_version)
51  {
52  case "4.3.0":
53  return array(
54  "Id" => "integer",
55  "Username" => "text",
56  "Firstname" => "text",
57  "Lastname" => "text",
58  "Title" => "text",
59  "Birthday" => "text",
60  "Gender" => "text",
61  "Institution" => "text",
62  "Department" => "text",
63  "Street" => "text",
64  "Zipcode" => "text",
65  "City" => "text",
66  "Country" => "text",
67  "SelCountry" => "text",
68  "PhoneOffice" => "text",
69  "PhoneHome" => "text",
70  "PhoneMobile" => "text",
71  "Fax" => "text",
72  "Email" => "text",
73  "Hobby" => "text",
74  "ReferralComment" => "text",
75  "Matriculation" => "text",
76  "Delicious" => "text",
77  "Latitude" => "text",
78  "Longitude" => "text",
79  "Picture" => "directory"
80  );
81  }
82  }
83 
84  if ($a_entity == "usr_setting")
85  {
86  switch ($a_version)
87  {
88  case "4.3.0":
89  return array(
90  "UserId" => "integer",
91  "Keyword" => "text",
92  "Value" => "text"
93  );
94  }
95  }
96 
97  if ($a_entity == "personal_data")
98  {
99  switch ($a_version)
100  {
101  case "4.3.0":
102  return array(
103  "Id" => "integer"
104  );
105  }
106  }
107 
108  }
109 
110 
117  function getXmlRecord($a_entity, $a_version, $a_set)
118  {
119  global $ilLog;
120 
121  if ($a_entity == "usr_profile")
122  {
123  $tmp_dir = ilUtil::ilTempnam();
124  ilUtil::makeDir($tmp_dir);
125  include_once("./Services/User/classes/class.ilObjUser.php");
126  ilObjUser::copyProfilePicturesToDirectory($a_set["Id"], $tmp_dir);
127 
128  $this->temp_picture_dirs[$a_set["Id"]] = $tmp_dir;
129 
130  $a_set["Picture"] = $tmp_dir;
131  }
132 
133  return $a_set;
134  }
135 
142  function afterXmlRecordWriting($a_entity, $a_version, $a_set)
143  {
144  if ($a_entity == "usr_profile")
145  {
146  // cleanup temp dirs for pictures
147  $tmp_dir = $this->temp_picture_dirs[$a_set["Id"]];
148  if ($tmp_dir != "" && is_dir($tmp_dir))
149  {
150  ilUtil::delDir($tmp_dir);
151  }
152  }
153  }
154 
161  function readData($a_entity, $a_version, $a_ids, $a_field = "")
162  {
163  global $ilDB;
164 
165  if (!is_array($a_ids))
166  {
167  $a_ids = array($a_ids);
168  }
169 
170  if ($a_entity == "personal_data")
171  {
172  switch ($a_version)
173  {
174  case "4.3.0":
175  $this->data = array();
176  foreach ($a_ids as $id)
177  {
178  $this->data[] = array("Id" => $id);
179  }
180  break;
181  }
182  }
183 
184  if ($a_entity == "usr_profile")
185  {
186  switch ($a_version)
187  {
188  case "4.3.0":
189  $this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, ".
190  " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, ".
191  " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, ".
192  " delicious, latitude, longitude".
193  " FROM usr_data u ".
194  "WHERE ".
195  $ilDB->in("u.usr_id", $a_ids, false, "integer"));
196  break;
197  }
198  }
199 
200  if ($a_entity == "usr_setting")
201  {
202  switch ($a_version)
203  {
204  case "4.3.0":
205  // for all user ids get data from usr_pref and mail options, create records user_id/name/value
206  $prefs = array("date_format", "day_end", "day_start", "hide_own_online_status", "hits_per_page", "language",
207  "public_birthday", "puplic_city", "public_country", "public_delicious", "public_department", "public_email",
208  "public_fax", "public_gender", "public_hobby", "public_im_aim", "public_im_icq", "public_im_jabber",
209  "public_im_msn", "public_im_skype", "public_im_voip", "public_im_yahoo", "public_institution", "public_location",
210  "public_matriculation", "public_phone_home", "public_phone_mobile", "public_phone_office", "public_profile",
211  "public_sel_country", "public_street", "public_title", "public_upload", "public_zipcode",
212  "screen_reader_optimization", "show_users_online",
213  "store_last_visited", "time_format", "user_tz", "weekstart");
214  $this->data = array();
215  $set = $ilDB->query("SELECT * FROM usr_pref ".
216  " WHERE ".$ilDB->in("keyword", $prefs, false, "text").
217  " AND ".$ilDB->in("usr_id", $a_ids, false, "integer"));
218  while ($rec = $ilDB->fetchAssoc($set))
219  {
220  $this->data[] = array("UserId" => $rec["usr_id"], "Keyword" => $rec["keyword"], "Value" => $rec["value"]);
221  }
222 
223  /*
224  require_once 'Services/Mail/classes/class.ilMailOptions.php';
225  $mailOptions = new ilMailOptions($ilUser->getId());
226 
227  /*$this->getDirectDataFromQuery("SELECT usr_id id, login username, firstname, lastname, ".
228  " title, birthday, gender, institution, department, street, city, zipcode, country, sel_country, ".
229  " phone_office, phone_home, phone_mobile, fax, email, hobby, referral_comment, matriculation, ".
230  " delicious, latitude, longitude".
231  " FROM usr_data u ".
232  "WHERE ".
233  $ilDB->in("u.usr_id", $a_ids, false, "integer"));*/
234  break;
235  }
236  }
237 
238  }
239 
243  protected function getDependencies($a_entity, $a_version, $a_rec, $a_ids)
244  {
245  return false;
246  switch ($a_entity)
247  {
248  case "personal_data":
249  return array (
250  "usr_profile" => array("ids" => $a_rec["Id"]),
251  "usr_setting" => array("ids" => $a_rec["Id"])
252  );
253  }
254  return false;
255  }
256 
257 
264  function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
265  {
266  global $ilSetting, $ilUser;
267 //echo $a_entity;
268 //var_dump($a_rec);
269 
270  switch ($a_entity)
271  {
272  case "personal_data":
273  // only users themselves import their profiles!
274  // thus we can map the import id of the dataset to the current user
275  $a_mapping->addMapping("Services/User", "usr", $a_rec["Id"], $ilUser->getId());
276  break;
277 
278  case "usr_profile":
279  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["Id"]);
280  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
281  {
282  if (!isset($this->users[$usr_id]))
283  {
284  $this->users[$usr_id] = new ilObjUser($usr_id);
285  }
286  $user = $this->users[$usr_id];
287  include_once("./Services/User/classes/class.ilUserProfile.php");
288  $prof = new ilUserProfile();
289  $prof->skipField("username");
290  $prof->skipField("password");
291  $prof->skipField("roles");
292  $prof->skipGroup("settings");
293  $fields = $prof->getStandardFields();
294  foreach ($fields as $k => $f)
295  {
296  $up_k = $this->convertToLeadingUpper($k);
297  // only change fields, when it is possible in profile
299  !$ilSetting->get("usr_settings_disable_".$k) &&
300  $f["method"] != "" && isset($a_rec[$up_k]))
301  {
302  $set_method = "set".substr($f["method"], 3);
303  $user->{$set_method}(ilUtil::secureString($a_rec[$up_k]));
304 // echo "<br>-setting-".$set_method."-".$a_rec[$up_k]."-";
305  }
306  }
307  $user->update();
308 
309  // personal picture
310  $pic_dir = $this->getImportDirectory()."/".str_replace("..", "", $a_rec["Picture"]);
311  if ($pic_dir != "" && is_dir($pic_dir))
312  {
313  $upload_file = $pic_dir."/upload_".$a_rec["Id"]."pic";
314  if (is_file($upload_file))
315  {
316  ilObjUser::_uploadPersonalPicture($upload_file, $user->getId());
317  }
318  }
319  }
320  break;
321 
322  case "usr_setting":
323  $usr_id = $a_mapping->getMapping("Services/User", "usr", $a_rec["UserId"]);
324  if ($usr_id > 0 && ilObject::_lookupType($usr_id) == "usr")
325  {
326  if (!isset($this->users[$usr_id]))
327  {
328  $this->users[$usr_id] = new ilObjUser($usr_id);
329  }
330  $user = $this->users[$usr_id];
331  $user->writePref($a_rec["Keyword"], ilUtil::secureString($a_rec["Value"]));
332  }
333  break;
334  }
335  }
336 }
337 ?>