ILIAS  trunk Revision v12.0_alpha-1221-g4e438232683
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)
 
 setFieldsToExport (array $fields_to_export)
 
 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 (array $row)
 add user defined field data to xml (using usr dtd) More...
 

Private Attributes

readonly ILIAS $ilias
 
readonly ilDBInterface $db
 
readonly Language $lng
 
readonly Profile $user_profile
 
readonly SettingsImplementation $user_settings
 
readonly UserSettingsDataRepository $user_settings_data_repo
 
array $users
 
int $user_id = 0
 
bool $attach_roles = false
 
bool $attach_preferences = false
 
array $fields_to_export = []
 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 39 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 320 of file class.ilUserXMLWriter.php.

326 : void {
327 if ($this->canExport($tagname, $settingsname)
328 && ($value !== null
329 || $requiredTag
330 || is_array($attrs) && count($attrs) > 0)) {
331 $this->xmlElement($tagname, $attrs, (string) $value);
332 }
333 }
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 308 of file class.ilUserXMLWriter.php.

314 : void {
315 foreach ($value as $item) {
316 $this->__addElement($tagname, $item, $attrs, $settingsname, $requiredTag);
317 }
318 }
__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 124 of file class.ilUserXMLWriter.php.

124 : void
125 {
126 $this->xmlEndTag('Users');
127 }
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 115 of file class.ilUserXMLWriter.php.

115 : void
116 {
117 $this->xmlSetDtdDef('<!DOCTYPE Users PUBLIC "-//ILIAS//DTD UserImport//EN" "' . ILIAS_HTTP_PATH . '/components/ILIAS/Export/xml/ilias_user_5_1.dtd">');
118 $this->xmlSetGenCmt('User of ilias system');
119 $this->xmlHeader();
120
121 $this->xmlStartTag('Users');
122 }
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 290 of file class.ilUserXMLWriter.php.

290 : void // Missing array type.
291 {
292 //todo nadia: test mail_address_option
293 $mailOptions = new ilMailOptions($row['usr_id']);
294 $prefs['mail_incoming_type'] = $mailOptions->getIncomingType();
295 $prefs['mail_address_option'] = $mailOptions->getEmailAddressMode();
296 $prefs['mail_signature'] = $mailOptions->getSignature();
297 if ($prefs !== []) {
298 $this->xmlStartTag('Prefs');
299 foreach ($prefs as $key => $value) {
300 if (self::isPrefExportable($key)) {
301 $this->xmlElement('Pref', ['key' => $key], $value);
302 }
303 }
304 $this->xmlEndTag('Prefs');
305 }
306 }

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 129 of file class.ilUserXMLWriter.php.

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

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

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

387 : void {
388 foreach ($this->user_profile->getVisibleFields(Context::Export) as $field) {
389 if (!$field->isCustom()) {
390 continue;
391 }
392 $this->xmlElement(
393 'UserDefinedField',
394 [
395 'Id' => $field->getIdentifier(),
396 'Name' => $field->getLabel($this->lng)
397 ],
398 json_encode($row[$field->getIdentifier()])
399 );
400 }
401 }

Referenced by __handleUser().

+ Here is the caller graph for this function:

◆ canExport()

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

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

338 : bool {
339 return $this->fields_to_export === []
340 || in_array(strtolower($tagname), $this->fields_to_export) !== false
341 || in_array($settingsname, $this->fields_to_export) !== false;
342 }

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 406 of file class.ilUserXMLWriter.php.

406 : array // Missing array type.
407 {
408 return [
409 'public_city',
410 'public_country',
411 'public_department',
412 'public_email',
413 'public_second_email',
414 'public_fax',
415 'public_hobby',
416 'public_institution',
417 'public_matriculation',
418 'public_phone',
419 'public_phone_home',
420 'public_phone_mobile',
421 'public_phone_office',
422 'public_profile',
423 'public_street',
424 'public_avatar',
425 'public_zip',
426 'send_info_mails',
427 /*'show_users_online',*/
428 'hide_own_online_status',
429 'bs_allow_to_contact_me',
430 'chat_osc_accept_msg',
431 'chat_broadcast_typing',
432 'user_tz',
433 'weekstart',
434 'mail_incoming_type',
435 'mail_signature',
436 'mail_linebreak',
437 'public_interests_general',
438 'public_interests_help_offered',
439 'public_interests_help_looking'
440 ];
441 }

◆ 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 361 of file class.ilUserXMLWriter.php.

361 : ?array
362 {
363 $avatar_resolver = new ilUserAvatarResolver($usr_id);
364 $avatar_resolver->setForcePicture(true);
365 if (!$avatar_resolver->hasProfilePicture()) {
366 return null;
367 }
368
369 [$image_data, $image_type] = $avatar_resolver->getUserPictureForVCard();
370
371 if ($image_data === null || $image_type === null) {
372 return null;
373 }
374
375 return [
376 'value' => base64_encode($image_data),
377 'encoding' => 'Base64',
378 'imagetype' => $image_type
379 ];
380 }
Class ilUserAvatarResolver.

Referenced by __handleUser().

+ Here is the caller graph for this function:

◆ getXML()

ilUserXMLWriter::getXML ( )

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

109 : string
110 {
111 return $this->xmlDumpMem(false);
112 }
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 446 of file class.ilUserXMLWriter.php.

446 : bool
447 {
448 return in_array($key, self::getExportablePreferences());
449 }

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 352 of file class.ilUserXMLWriter.php.

352 : void
353 {
354 $this->attach_preferences = $attach_preferences;
355 }

◆ setAttachRoles()

ilUserXMLWriter::setAttachRoles ( bool  $value)

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

81 : void
82 {
83 $this->attach_roles = $value;
84 }

◆ setFieldsToExport()

ilUserXMLWriter::setFieldsToExport ( array  $fields_to_export)

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

344 : void // Missing array type.
345 {
346 $this->fields_to_export = $fields_to_export;
347 }
array $fields_to_export
fields to be exported

Referenced by __handleUser().

+ Here is the caller graph for this function:

◆ setObjects()

ilUserXMLWriter::setObjects ( array  $users)

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

86 : void // Missing array type.
87 {
88 $this->users = $users;
89 }

References $users.

◆ start()

ilUserXMLWriter::start ( )

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

92 : bool
93 {
94 if (!is_array($this->users)) {
95 return false;
96 }
97
98 $this->__buildHeader();
99
100 foreach ($this->users as $user) {
101 $this->__handleUser($user);
102 }
103
104 $this->__buildFooter();
105
106 return true;
107 }

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

+ Here is the call graph for this function:

Field Documentation

◆ $attach_preferences

bool ilUserXMLWriter::$attach_preferences = false
private

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

◆ $attach_roles

bool ilUserXMLWriter::$attach_roles = false
private

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

◆ $db

readonly ilDBInterface ilUserXMLWriter::$db
private

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

◆ $fields_to_export

array ilUserXMLWriter::$fields_to_export = []
private

fields to be exported

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

◆ $ilias

readonly ILIAS ilUserXMLWriter::$ilias
private

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

◆ $lng

readonly Language ilUserXMLWriter::$lng
private

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

◆ $user_id

int ilUserXMLWriter::$user_id = 0
private

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

◆ $user_profile

readonly Profile ilUserXMLWriter::$user_profile
private

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

◆ $user_settings

readonly SettingsImplementation ilUserXMLWriter::$user_settings
private

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

◆ $user_settings_data_repo

readonly UserSettingsDataRepository ilUserXMLWriter::$user_settings_data_repo
private

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

◆ $users

array ilUserXMLWriter::$users
private

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

Referenced by setObjects().


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