ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
ilUserXMLWriter Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. 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
 
ilLanguage $lng
 
array $users
 
int $user_id = 0
 
bool $attach_roles = false
 
bool $attach_preferences = false
 
array $settings = []
 fields to be exported More...
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning 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 28 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 288 of file class.ilUserXMLWriter.php.

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

Referenced by __addElementMulti(), and __handleUser().

294  : void {
295  if ($this->canExport($tagname, $settingsname)
296  && ($value !== null
297  || $requiredTag
298  || is_array($attrs) && count($attrs) > 0)) {
299  $this->xmlElement($tagname, $attrs, (string) $value);
300  }
301  }
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)
+ 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 276 of file class.ilUserXMLWriter.php.

References __addElement().

Referenced by __handleUser().

282  : void {
283  foreach ($value as $item) {
284  $this->__addElement($tagname, $item, $attrs, $settingsname, $requiredTag);
285  }
286  }
__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 105 of file class.ilUserXMLWriter.php.

References ilXmlWriter\xmlEndTag().

Referenced by start().

105  : void
106  {
107  $this->xmlEndTag('Users');
108  }
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 96 of file class.ilUserXMLWriter.php.

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

Referenced by start().

96  : void
97  {
98  $this->xmlSetDtdDef('<!DOCTYPE Users PUBLIC "-//ILIAS//DTD UserImport//EN" "' . ILIAS_HTTP_PATH . '/xml/ilias_user_5_1.dtd">');
99  $this->xmlSetGenCmt('User of ilias system');
100  $this->xmlHeader();
101 
102  $this->xmlStartTag('Users');
103  }
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 258 of file class.ilUserXMLWriter.php.

References ILIAS\LTI\ToolProvider\$key, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by __handleUser().

258  : void // Missing array type.
259  {
260  //todo nadia: test mail_address_option
261  $mailOptions = new ilMailOptions($row['usr_id']);
262  $prefs['mail_incoming_type'] = $mailOptions->getIncomingType();
263  $prefs['mail_address_option'] = $mailOptions->getEmailAddressMode();
264  $prefs['mail_signature'] = $mailOptions->getSignature();
265  if ($prefs !== []) {
266  $this->xmlStartTag('Prefs');
267  foreach ($prefs as $key => $value) {
268  if (self::isPrefExportable($key)) {
269  $this->xmlElement('Pref', ['key' => $key], $value);
270  }
271  }
272  $this->xmlEndTag('Prefs');
273  }
274  }
xmlEndTag(string $tag)
Writes an endtag.
string $key
Consumer key/client ID value.
Definition: System.php:193
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 110 of file class.ilUserXMLWriter.php.

References __addElement(), __addElementMulti(), __handlePreferences(), ilObjUser\_getPreferences(), 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().

