ILIAS  release_8 Revision v8.24
class.ilUserXMLWriter.php
Go to the documentation of this file.
1<?php
2
29{
30 public ILIAS $ilias;
31 public array $users; // Missing array type.
32 public int $user_id = 0;
33 public bool $attachRoles = false;
34 public bool $attachPreferences = false;
35
40 private array $settings = [];
41
42 public function __construct()
43 {
44 global $DIC;
45
46 $ilias = $DIC['ilias'];
47 $ilUser = $DIC->user();
48
50
51 $this->ilias = $ilias;
52 $this->user_id = $ilUser->getId();
53 $this->attachRoles = false;
54 }
55
56 public function setAttachRoles(bool $value): void
57 {
58 $this->attachRoles = $value;
59 }
60
61 public function setObjects(array $users): void // Missing array type.
62 {
63 $this->users = $users;
64 }
65
66
67 public function start(): bool
68 {
69 if (!is_array($this->users)) {
70 return false;
71 }
72
73 $this->__buildHeader();
74
76 $udf_data->addToXML($this);
77
78 foreach ($this->users as $user) {
79 $this->__handleUser($user);
80 }
81
82 $this->__buildFooter();
83
84 return true;
85 }
86
87 public function getXML(): string
88 {
89 return $this->xmlDumpMem(false);
90 }
91
92
93 public function __buildHeader(): void
94 {
95 $this->xmlSetDtdDef("<!DOCTYPE Users PUBLIC \"-//ILIAS//DTD UserImport//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_user_5_1.dtd\">");
96 $this->xmlSetGenCmt("User of ilias system");
97 $this->xmlHeader();
98
99 $this->xmlStartTag('Users');
100 }
101
102 public function __buildFooter(): void
103 {
104 $this->xmlEndTag('Users');
105 }
106
107 public function __handleUser(array $row): void // Missing array type.
108 {
109 global $DIC;
110
111 $ilDB = $DIC['ilDB'];
112 $lng = $DIC['lng'];
113 if ($this->settings === []) {
115 }
116
117 $prefs = ilObjUser::_getPreferences($row["usr_id"]);
118
119 if (strlen($row["language"]) == 0) {
120 $row["language"] = $lng->getDefaultLanguage();
121 }
122
123 $attrs = [
124 'Id' => "il_" . IL_INST_ID . "_usr_" . $row["usr_id"],
125 'Language' => $row["language"],
126 'Action' => "Update"
127 ];
128
129 $this->xmlStartTag("User", $attrs);
130
131 $this->xmlElement("Login", null, $row["login"]);
132
133 if ($this->attachRoles == true) {
134 $query = sprintf(
135 "SELECT object_data.title, object_data.description, rbac_fa.* " .
136 "FROM object_data, rbac_ua, rbac_fa WHERE rbac_ua.usr_id = %s " .
137 "AND rbac_ua.rol_id = rbac_fa.rol_id AND object_data.obj_id = rbac_fa.rol_id",
138 $ilDB->quote($row["usr_id"], 'integer')
139 );
140 $rbacresult = $ilDB->query($query);
141
142 while ($rbacrow = $rbacresult->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
143 if ($rbacrow["assign"] != "y") {
144 continue;
145 }
146
147 $type = "";
148
149 if ($rbacrow["parent"] == ROLE_FOLDER_ID) {
150 $type = "Global";
151 } else {
152 $type = "Local";
153 }
154 if (strlen($type)) {
155 $this->xmlElement(
156 "Role",
157 array("Id" =>
158 "il_" . IL_INST_ID . "_role_" . $rbacrow["rol_id"], "Type" => $type),
159 $rbacrow["title"]
160 );
161 }
162 }
163 }
164
165 $this->__addElement("Firstname", $row["firstname"]);
166 $this->__addElement("Lastname", $row["lastname"]);
167 $this->__addElement("Title", $row["title"]);
168
169 if ($this->canExport("PersonalPicture", "upload")) {
170 $imageData = $this->getPictureValue($row["usr_id"]);
171 if ($imageData) {
172 $value = array_shift($imageData); //$imageData["value"];
173 $this->__addElement("PersonalPicture", $value, $imageData, "upload");
174 }
175 }
176
177
178 $this->__addElement("Gender", $row["gender"]);
179 $this->__addElement("Email", $row["email"]);
180 $this->__addElement("SecondEmail", $row["second_email"], null, "second_email");
181 $this->__addElement("Birthday", $row["birthday"]);
182 $this->__addElement("Institution", $row["institution"]);
183 $this->__addElement("Street", $row["street"]);
184 $this->__addElement("City", $row["city"]);
185 $this->__addElement("PostalCode", $row["zipcode"], null, "zipcode");
186 $this->__addElement("Country", $row["country"]);
187 $this->__addElement("SelCountry", $row["sel_country"], null, "sel_country");
188 $this->__addElement("PhoneOffice", $row["phone_office"], null, "phone_office");
189 $this->__addElement("PhoneHome", $row["phone_home"], null, "phone_home");
190 $this->__addElement("PhoneMobile", $row["phone_mobile"], null, "phone_mobile");
191 $this->__addElement("Fax", $row["fax"]);
192 $this->__addElement("Hobby", $row["hobby"]);
193
194 $this->__addElementMulti("GeneralInterest", $row["interests_general"] ?? [], null, "interests_general");
195 $this->__addElementMulti("OfferingHelp", $row["interests_help_offered"] ?? [], null, "interests_help_offered");
196 $this->__addElementMulti("LookingForHelp", $row["interests_help_looking"] ?? [], null, "interests_help_looking");
197
198 $this->__addElement("Department", $row["department"]);
199 $this->__addElement("Comment", $row["referral_comment"], null, "referral_comment");
200 $this->__addElement("Matriculation", $row["matriculation"]);
201 $this->__addElement("Active", $row["active"] ? "true" : "false");
202 $this->__addElement("ClientIP", $row["client_ip"], null, "client_ip");
203 $this->__addElement("TimeLimitOwner", $row["time_limit_owner"], null, "time_limit_owner");
204 $this->__addElement("TimeLimitUnlimited", $row["time_limit_unlimited"], null, "time_limit_unlimited");
205 $this->__addElement("TimeLimitFrom", $row["time_limit_from"], null, "time_limit_from");
206 $this->__addElement("TimeLimitUntil", $row["time_limit_until"], null, "time_limit_until");
207 $this->__addElement("TimeLimitMessage", $row["time_limit_message"], null, "time_limit_message");
208 $this->__addElement("ApproveDate", $row["approve_date"], null, "approve_date");
209 $this->__addElement("AgreeDate", $row["agree_date"], null, "agree_date");
210
211 if (strlen($row["auth_mode"]) > 0) {
212 $this->__addElement("AuthMode", null, array("type" => $row["auth_mode"]), "auth_mode", true);
213 }
214
215 if (strlen($row["ext_account"]) > 0) {
216 $this->__addElement("ExternalAccount", $row["ext_account"], null, "ext_account", true);
217 }
218
219 if (isset($prefs['skin'])
220 && isset($prefs['style'])
221 && $this->canExport('Look', 'skin_style')) {
222 $this->__addElement(
223 'Look',
224 null,
225 [
226 'Skin' => $prefs['skin'], 'Style' => $prefs['style']
227 ],
228 'skin_style',
229 true
230 );
231 }
232
233
234 $this->__addElement("LastUpdate", $row["last_update"], null, "last_update");
235 $this->__addElement("LastLogin", $row["last_login"], null, "last_login");
236
237 $udf_data = new ilUserDefinedData($row['usr_id']);
238 $udf_data->addToXML($this);
239
240 $this->__addElement("AccountInfo", $row["ext_account"], array("Type" => "external"));
241
242 $this->__addElement("GMapsInfo", null, array(
243 "longitude" => $row["longitude"],
244 "latitude" => $row["latitude"],
245 "zoom" => $row["loc_zoom"]));
246
247 $this->__addElement("Feedhash", $row["feed_hash"]);
248
249 if ($this->attachPreferences || $this->canExport("prefs", "preferences")) {
250 $this->__handlePreferences($prefs, $row);
251 }
252
253 $this->xmlEndTag('User');
254 }
255
256
257 private function __handlePreferences(array $prefs, array $row): void // Missing array type.
258 {
259 //todo nadia: test mail_address_option
260 $mailOptions = new ilMailOptions($row["usr_id"]);
261 $prefs["mail_incoming_type"] = $mailOptions->getIncomingType();
262 $prefs["mail_address_option"] = $mailOptions->getEmailAddressMode();
263 $prefs["mail_signature"] = $mailOptions->getSignature();
264 $prefs["mail_linebreak"] = $mailOptions->getLinebreak();
265 if (count($prefs)) {
266 $this->xmlStartTag("Prefs");
267 foreach ($prefs as $key => $value) {
268 if (self::isPrefExportable($key)) {
269 $this->xmlElement("Pref", array("key" => $key), $value);
270 }
271 }
272 $this->xmlEndTag("Prefs");
273 }
274 }
275
276 public function __addElementMulti(
277 string $tagname,
278 array $value,
279 ?array $attrs = null,
280 ?string $settingsname = null,
281 bool $requiredTag = false
282 ): void {
283 if (is_array($value) && count($value)) {
284 foreach ($value as $item) {
285 $this->__addElement($tagname, $item, $attrs, $settingsname, $requiredTag);
286 }
287 }
288 }
289
290 public function __addElement(
291 string $tagname,
292 ?string $value,
293 array $attrs = null,
294 ?string $settingsname = null,
295 bool $requiredTag = false
296 ): void {
297 if ($this->canExport($tagname, $settingsname)) {
298 if (strlen($value) > 0 || $requiredTag || (is_array($attrs) && count($attrs) > 0)) {
299 $this->xmlElement($tagname, $attrs, (string) $value);
300 }
301 }
302 }
303
304 private function canExport(
305 string $tagname,
306 ?string $settingsname = null
307 ): bool {
308 return $this->settings === []
309 || in_array(strtolower($tagname), $this->settings) !== false
310 || in_array($settingsname, $this->settings) !== false;
311 }
312
313 public function setSettings(array $settings): void // Missing array type.
314 {
315 $this->settings = $settings;
316 }
317
322 private function getPictureValue(int $usr_id): ?array
323 {
324 global $DIC;
325
326 $ilDB = $DIC['ilDB'];
327 // personal picture
328 $q = sprintf(
329 "SELECT value FROM usr_pref WHERE usr_id = %s AND keyword = %s",
330 $ilDB->quote($usr_id, "integer"),
331 $ilDB->quote('profile_image', "text")
332 );
333 $r = $ilDB->query($q);
334 if ($ilDB->numRows($r) == 1) {
335 $personal_picture_data = $r->fetchRow(ilDBConstants::FETCHMODE_ASSOC);
336 $personal_picture = $personal_picture_data["value"];
337 $webspace_dir = ilFileUtils::getWebspaceDir();
338 $image_file = $webspace_dir . "/usr_images/" . $personal_picture;
339 if (is_file($image_file)) {
340 $fh = fopen($image_file, "rb");
341 if ($fh) {
342 $image_data = fread($fh, filesize($image_file));
343 fclose($fh);
344 $base64 = base64_encode($image_data);
345 $imagetype = "image/jpeg";
346 if (preg_match("/.*\.(png|gif)$/", $personal_picture, $matches)) {
347 $imagetype = "image/" . $matches[1];
348 }
349 return array(
350 "value" => $base64,
351 "encoding" => "Base64",
352 "imagetype" => $imagetype
353 );
354 }
355 }
356 }
357 return null;
358 }
359
360
364 public function setAttachPreferences(bool $attachPrefs): void
365 {
366 $this->attachPreferences = $attachPrefs;
367 }
368
372 public static function getExportablePreferences(): array // Missing array type.
373 {
374 return array(
375 'hits_per_page',
376 'public_city',
377 'public_country',
378 'public_department',
379 'public_email',
380 'public_second_email',
381 'public_fax',
382 'public_hobby',
383 'public_institution',
384 'public_matriculation',
385 'public_phone',
386 'public_phone_home',
387 'public_phone_mobile',
388 'public_phone_office',
389 'public_profile',
390 'public_street',
391 'public_upload',
392 'public_zip',
393 'send_info_mails',
394 /*'show_users_online',*/
395 'hide_own_online_status',
396 'bs_allow_to_contact_me',
397 'chat_osc_accept_msg',
398 'chat_broadcast_typing',
399 'user_tz',
400 'weekstart',
401 'mail_incoming_type',
402 'mail_signature',
403 'mail_linebreak',
404 'public_interests_general',
405 'public_interests_help_offered',
406 'public_interests_help_looking'
407 );
408 }
409
413 public static function isPrefExportable(string $key): bool
414 {
415 return in_array($key, self::getExportablePreferences());
416 }
417}
static getWebspaceDir(string $mode="filesystem")
get webspace directory
Class ilMailOptions this class handles user mails.
static _getPreferences(int $user_id)
get preferences for user
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
getPictureValue(int $usr_id)
return array with base-encoded picture data as key value, encoding type as encoding,...
static isPrefExportable(string $key)
returns wether a key from db is exportable or not
canExport(string $tagname, ?string $settingsname=null)
array $settings
fields to be exported
__handlePreferences(array $prefs, array $row)
static getExportablePreferences()
return exportable preference keys as found in db
__addElement(string $tagname, ?string $value, array $attrs=null, ?string $settingsname=null, bool $requiredTag=false)
setSettings(array $settings)
setObjects(array $users)
__addElementMulti(string $tagname, array $value, ?array $attrs=null, ?string $settingsname=null, bool $requiredTag=false)
setAttachPreferences(bool $attachPrefs)
if set to true, all preferences of a user will be set
setAttachRoles(bool $value)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlHeader()
Writes xml header.
xmlEndTag(string $tag)
Writes an endtag.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
if(!file_exists(getcwd() . '/ilias.ini.php'))
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: confirmReg.php:20
const IL_INST_ID
Definition: constants.php:40
const ROLE_FOLDER_ID
Definition: constants.php:34
return['3gp', '7z', 'ai', 'aif', 'aifc', 'aiff', 'au', 'arw', 'avi', 'backup', 'bak', 'bas', 'bpmn', 'bpmn2', 'bmp', 'bib', 'bibtex', 'bz', 'bz2', 'c', 'c++', 'cc', 'cct', 'cdf', 'cer', 'class', 'cls', 'conf', 'cpp', 'crt', 'crs', 'crw', 'cr2', 'css', 'cst', 'csv', 'cur', 'db', 'dcr', 'des', 'dng', 'doc', 'docx', 'dot', 'dotx', 'dtd', 'dvi', 'el', 'eps', 'epub', 'f', 'f77', 'f90', 'flv', 'for', 'g3', 'gif', 'gl', 'gan', 'ggb', 'gsd', 'gsm', 'gtar', 'gz', 'gzip', 'h', 'hpp', 'htm', 'html', 'htmls', 'ibooks', 'ico', 'ics', 'ini', 'ipynb', 'java', 'jbf', 'jpeg', 'jpg', 'js', 'jsf', 'jso', 'json', 'latex', 'lang', 'less', 'log', 'lsp', 'ltx', 'm1v', 'm2a', 'm2v', 'm3u', 'm4a', 'm4v', 'markdown', 'm', 'mat', 'md', 'mdl', 'mdown', 'mid', 'min', 'midi', 'mobi', 'mod', 'mov', 'movie', 'mp2', 'mp3', 'mp4', 'mpa', 'mpeg', 'mpg', 'mph', 'mpga', 'mpp', 'mpt', 'mpv', 'mpx', 'mv', 'mw', 'mv4', 'nb', 'nbp', 'nef', 'nif', 'niff', 'obj', 'obm', 'odt', 'ods', 'odp', 'odg', 'odf', 'oga', 'ogg', 'ogv', 'old', 'p', 'pas', 'pbm', 'pcl', 'pct', 'pcx', 'pdf', 'pgm', 'pic', 'pict', 'png', 'por', 'pov', 'project', 'properties', 'ppa', 'ppm', 'pps', 'ppsx', 'ppt', 'pptx', 'ppz', 'ps', 'psd', 'pwz', 'qt', 'qtc', 'qti', 'qtif', 'r', 'ra', 'ram', 'rar', 'rast', 'rda', 'rev', 'rexx', 'ris', 'rf', 'rgb', 'rm', 'rmd', 'rmi', 'rmm', 'rmp', 'rt', 'rtf', 'rtx', 'rv', 's', 's3m', 'sav', 'sbs', 'sec', 'sdml', 'sgm', 'sgml', 'smi', 'smil', 'srt', 'sps', 'spv', 'stl', 'svg', 'swa', 'swf', 'swz', 'tar', 'tex', 'texi', 'texinfo', 'text', 'tgz', 'tif', 'tiff', 'ttf', 'txt', 'tmp', 'uvproj', 'vdf', 'vimeo', 'viv', 'vivo', 'vrml', 'vsdx', 'wav', 'webm', 'wmv', 'wmx', 'wmz', 'woff', 'wwd', 'xhtml', 'xif', 'xls', 'xlsx', 'xmind', 'xml', 'xsl', 'xsd', 'zip']
global $DIC
Definition: feed.php:28
$ilUser
Definition: imgupload.php:34
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
string $key
Consumer key/client ID value.
Definition: System.php:193
array $settings
Setting values (LTI parameters, custom parameters and local parameters).
Definition: System.php:200
Class ChatMainBarProvider \MainMenu\Provider.
header include for all ilias files.
$query
$type
$lng