ILIAS  trunk Revision v11.0_alpha-1846-g895b5f47236
All Data Structures Namespaces Files Functions Variables Enumerations Enumerator Modules Pages
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...
 

Private Attributes

ILIAS $ilias
 
ilDBInterface $db
 
Language $lng
 
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 30 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 290 of file class.ilUserXMLWriter.php.

References canExport(), null, and ilXmlWriter\xmlElement().

Referenced by __addElementMulti(), and __handleUser().

296  : void {
297  if ($this->canExport($tagname, $settingsname)
298  && ($value !== null
299  || $requiredTag
300  || is_array($attrs) && count($attrs) > 0)) {
301  $this->xmlElement($tagname, $attrs, (string) $value);
302  }
303  }
canExport(string $tagname, ?string $settingsname=null)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:
+ 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 278 of file class.ilUserXMLWriter.php.

References __addElement().

Referenced by __handleUser().

284  : void {
285  foreach ($value as $item) {
286  $this->__addElement($tagname, $item, $attrs, $settingsname, $requiredTag);
287  }
288  }
__addElement(string $tagname, ?string $value, ?array $attrs=null, ?string $settingsname=null, bool $requiredTag=false)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __buildFooter()

ilUserXMLWriter::__buildFooter ( )

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

References ilXmlWriter\xmlEndTag().

Referenced by start().

107  : void
108  {
109  $this->xmlEndTag('Users');
110  }
xmlEndTag(string $tag)
Writes an endtag.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __buildHeader()

ilUserXMLWriter::__buildHeader ( )

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

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

Referenced by start().

98  : void
99  {
100  $this->xmlSetDtdDef('<!DOCTYPE Users PUBLIC "-//ILIAS//DTD UserImport//EN" "' . ILIAS_HTTP_PATH . '/components/ILIAS/Export/xml/ilias_user_5_1.dtd">');
101  $this->xmlSetGenCmt('User of ilias system');
102  $this->xmlHeader();
103 
104  $this->xmlStartTag('Users');
105  }
xmlSetGenCmt(string $genCmt)
Sets generated comment.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
xmlHeader()
Writes xml header.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
+ 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 260 of file class.ilUserXMLWriter.php.

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

Referenced by __handleUser().

260  : void // Missing array type.
261  {
262  //todo nadia: test mail_address_option
263  $mailOptions = new ilMailOptions($row['usr_id']);
264  $prefs['mail_incoming_type'] = $mailOptions->getIncomingType();
265  $prefs['mail_address_option'] = $mailOptions->getEmailAddressMode();
266  $prefs['mail_signature'] = $mailOptions->getSignature();
267  if ($prefs !== []) {
268  $this->xmlStartTag('Prefs');
269  foreach ($prefs as $key => $value) {
270  if (self::isPrefExportable($key)) {
271  $this->xmlElement('Pref', ['key' => $key], $value);
272  }
273  }
274  $this->xmlEndTag('Prefs');
275  }
276  }
xmlEndTag(string $tag)
Writes an endtag.
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ __handleUser()

ilUserXMLWriter::__handleUser ( array  $row)

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

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

Referenced by start().

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

◆ canExport()

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

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

References ILIAS\Repository\settings().

Referenced by __addElement(), and __handleUser().

308  : bool {
309  return $this->settings === []
310  || in_array(strtolower($tagname), $this->settings) !== false
311  || in_array($settingsname, $this->settings) !== false;
312  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getExportablePreferences()

static ilUserXMLWriter::getExportablePreferences ( )
static

return exportable preference keys as found in db

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

356  : array // Missing array type.
357  {
358  return [
359  'public_city',
360  'public_country',
361  'public_department',
362  'public_email',
363  'public_second_email',
364  'public_fax',
365  'public_hobby',
366  'public_institution',
367  'public_matriculation',
368  'public_phone',
369  'public_phone_home',
370  'public_phone_mobile',
371  'public_phone_office',
372  'public_profile',
373  'public_street',
374  'public_upload',
375  'public_zip',
376  'send_info_mails',
377  /*'show_users_online',*/
378  'hide_own_online_status',
379  'bs_allow_to_contact_me',
380  'chat_osc_accept_msg',
381  'chat_broadcast_typing',
382  'user_tz',
383  'weekstart',
384  'mail_incoming_type',
385  'mail_signature',
386  'mail_linebreak',
387  'public_interests_general',
388  'public_interests_help_offered',
389  'public_interests_help_looking'
390  ];
391  }

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

References null.

Referenced by __handleUser().

323  : ?array
324  {
325  $avatar_resolver = new ilUserAvatarResolver($usr_id);
326  $avatar_resolver->setForcePicture(true);
327  if (!$avatar_resolver->hasProfilePicture()) {
328  return null;
329  }
330 
331  [$image_data, $image_type] = $avatar_resolver->getUserPictureForVCard();
332 
333  if ($image_data === null || $image_type === null) {
334  return null;
335  }
336 
337  return [
338  'value' => base64_encode($image_data),
339  'encoding' => 'Base64',
340  'imagetype' => $image_type
341  ];
342  }
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
Class ilUserAvatarResolver.
+ Here is the caller graph for this function:

◆ getXML()

ilUserXMLWriter::getXML ( )

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

References ilXmlWriter\xmlDumpMem().

92  : string
93  {
94  return $this->xmlDumpMem(false);
95  }
xmlDumpMem(bool $format=true)
Returns xml document from memory.
+ 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 396 of file class.ilUserXMLWriter.php.

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

396  : bool
397  {
398  return in_array($key, self::getExportablePreferences());
399  }
+ 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 348 of file class.ilUserXMLWriter.php.

References $attach_preferences.

348  : void
349  {
350  $this->attach_preferences = $attach_preferences;
351  }

◆ setAttachRoles()

ilUserXMLWriter::setAttachRoles ( bool  $value)

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

61  : void
62  {
63  $this->attach_roles = $value;
64  }

◆ setObjects()

ilUserXMLWriter::setObjects ( array  $users)

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

References $users.

66  : void // Missing array type.
67  {
68  $this->users = $users;
69  }

◆ setSettings()

ilUserXMLWriter::setSettings ( array  $settings)

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

References $settings, and ILIAS\Repository\settings().

Referenced by __handleUser().

314  : void // Missing array type.
315  {
316  $this->settings = $settings;
317  }
array $settings
fields to be exported
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ start()

ilUserXMLWriter::start ( )

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

References __buildFooter(), __buildHeader(), __handleUser(), and ilUserDefinedFields\_getInstance().

72  : bool
73  {
74  if (!is_array($this->users)) {
75  return false;
76  }
77 
78  $this->__buildHeader();
79 
81  $udf_data->addToXML($this);
82 
83  foreach ($this->users as $user) {
84  $this->__handleUser($user);
85  }
86 
87  $this->__buildFooter();
88 
89  return true;
90  }
+ Here is the call graph for this function:

Field Documentation

◆ $attach_preferences

bool ilUserXMLWriter::$attach_preferences = false
private

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

Referenced by setAttachPreferences().

◆ $attach_roles

bool ilUserXMLWriter::$attach_roles = false
private

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

◆ $db

ilDBInterface ilUserXMLWriter::$db
private

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

◆ $ilias

ILIAS ilUserXMLWriter::$ilias
private

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

◆ $lng

Language ilUserXMLWriter::$lng
private

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

◆ $settings

array ilUserXMLWriter::$settings = []
private

fields to be exported

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

Referenced by setSettings().

◆ $user_id

int ilUserXMLWriter::$user_id = 0
private

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

◆ $users

array ilUserXMLWriter::$users
private

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

Referenced by setObjects().


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