ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
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

 __construct ()
 
 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 $attachPrefs)
 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...
 

Data Fields

ILIAS $ilias
 
array $users
 
int $user_id = 0
 
bool $attachRoles = false
 
bool $attachPreferences = false
 

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

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.

Constructor & Destructor Documentation

◆ __construct()

ilUserXMLWriter::__construct ( )

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

References $DIC, $ilias, $ilUser, and ILIAS\GlobalScreen\Provider\__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  }
global $DIC
Definition: feed.php:28
header include for all ilias files.
__construct(Container $dic, ilPlugin $plugin)
$ilUser
Definition: imgupload.php:34
+ Here is the call graph for this function:

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(), and ilXmlWriter\xmlElement().

Referenced by __addElementMulti(), and __handleUser().

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  }
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  if (is_array($value) && count($value)) {
284  foreach ($value as $item) {
285  $this->__addElement($tagname, $item, $attrs, $settingsname, $requiredTag);
286  }
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 102 of file class.ilUserXMLWriter.php.

References ilXmlWriter\xmlEndTag().

Referenced by start().

102  : void
103  {
104  $this->xmlEndTag('Users');
105  }
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 93 of file class.ilUserXMLWriter.php.

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

Referenced by start().

93  : 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  }
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 257 of file class.ilUserXMLWriter.php.

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

Referenced by __handleUser().

257  : 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  }
Class ilMailOptions this class handles user mails.
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 107 of file class.ilUserXMLWriter.php.

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

Referenced by start().

107  : 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  }
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...
$type
$lng
__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.
global $DIC
Definition: feed.php:28
__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)
$query
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 304 of file class.ilUserXMLWriter.php.

References ILIAS\Repository\settings().

Referenced by __addElement(), and __handleUser().

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

372  : 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  }

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

References $DIC, $ilDB, ilDBConstants\FETCHMODE_ASSOC, and ilFileUtils\getWebspaceDir().

Referenced by __handleUser().

322  : ?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  }
static getWebspaceDir(string $mode="filesystem")
get webspace directory
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getXML()

ilUserXMLWriter::getXML ( )

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

References ilXmlWriter\xmlDumpMem().

87  : string
88  {
89  return $this->xmlDumpMem(false);
90  }
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 413 of file class.ilUserXMLWriter.php.

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

413  : bool
414  {
415  return in_array($key, self::getExportablePreferences());
416  }
string $key
Consumer key/client ID value.
Definition: System.php:193
+ Here is the caller graph for this function:

◆ setAttachPreferences()

ilUserXMLWriter::setAttachPreferences ( bool  $attachPrefs)

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

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

364  : void
365  {
366  $this->attachPreferences = $attachPrefs;
367  }

◆ setAttachRoles()

ilUserXMLWriter::setAttachRoles ( bool  $value)

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

56  : void
57  {
58  $this->attachRoles = $value;
59  }

◆ setObjects()

ilUserXMLWriter::setObjects ( array  $users)

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

References $users.

61  : void // Missing array type.
62  {
63  $this->users = $users;
64  }

◆ setSettings()

ilUserXMLWriter::setSettings ( array  $settings)

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

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

Referenced by __handleUser().

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

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

67  : 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  }
+ Here is the call graph for this function:

Field Documentation

◆ $attachPreferences

bool ilUserXMLWriter::$attachPreferences = false

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

◆ $attachRoles

bool ilUserXMLWriter::$attachRoles = false

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

◆ $ilias

ILIAS ilUserXMLWriter::$ilias

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

Referenced by __construct().

◆ $settings

array ilUserXMLWriter::$settings = []
private

fields to be exported

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

Referenced by setSettings().

◆ $user_id

int ilUserXMLWriter::$user_id = 0

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

◆ $users

array ilUserXMLWriter::$users

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

Referenced by setObjects().


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