110  : void // Missing array type.
111  {
112  if ($this->settings === []) {
114  }
115 
116  $prefs = ilObjUser::_getPreferences($row['usr_id']);
117 
118  if ($row['language'] === null
119  || $row['language'] === '') {
120  $row['language'] = $this->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->attach_roles == 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  $this->db->quote($row['usr_id'], 'integer')
139  );
140  $rbacresult = $this->db->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 ($type !== '') {
155  $this->xmlElement(
156  'Role',
157  ['Id' => 'il_' . IL_INST_ID . '_role_' . $rbacrow['rol_id'], 'Type' => $type],
158  $rbacrow['title']
159  );
160  }
161  }
162  }
163 
164  $this->__addElement('Firstname', $row['firstname']);
165  $this->__addElement('Lastname', $row['lastname']);
166  $this->__addElement('Title', $row['title']);
167 
168  if ($this->canExport('PersonalPicture', 'upload')) {
169  $imageData = $this->getPictureValue($row['usr_id']);
170  if ($imageData) {
171  $value = array_shift($imageData); //$imageData['value'];
172  $this->__addElement('PersonalPicture', $value, $imageData, 'upload');
173  }
174  }
175 
176 
177  $this->__addElement('Gender', $row['gender']);
178  $this->__addElement('Email', $row['email']);
179  $this->__addElement('SecondEmail', $row['second_email'], null, 'second_email');
180  $this->__addElement('Birthday', $row['birthday']);
181  $this->__addElement('Institution', $row['institution']);
182  $this->__addElement('Street', $row['street']);
183  $this->__addElement('City', $row['city']);
184  $this->__addElement('PostalCode', $row['zipcode'], null, 'zipcode');
185  $this->__addElement('Country', $row['country']);
186  $this->__addElement('SelCountry', $row['sel_country'], null, 'sel_country');
187  $this->__addElement('PhoneOffice', $row['phone_office'], null, 'phone_office');
188  $this->__addElement('PhoneHome', $row['phone_home'], null, 'phone_home');
189  $this->__addElement('PhoneMobile', $row['phone_mobile'], null, 'phone_mobile');
190  $this->__addElement('Fax', $row['fax']);
191  $this->__addElement('Hobby', $row['hobby']);
192 
193  $this->__addElementMulti('GeneralInterest', $row['interests_general'] ?? [], null, 'interests_general');
194  $this->__addElementMulti('OfferingHelp', $row['interests_help_offered'] ?? [], null, 'interests_help_offered');
195  $this->__addElementMulti('LookingForHelp', $row['interests_help_looking'] ?? [], null, 'interests_help_looking');
196 
197  $this->__addElement('Department', $row['department']);
198  $this->__addElement('Comment', $row['referral_comment'], null, 'referral_comment');
199  $this->__addElement('Matriculation', $row['matriculation']);
200  $this->__addElement('Active', $row['active'] ? 'true' : 'false');
201  $this->__addElement('ClientIP', $row['client_ip'], null, 'client_ip');
202  $this->__addElement('TimeLimitOwner', $row['time_limit_owner'], null, 'time_limit_owner');
203  $this->__addElement('TimeLimitUnlimited', $row['time_limit_unlimited'], null, 'time_limit_unlimited');
204  $this->__addElement('TimeLimitFrom', $row['time_limit_from'], null, 'time_limit_from');
205  $this->__addElement('TimeLimitUntil', $row['time_limit_until'], null, 'time_limit_until');
206  $this->__addElement('TimeLimitMessage', $row['time_limit_message'], null, 'time_limit_message');
207  $this->__addElement('ApproveDate', $row['approve_date'], null, 'approve_date');
208  $this->__addElement('AgreeDate', $row['agree_date'], null, 'agree_date');
209 
210  if ($row['auth_mode'] !== null
211  && $row['auth_mode'] !== '') {
212  $this->__addElement('AuthMode', null, ['type' => $row['auth_mode']], 'auth_mode', true);
213  }
214 
215  if ($row['ext_account'] !== null
216  && $row['ext_account'] !== '') {
217  $this->__addElement('ExternalAccount', $row['ext_account'], null, 'ext_account', true);
218  }
219 
220  if (isset($prefs['skin'])
221  && isset($prefs['style'])
222  && $this->canExport('Look', 'skin_style')) {
223  $this->__addElement(
224  'Look',
225  null,
226  [
227  'Skin' => $prefs['skin'], 'Style' => $prefs['style']
228  ],
229  'skin_style',
230  true
231  );
232  }
233 
234 
235  $this->__addElement('LastUpdate', $row['last_update'], null, 'last_update');
236  $this->__addElement('LastLogin', $row['last_login'], null, 'last_login');
237 
238  $udf_data = new ilUserDefinedData($row['usr_id']);
239  $udf_data->addToXML($this);
240 
241  $this->__addElement('AccountInfo', $row['ext_account'], ['Type' => 'external']);
242 
243  $this->__addElement('GMapsInfo', null, [
244  'longitude' => $row['longitude'],
245  'latitude' => $row['latitude'],
246  'zoom' => $row['loc_zoom']]);
247 
248  $this->__addElement('Feedhash', $row['feed_hash']);
249 
250  if ($this->attach_preferences || $this->canExport('prefs', 'preferences')) {
251  $this->__handlePreferences($prefs, $row);
252  }
253 
254  $this->xmlEndTag('User');
255  }
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.
__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)
const ROLE_FOLDER_ID
Definition: constants.php:34
setSettings(array $settings)
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 303 of file class.ilUserXMLWriter.php.

References ILIAS\Repository\settings().

Referenced by __addElement(), and __handleUser().

306  : bool {
307  return $this->settings === []
308  || in_array(strtolower($tagname), $this->settings) !== false
309  || in_array($settingsname, $this->settings) !== false;
310  }
+ 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 354 of file class.ilUserXMLWriter.php.

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

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

Referenced by __handleUser().

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

◆ getXML()

ilUserXMLWriter::getXML ( )

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

References ilXmlWriter\xmlDumpMem().

90  : string
91  {
92  return $this->xmlDumpMem(false);
93  }
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 395 of file class.ilUserXMLWriter.php.

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

395  : bool
396  {
397  return in_array($key, self::getExportablePreferences());
398  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ 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 346 of file class.ilUserXMLWriter.php.

References $attach_preferences.

346  : void
347  {
348  $this->attach_preferences = $attach_preferences;
349  }

◆ setAttachRoles()

ilUserXMLWriter::setAttachRoles ( bool  $value)

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

59  : void
60  {
61  $this->attach_roles = $value;
62  }

◆ setObjects()

ilUserXMLWriter::setObjects ( array  $users)

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

References $users.

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

◆ setSettings()

ilUserXMLWriter::setSettings ( array  $settings)

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

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

Referenced by __handleUser().

312  : void // Missing array type.
313  {
314  $this->settings = $settings;
315  }
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 70 of file class.ilUserXMLWriter.php.

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

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

Field Documentation

◆ $attach_preferences

bool ilUserXMLWriter::$attach_preferences = false
private

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

Referenced by setAttachPreferences().

◆ $attach_roles

bool ilUserXMLWriter::$attach_roles = false
private

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

◆ $db

ilDBInterface ilUserXMLWriter::$db
private

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

◆ $ilias

ILIAS ilUserXMLWriter::$ilias
private

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

◆ $lng

ilLanguage ilUserXMLWriter::$lng
private

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

◆ $settings

array ilUserXMLWriter::$settings = []
private

fields to be exported

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

Referenced by setSettings().

◆ $user_id

int ilUserXMLWriter::$user_id = 0
private

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

◆ $users

array ilUserXMLWriter::$users
private

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

Referenced by setObjects().


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