ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilUserXMLWriter Class Reference

XML writer class Class to simplify manual writing of xml documents. More...

+ Inheritance diagram for ilUserXMLWriter:
+ Collaboration diagram for ilUserXMLWriter:

Public Member Functions

 setAttachRoles (bool $value)
 
 setObjects (array $users)
 
 start ()
 
 getXML ()
 
 __buildHeader ()
 
 __buildFooter ()
 
 __handleUser (array $row)
 
 __addElementMulti (string $tagname, array $value, ?array $attrs=null, ?string $settingsname=null, bool $requiredTag=false)
 
 __addElement (string $tagname, ?string $value, ?array $attrs=null, ?string $settingsname=null, bool $requiredTag=false)
 
 setSettings (array $settings)
 
 setAttachPreferences (bool $attach_preferences)
 if set to true, all preferences of a user will be set More...
 
- Public Member Functions inherited from ilXmlWriter
 __construct (string $version="1.0", string $outEnc="utf-8", string $inEnc="utf-8")
 
 xmlSetDtdDef (string $dtdDef)
 Sets dtd definition. More...
 
 xmlSetGenCmt (string $genCmt)
 Sets generated comment. More...
 
 xmlFormatData (string $data)
 Indents text for better reading. More...
 
 xmlHeader ()
 Writes xml header. More...
 
 xmlStartTag (string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
 Writes a starttag. More...
 
 xmlEndTag (string $tag)
 Writes an endtag. More...
 
 xmlData (string $data, bool $encode=true, bool $escape=true)
 Writes data. More...
 
 xmlElement (string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
 Writes a basic element (no children, just textual content) More...
 
 xmlDumpFile (string $file, bool $format=true)
 Dumps xml document from memory into a file. More...
 
 xmlDumpMem (bool $format=true)
 Returns xml document from memory. More...
 
 appendXML (string $a_str)
 append xml string to document More...
 
 xmlClear ()
 clears xmlStr More...
 

Static Public Member Functions

static getExportablePreferences ()
 return exportable preference keys as found in db More...
 
static isPrefExportable (string $key)
 returns wether a key from db is exportable or not More...
 

Private Member Functions

 __handlePreferences (array $prefs, array $row)
 
 canExport (string $tagname, ?string $settingsname=null)
 
 getPictureValue (int $usr_id)
 return array with base-encoded picture data as key value, encoding type as encoding, and image type as key type. More...
 
 addUDFsToXML ()
 add user defined field data to xml (using usr dtd) More...
 

Private Attributes

ILIAS $ilias
 
ilDBInterface $db
 
Language $lng
 
Profile $user_profile
 
array $users
 
int $user_id = 0
 
bool $attach_roles = false
 
bool $attach_preferences = false
 
array $settings = []
 fields to be exported More...
 

Detailed Description

XML writer class Class to simplify manual writing of xml documents.

It only supports writing xml sequentially, because the xml document is saved in a string with no additional structure information. The author is responsible for well-formedness and validity of the xml document.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om

Definition at line 34 of file class.ilUserXMLWriter.php.

Member Function Documentation

◆ __addElement()

ilUserXMLWriter::__addElement ( string  $tagname,
?string  $value,
?array  $attrs = null,
?string  $settingsname = null,
bool  $requiredTag = false 
)

Definition at line 293 of file class.ilUserXMLWriter.php.

299 : void {
300 if ($this->canExport($tagname, $settingsname)
301 && ($value !== null
302 || $requiredTag
303 || is_array($attrs) && count($attrs) > 0)) {
304 $this->xmlElement($tagname, $attrs, (string) $value);
305 }
306 }
canExport(string $tagname, ?string $settingsname=null)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)

Referenced by __addElementMulti(), and __handleUser().

+ Here is the caller graph for this function:

◆ __addElementMulti()

ilUserXMLWriter::__addElementMulti ( string  $tagname,
array  $value,
?array  $attrs = null,
?string  $settingsname = null,
bool  $requiredTag = false 
)

Definition at line 281 of file class.ilUserXMLWriter.php.

287 : void {
288 foreach ($value as $item) {
289 $this->__addElement($tagname, $item, $attrs, $settingsname, $requiredTag);
290 }
291 }
__addElement(string $tagname, ?string $value, ?array $attrs=null, ?string $settingsname=null, bool $requiredTag=false)

References __addElement().

Referenced by __handleUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __buildFooter()

ilUserXMLWriter::__buildFooter ( )

Definition at line 111 of file class.ilUserXMLWriter.php.

111 : void
112 {
113 $this->xmlEndTag('Users');
114 }
xmlEndTag(string $tag)
Writes an endtag.

References ilXmlWriter\xmlEndTag().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __buildHeader()

ilUserXMLWriter::__buildHeader ( )

Definition at line 102 of file class.ilUserXMLWriter.php.

102 : void
103 {
104 $this->xmlSetDtdDef('<!DOCTYPE Users PUBLIC "-//ILIAS//DTD UserImport//EN" "' . ILIAS_HTTP_PATH . '/components/ILIAS/Export/xml/ilias_user_5_1.dtd">');
105 $this->xmlSetGenCmt('User of ilias system');
106 $this->xmlHeader();
107
108 $this->xmlStartTag('Users');
109 }
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlHeader()
Writes xml header.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.

References ilXmlWriter\xmlHeader(), ilXmlWriter\xmlSetDtdDef(), ilXmlWriter\xmlSetGenCmt(), and ilXmlWriter\xmlStartTag().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __handlePreferences()

ilUserXMLWriter::__handlePreferences ( array  $prefs,
array  $row 
)
private

Definition at line 263 of file class.ilUserXMLWriter.php.

263 : void // Missing array type.
264 {
265 //todo nadia: test mail_address_option
266 $mailOptions = new ilMailOptions($row['usr_id']);
267 $prefs['mail_incoming_type'] = $mailOptions->getIncomingType();
268 $prefs['mail_address_option'] = $mailOptions->getEmailAddressMode();
269 $prefs['mail_signature'] = $mailOptions->getSignature();
270 if ($prefs !== []) {
271 $this->xmlStartTag('Prefs');
272 foreach ($prefs as $key => $value) {
273 if (self::isPrefExportable($key)) {
274 $this->xmlElement('Pref', ['key' => $key], $value);
275 }
276 }
277 $this->xmlEndTag('Prefs');
278 }
279 }

References ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by __handleUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __handleUser()

ilUserXMLWriter::__handleUser ( array  $row)

Definition at line 116 of file class.ilUserXMLWriter.php.

116 : void // Missing array type.
117 {
118 if ($this->settings === []) {
120 }
121
122 $prefs = ilObjUser::_getPreferences($row['usr_id']);
123
124 if ($row['language'] === null
125 || $row['language'] === '') {
126 $row['language'] = $this->lng->getDefaultLanguage();
127 }
128
129 $attrs = [
130 'Id' => 'il_' . IL_INST_ID . '_usr_' . $row['usr_id'],
131 'Language' => $row['language'],
132 'Action' => 'Update'
133 ];
134
135 $this->xmlStartTag('User', $attrs);
136
137 $this->xmlElement('Login', null, $row['login']);
138
139 if ($this->attach_roles == true) {
140 $query = sprintf(
141 'SELECT object_data.title, object_data.description, rbac_fa.* ' .
142 'FROM object_data, rbac_ua, rbac_fa WHERE rbac_ua.usr_id = %s ' .
143 'AND rbac_ua.rol_id = rbac_fa.rol_id AND object_data.obj_id = rbac_fa.rol_id',
144 $this->db->quote($row['usr_id'], 'integer')
145 );
146 $rbacresult = $this->db->query($query);
147
148 while ($rbacrow = $rbacresult->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) {
149 if ($rbacrow['assign'] != 'y') {
150 continue;
151 }
152
153 $type = '';
154
155 if ($rbacrow['parent'] == ROLE_FOLDER_ID) {
156 $type = 'Global';
157 } else {
158 $type = 'Local';
159 }
160 if ($type !== '') {
161 $this->xmlElement(
162 'Role',
163 ['Id' => 'il_' . IL_INST_ID . '_role_' . $rbacrow['rol_id'], 'Type' => $type],
164 $rbacrow['title']
165 );
166 }
167 }
168 }
169
170 $this->__addElement('Firstname', $row['firstname']);
171 $this->__addElement('Lastname', $row['lastname']);
172 $this->__addElement('Title', $row['title']);
173
174 if ($this->canExport('PersonalPicture', 'upload')) {
175 $imageData = $this->getPictureValue($row['usr_id']);
176 if ($imageData) {
177 $value = array_shift($imageData); //$imageData['value'];
178 $this->__addElement('PersonalPicture', $value, $imageData, 'upload');
179 }
180 }
181
182
183 $this->__addElement('Gender', $row['gender']);
184 $this->__addElement('Email', $row['email']);
185 $this->__addElement('SecondEmail', $row['second_email'], null, 'second_email');
186 $this->__addElement('Birthday', $row['birthday']);
187 $this->__addElement('Institution', $row['institution']);
188 $this->__addElement('Street', $row['street']);
189 $this->__addElement('City', $row['city']);
190 $this->__addElement('PostalCode', $row['zipcode'], null, 'zipcode');
191 $this->__addElement('Country', $row['country']);
192 $this->__addElement('SelCountry', $row['sel_country'], null, 'sel_country');
193 $this->__addElement('PhoneOffice', $row['phone_office'], null, 'phone_office');
194 $this->__addElement('PhoneHome', $row['phone_home'], null, 'phone_home');
195 $this->__addElement('PhoneMobile', $row['phone_mobile'], null, 'phone_mobile');
196 $this->__addElement('Fax', $row['fax']);
197 $this->__addElement('Hobby', $row['hobby']);
198
199 $this->__addElementMulti('GeneralInterest', $row['interests_general'] ?? [], null, 'interests_general');
200 $this->__addElementMulti('OfferingHelp', $row['interests_help_offered'] ?? [], null, 'interests_help_offered');
201 $this->__addElementMulti('LookingForHelp', $row['interests_help_looking'] ?? [], null, 'interests_help_looking');
202
203 $this->__addElement('Department', $row['department']);
204 $this->__addElement('Comment', $row['referral_comment'], null, 'referral_comment');
205 $this->__addElement('Matriculation', $row['matriculation']);
206 $this->__addElement('Active', $row['active'] ? 'true' : 'false');
207 $this->__addElement('ClientIP', $row['client_ip'], null, 'client_ip');
208 $this->__addElement('TimeLimitOwner', $row['time_limit_owner'], null, 'time_limit_owner');
209 $this->__addElement('TimeLimitUnlimited', $row['time_limit_unlimited'], null, 'time_limit_unlimited');
210 $this->__addElement('TimeLimitFrom', $row['time_limit_from'], null, 'time_limit_from');
211 $this->__addElement('TimeLimitUntil', $row['time_limit_until'], null, 'time_limit_until');
212 $this->__addElement('TimeLimitMessage', $row['time_limit_message'], null, 'time_limit_message');
213 $this->__addElement('ApproveDate', $row['approve_date'], null, 'approve_date');
214 $this->__addElement('AgreeDate', $row['agree_date'], null, 'agree_date');
215
216 if ($row['auth_mode'] !== null
217 && $row['auth_mode'] !== '') {
218 $this->__addElement('AuthMode', null, ['type' => $row['auth_mode']], 'auth_mode', true);
219 }
220
221 if ($row['ext_account'] !== null
222 && $row['ext_account'] !== '') {
223 $this->__addElement('ExternalAccount', $row['ext_account'], null, 'ext_account', true);
224 }
225
226 if (isset($prefs['skin'])
227 && isset($prefs['style'])
228 && $this->canExport('Look', 'skin_style')) {
229 $this->__addElement(
230 'Look',
231 null,
232 [
233 'Skin' => $prefs['skin'], 'Style' => $prefs['style']
234 ],
235 'skin_style',
236 true
237 );
238 }
239
240
241 $this->__addElement('LastUpdate', $row['last_update'], null, 'last_update');
242 $this->__addElement('LastLogin', $row['last_login'], null, 'last_login');
243
244 $udf_data = $this->addUDFsToXML();
245
246 $this->__addElement('AccountInfo', $row['ext_account'], ['Type' => 'external']);
247
248 $this->__addElement('GMapsInfo', null, [
249 'longitude' => $row['longitude'],
250 'latitude' => $row['latitude'],
251 'zoom' => $row['loc_zoom']]);
252
253 $this->__addElement('Feedhash', $row['feed_hash']);
254
255 if ($this->attach_preferences || $this->canExport('prefs', 'preferences')) {
256 $this->__handlePreferences($prefs, $row);
257 }
258
259 $this->xmlEndTag('User');
260 }
static _getPreferences(int $user_id)
getPictureValue(int $usr_id)
return array with base-encoded picture data as key value, encoding type as encoding,...
addUDFsToXML()
add user defined field data to xml (using usr dtd)
__handlePreferences(array $prefs, array $row)
setSettings(array $settings)
__addElementMulti(string $tagname, array $value, ?array $attrs=null, ?string $settingsname=null, bool $requiredTag=false)
const IL_INST_ID
Definition: constants.php:40
const ROLE_FOLDER_ID
Definition: constants.php:34

References __addElement(), __addElementMulti(), __handlePreferences(), ilObjUser\_getPreferences(), addUDFsToXML(), canExport(), ilDBConstants\FETCHMODE_ASSOC, ilObjUserFolder\getExportSettings(), getPictureValue(), IL_INST_ID, ILIAS\Repository\lng(), ROLE_FOLDER_ID, setSettings(), ILIAS\Repository\settings(), ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addUDFsToXML()

ilUserXMLWriter::addUDFsToXML ( )
private

add user defined field data to xml (using usr dtd)

Definition at line 358 of file class.ilUserXMLWriter.php.

358 : void
359 {
360 foreach ($this->user_profile->getVisibleFields(Context::Export) as $field) {
361 $this->xmlElement(
362 'UserDefinedField',
363 [
364 'Id' => $field->getIdentifier(),
365 'Name' => $field->getName($this->lng)
366 ],
367 (string) ($this->user_data['f_' . $field->getIdentifier()] ?? '')
368 );
369 }
370 }

Referenced by __handleUser(), and start().

+ Here is the caller graph for this function:

◆ canExport()

ilUserXMLWriter::canExport ( string  $tagname,
?string  $settingsname = null 
)
private

Definition at line 308 of file class.ilUserXMLWriter.php.

311 : bool {
312 return $this->settings === []
313 || in_array(strtolower($tagname), $this->settings) !== false
314 || in_array($settingsname, $this->settings) !== false;
315 }

Referenced by __handleUser().

+ Here is the caller graph for this function:

◆ getExportablePreferences()

static ilUserXMLWriter::getExportablePreferences ( )
static

return exportable preference keys as found in db

Definition at line 375 of file class.ilUserXMLWriter.php.

375 : array // Missing array type.
376 {
377 return [
378 'public_city',
379 'public_country',
380 'public_department',
381 'public_email',
382 'public_second_email',
383 'public_fax',
384 'public_hobby',
385 'public_institution',
386 'public_matriculation',
387 'public_phone',
388 'public_phone_home',
389 'public_phone_mobile',
390 'public_phone_office',
391 'public_profile',
392 'public_street',
393 'public_upload',
394 'public_zip',
395 'send_info_mails',
396 /*'show_users_online',*/
397 'hide_own_online_status',
398 'bs_allow_to_contact_me',
399 'chat_osc_accept_msg',
400 'chat_broadcast_typing',
401 'user_tz',
402 'weekstart',
403 'mail_incoming_type',
404 'mail_signature',
405 'mail_linebreak',
406 'public_interests_general',
407 'public_interests_help_offered',
408 'public_interests_help_looking'
409 ];
410 }

◆ getPictureValue()

ilUserXMLWriter::getPictureValue ( int  $usr_id)
private

return array with base-encoded picture data as key value, encoding type as encoding, and image type as key type.

Definition at line 334 of file class.ilUserXMLWriter.php.

334 : ?array
335 {
336 $avatar_resolver = new ilUserAvatarResolver($usr_id);
337 $avatar_resolver->setForcePicture(true);
338 if (!$avatar_resolver->hasProfilePicture()) {
339 return null;
340 }
341
342 [$image_data, $image_type] = $avatar_resolver->getUserPictureForVCard();
343
344 if ($image_data === null || $image_type === null) {
345 return null;
346 }
347
348 return [
349 'value' => base64_encode($image_data),
350 'encoding' => 'Base64',
351 'imagetype' => $image_type
352 ];
353 }
Class ilUserAvatarResolver.

Referenced by __handleUser().

+ Here is the caller graph for this function:

◆ getXML()

ilUserXMLWriter::getXML ( )

Definition at line 96 of file class.ilUserXMLWriter.php.

96 : string
97 {
98 return $this->xmlDumpMem(false);
99 }
xmlDumpMem(bool $format=true)
Returns xml document from memory.

References ilXmlWriter\xmlDumpMem().

+ Here is the call graph for this function:

◆ isPrefExportable()

static ilUserXMLWriter::isPrefExportable ( string  $key)
static

returns wether a key from db is exportable or not

Definition at line 415 of file class.ilUserXMLWriter.php.

415 : bool
416 {
417 return in_array($key, self::getExportablePreferences());
418 }

Referenced by ilUserImportParser\importEndTag(), and ilUserImportParser\verifyPref().

+ Here is the caller graph for this function:

◆ setAttachPreferences()

ilUserXMLWriter::setAttachPreferences ( bool  $attach_preferences)

if set to true, all preferences of a user will be set

Definition at line 325 of file class.ilUserXMLWriter.php.

325 : void
326 {
327 $this->attach_preferences = $attach_preferences;
328 }

◆ setAttachRoles()

ilUserXMLWriter::setAttachRoles ( bool  $value)

Definition at line 66 of file class.ilUserXMLWriter.php.

66 : void
67 {
68 $this->attach_roles = $value;
69 }

◆ setObjects()

ilUserXMLWriter::setObjects ( array  $users)

Definition at line 71 of file class.ilUserXMLWriter.php.

71 : void // Missing array type.
72 {
73 $this->users = $users;
74 }

References $users.

◆ setSettings()

ilUserXMLWriter::setSettings ( array  $settings)

Definition at line 317 of file class.ilUserXMLWriter.php.

317 : void // Missing array type.
318 {
319 $this->settings = $settings;
320 }
array $settings
fields to be exported

References ILIAS\Repository\settings().

Referenced by __handleUser().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start()

ilUserXMLWriter::start ( )

Definition at line 77 of file class.ilUserXMLWriter.php.

77 : bool
78 {
79 if (!is_array($this->users)) {
80 return false;
81 }
82
83 $this->__buildHeader();
84
85 $this->addUDFsToXML();
86
87 foreach ($this->users as $user) {
88 $this->__handleUser($user);
89 }
90
91 $this->__buildFooter();
92
93 return true;
94 }

References __buildFooter(), __buildHeader(), __handleUser(), and addUDFsToXML().

+ Here is the call graph for this function:

Field Documentation

◆ $attach_preferences

bool ilUserXMLWriter::$attach_preferences = false
private

Definition at line 43 of file class.ilUserXMLWriter.php.

◆ $attach_roles

bool ilUserXMLWriter::$attach_roles = false
private

Definition at line 42 of file class.ilUserXMLWriter.php.

◆ $db

ilDBInterface ilUserXMLWriter::$db
private

Definition at line 37 of file class.ilUserXMLWriter.php.

◆ $ilias

ILIAS ilUserXMLWriter::$ilias
private

Definition at line 36 of file class.ilUserXMLWriter.php.

◆ $lng

Language ilUserXMLWriter::$lng
private

Definition at line 38 of file class.ilUserXMLWriter.php.

◆ $settings

array ilUserXMLWriter::$settings = []
private

fields to be exported

Definition at line 49 of file class.ilUserXMLWriter.php.

◆ $user_id

int ilUserXMLWriter::$user_id = 0
private

Definition at line 41 of file class.ilUserXMLWriter.php.

◆ $user_profile

Profile ilUserXMLWriter::$user_profile
private

Definition at line 39 of file class.ilUserXMLWriter.php.

◆ $users

array ilUserXMLWriter::$users
private

Definition at line 40 of file class.ilUserXMLWriter.php.

Referenced by setObjects().


The documentation for this class was generated from the following file: