ILIAS  release_8 Revision v8.23
ilObjectXMLWriter Class Reference

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

+ Inheritance diagram for ilObjectXMLWriter:
+ Collaboration diagram for ilObjectXMLWriter:

Public Member Functions

 __construct ()
 
 setMode (int $a_mode)
 
 getMode ()
 
 setHighlighter (ilLuceneHighlighterResultParser $a_highlighter)
 
 getHighlighter ()
 
 enablePermissionCheck (bool $a_status)
 
 isPermissionCheckEnabled ()
 
 setUserId (int $a_id)
 
 getUserId ()
 
 enableOperations (bool $a_status)
 
 enabledOperations ()
 
 enableReferences (bool $a_stat)
 
 enabledReferences ()
 
 setObjects (array $objects)
 
 getObjects ()
 
 start ()
 
 getXML ()
 
- 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 appendPathToObject (ilXmlWriter $writer, int $refid)
 

Data Fields

const MODE_SEARCH_RESULT = 1
 
const TIMING_DEACTIVATED = 0
 
const TIMING_TEMPORARILY_AVAILABLE = 1
 
const TIMING_PRESETTING = 2
 
const TIMING_VISIBILITY_OFF = 0
 
const TIMING_VISIBILITY_ON = 1
 

Protected Attributes

string $xml
 
bool $enable_operations = false
 
bool $enable_references = true
 
array $objects = array()
 
int $user_id = 0
 
bool $check_permission = false
 

Private Member Functions

 appendTimeTargets (int $a_ref_id)
 Append time target settings for items inside of courses. More...
 
 appendObjectProperties (ilObject $obj)
 
 appendOperations (int $a_ref_id, string $a_type)
 
 appendPath (int $refid)
 
 buildHeader ()
 
 buildFooter ()
 
 getAccessInfo (ilObject $object, int $ref_id)
 

Private Attributes

int $mode = 0
 
ilLuceneHighlighterResultParser $highlighter = null
 

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 16 of file class.ilObjectXMLWriter.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjectXMLWriter::__construct ( )

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

References $DIC, $ilUser, and ILIAS\GlobalScreen\Provider\__construct().

38  {
39  global $DIC;
40 
41  $ilUser = $DIC['ilUser'];
42 
44  $this->user_id = $ilUser->getId();
45  }
global $DIC
Definition: feed.php:28
__construct(Container $dic, ilPlugin $plugin)
$ilUser
Definition: imgupload.php:34
+ Here is the call graph for this function:

Member Function Documentation

◆ appendObjectProperties()

ilObjectXMLWriter::appendObjectProperties ( ilObject  $obj)
private

Definition at line 259 of file class.ilObjectXMLWriter.php.

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

Referenced by getXML().

259  : void
260  {
261  switch ($obj->getType()) {
262  case 'file':
263  if (!$obj instanceof ilObjFile) {
264  break;
265  }
266  $size = $obj->getFileSize();
267  $extension = $obj->getFileExtension();
268  $this->xmlStartTag('Properties');
269  $this->xmlElement("Property", array('name' => 'fileSize'), (string) $size);
270  $this->xmlElement("Property", array('name' => 'fileExtension'), (string) $extension);
271  $this->xmlElement(
272  'Property',
273  array('name' => 'fileVersion'),
274  (string) $obj->getVersion()
275  );
276  $this->xmlEndTag('Properties');
277  break;
278  }
279  }
xmlEndTag(string $tag)
Writes an endtag.
Class ilObjFile.
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:

◆ appendOperations()

ilObjectXMLWriter::appendOperations ( int  $a_ref_id,
string  $a_type 
)
private

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

References $DIC, $type, enabledOperations(), ilRbacReview\lookupCreateOperationIds(), and ilXmlWriter\xmlElement().

Referenced by getXML().

281  : void
282  {
283  global $DIC;
284 
285  $ilAccess = $DIC['ilAccess'];
286  $rbacreview = $DIC['rbacreview'];
287  $objDefinition = $DIC['objDefinition'];
288 
289  if ($this->enabledOperations()) {
290  $ops = $rbacreview->getOperationsOnTypeString($a_type);
291  if (is_array($ops)) {
292  foreach ($ops as $ops_id) {
293  $operation = $rbacreview->getOperation($ops_id);
294 
295  if (count($operation) && $ilAccess->checkAccessOfUser(
296  $this->getUserId(),
297  $operation['operation'],
298  'view',
299  $a_ref_id
300  )) {
301  $this->xmlElement('Operation', null, $operation['operation']);
302  }
303  }
304  }
305 
306  $objects = $objDefinition->getCreatableSubObjects($a_type);
307  $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
308  $creation_operations = array();
309  foreach ($objects as $type => $info) {
310  $ops_id = $ops_ids[$type];
311 
312  if (!$ops_id) {
313  continue;
314  }
315 
316  $operation = $rbacreview->getOperation($ops_id);
317 
318  if (count($operation) && $ilAccess->checkAccessOfUser(
319  $this->getUserId(),
320  $operation['operation'],
321  'view',
322  $a_ref_id
323  )) {
324  $this->xmlElement('Operation', null, $operation['operation']);
325  }
326  }
327  }
328  }
$type
global $DIC
Definition: feed.php:28
static lookupCreateOperationIds(array $a_type_arr)
Lookup operation ids.
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:

◆ appendPath()

ilObjectXMLWriter::appendPath ( int  $refid)
private

Definition at line 330 of file class.ilObjectXMLWriter.php.

Referenced by getXML().

330  : void
331  {
332  self::appendPathToObject($this, $refid);
333  }
+ Here is the caller graph for this function:

◆ appendPathToObject()

static ilObjectXMLWriter::appendPathToObject ( ilXmlWriter  $writer,
int  $refid 
)
static

Definition at line 365 of file class.ilObjectXMLWriter.php.

References $DIC, $lng, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by ilSoapRoleObjectXMLWriter\start().

365  : void
366  {
367  global $DIC;
368 
369  $tree = $DIC['tree'];
370  $lng = $DIC['lng'];
371  $items = $tree->getPathFull($refid);
372  $writer->xmlStartTag("Path");
373  foreach ($items as $item) {
374  if ((int) $item["ref_id"] === $refid) {
375  continue;
376  }
377  if ($item["type"] === "root") {
378  $item["title"] = $lng->txt("repository");
379  }
380  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
381  }
382  $writer->xmlEndTag("Path");
383  }
$lng
xmlEndTag(string $tag)
Writes an endtag.
global $DIC
Definition: feed.php:28
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:

◆ appendTimeTargets()

ilObjectXMLWriter::appendTimeTargets ( int  $a_ref_id)
private

Append time target settings for items inside of courses.

Parameters
int$ref_idReference id of object
Returns
void

Definition at line 212 of file class.ilObjectXMLWriter.php.

References $DIC, $type, ilObjectActivation\getItem(), ILIAS\Repository\int(), ilObjectActivation\TIMINGS_ACTIVATION, ilObjectActivation\TIMINGS_DEACTIVATED, ilObjectActivation\TIMINGS_PRESETTING, ilXmlWriter\xmlElement(), ilXmlWriter\xmlEndTag(), and ilXmlWriter\xmlStartTag().

Referenced by getXML().

212  : void
213  {
214  global $DIC;
215 
216  $tree = $DIC['tree'];
217 
218  if (!$tree->checkForParentType($a_ref_id, 'crs')) {
219  return;
220  }
221  include_once('./Services/Object/classes/class.ilObjectActivation.php');
222  $time_targets = ilObjectActivation::getItem($a_ref_id);
223 
224  switch ($time_targets['timing_type']) {
226  $type = self::TIMING_TEMPORARILY_AVAILABLE;
227  break;
229  $type = self::TIMING_PRESETTING;
230  break;
232  default:
233  $type = self::TIMING_DEACTIVATED;
234  break;
235  }
236 
237  $this->xmlStartTag('TimeTarget', array('type' => $type));
238 
239  $vis = (int) $time_targets['visible'] === 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
240  $this->xmlElement(
241  'Timing',
242  array('starting_time' => $time_targets['timing_start'],
243  'ending_time' => $time_targets['timing_end'],
244  'visibility' => $vis
245  )
246  );
247 
248  $this->xmlElement(
249  'Suggestion',
250  array(
251  'starting_time' => $time_targets['suggestion_start'],
252  'ending_time' => $time_targets['suggestion_end'],
253  'changeable' => $time_targets['changeable']
254  )
255  );
256  $this->xmlEndTag('TimeTarget');
257  }
$type
xmlEndTag(string $tag)
Writes an endtag.
global $DIC
Definition: feed.php:28
static getItem(int $ref_id)
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:

◆ buildFooter()

ilObjectXMLWriter::buildFooter ( )
private

Definition at line 343 of file class.ilObjectXMLWriter.php.

References ilXmlWriter\xmlEndTag().

Referenced by start().

343  : void
344  {
345  $this->xmlEndTag('Objects');
346  }
xmlEndTag(string $tag)
Writes an endtag.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ buildHeader()

ilObjectXMLWriter::buildHeader ( )
private

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

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

Referenced by start().

335  : void
336  {
337  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_object_4_0.dtd\">");
338  $this->xmlSetGenCmt("Export of ILIAS objects");
339  $this->xmlHeader();
340  $this->xmlStartTag("Objects");
341  }
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:

◆ enabledOperations()

ilObjectXMLWriter::enabledOperations ( )

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

References $enable_operations.

Referenced by appendOperations().

92  : bool
93  {
95  }
+ Here is the caller graph for this function:

◆ enabledReferences()

ilObjectXMLWriter::enabledReferences ( )

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

References $enable_references.

Referenced by getXML().

102  : bool
103  {
105  }
+ Here is the caller graph for this function:

◆ enableOperations()

ilObjectXMLWriter::enableOperations ( bool  $a_status)

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

87  : void
88  {
89  $this->enable_operations = $a_status;
90  }

◆ enablePermissionCheck()

ilObjectXMLWriter::enablePermissionCheck ( bool  $a_status)

Definition at line 67 of file class.ilObjectXMLWriter.php.

67  : void
68  {
69  $this->check_permission = $a_status;
70  }

◆ enableReferences()

ilObjectXMLWriter::enableReferences ( bool  $a_stat)

Definition at line 97 of file class.ilObjectXMLWriter.php.

97  : void
98  {
99  $this->enable_references = $a_stat;
100  }

◆ getAccessInfo()

ilObjectXMLWriter::getAccessInfo ( ilObject  $object,
int  $ref_id 
)
private

Definition at line 348 of file class.ilObjectXMLWriter.php.

References $DIC, ilObject\getId(), ilObject\getType(), and getUserId().

Referenced by getXML().

348  : string
349  {
350  global $DIC;
351 
352  $ilAccess = $DIC['ilAccess'];
353 
354  include_once 'Services/AccessControl/classes/class.ilAccess.php';
355 
356  $ilAccess->checkAccessOfUser($this->getUserId(), 'read', 'view', $ref_id, $object->getType(), $object->getId());
357 
358  if (!$info = $ilAccess->getInfo()) {
359  return 'granted';
360  }
361 
362  return $info[0]['type'];
363  }
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHighlighter()

ilObjectXMLWriter::getHighlighter ( )

Definition at line 62 of file class.ilObjectXMLWriter.php.

References $highlighter.

63  {
64  return $this->highlighter;
65  }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilLuceneHighlighterResultParser $highlighter

◆ getMode()

ilObjectXMLWriter::getMode ( )

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

References $mode.

52  : int
53  {
54  return $this->mode;
55  }

◆ getObjects()

ilObjectXMLWriter::getObjects ( )

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

References $objects.

Referenced by start().

112  : array
113  {
114  return $this->objects;
115  }
+ Here is the caller graph for this function:

◆ getUserId()

ilObjectXMLWriter::getUserId ( )

Definition at line 82 of file class.ilObjectXMLWriter.php.

References $user_id.

Referenced by getAccessInfo().

82  : int
83  {
84  return $this->user_id;
85  }
+ Here is the caller graph for this function:

◆ getXML()

◆ isPermissionCheckEnabled()

ilObjectXMLWriter::isPermissionCheckEnabled ( )

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

References $check_permission.

Referenced by start().

72  : bool
73  {
75  }
+ Here is the caller graph for this function:

◆ setHighlighter()

ilObjectXMLWriter::setHighlighter ( ilLuceneHighlighterResultParser  $a_highlighter)

Definition at line 57 of file class.ilObjectXMLWriter.php.

57  : void
58  {
59  $this->highlighter = $a_highlighter;
60  }

◆ setMode()

ilObjectXMLWriter::setMode ( int  $a_mode)

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

47  : void
48  {
49  $this->mode = $a_mode;
50  }

◆ setObjects()

ilObjectXMLWriter::setObjects ( array  $objects)

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

References $objects.

107  : void
108  {
109  $this->objects = $objects;
110  }

◆ setUserId()

ilObjectXMLWriter::setUserId ( int  $a_id)

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

77  : void
78  {
79  $this->user_id = $a_id;
80  }

◆ start()

ilObjectXMLWriter::start ( )

Definition at line 117 of file class.ilObjectXMLWriter.php.

References $DIC, buildFooter(), buildHeader(), getObjects(), and isPermissionCheckEnabled().

117  : bool
118  {
119  global $DIC;
120 
121  $ilAccess = $DIC['ilAccess'];
122  $objDefinition = $DIC['objDefinition'];
123 
124  $this->buildHeader();
125  foreach ($this->getObjects() as $object) {
126  if (method_exists($object, 'getType') &&
127  $this->isPermissionCheckEnabled() &&
128  $objDefinition->isRBACObject($object->getType()) &&
129  !$ilAccess->checkAccessOfUser(
130  $this->getUserId(),
131  'read',
132  '',
133  $object->getRefId()
134  )) {
135  continue;
136  }
137  $this->appendObject($object);
138  }
139  $this->buildFooter();
140  return true;
141  }
global $DIC
Definition: feed.php:28
+ Here is the call graph for this function:

Field Documentation

◆ $check_permission

bool ilObjectXMLWriter::$check_permission = false
protected

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

Referenced by isPermissionCheckEnabled().

◆ $enable_operations

bool ilObjectXMLWriter::$enable_operations = false
protected

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

Referenced by enabledOperations().

◆ $enable_references

bool ilObjectXMLWriter::$enable_references = true
protected

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

Referenced by enabledReferences().

◆ $highlighter

ilLuceneHighlighterResultParser ilObjectXMLWriter::$highlighter = null
private

Definition at line 28 of file class.ilObjectXMLWriter.php.

Referenced by getHighlighter().

◆ $mode

int ilObjectXMLWriter::$mode = 0
private

Definition at line 27 of file class.ilObjectXMLWriter.php.

Referenced by getMode().

◆ $objects

array ilObjectXMLWriter::$objects = array()
protected

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

Referenced by getObjects(), and setObjects().

◆ $user_id

int ilObjectXMLWriter::$user_id = 0
protected

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

Referenced by getUserId().

◆ $xml

string ilObjectXMLWriter::$xml
protected

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

◆ MODE_SEARCH_RESULT

const ilObjectXMLWriter::MODE_SEARCH_RESULT = 1

◆ TIMING_DEACTIVATED

const ilObjectXMLWriter::TIMING_DEACTIVATED = 0

◆ TIMING_PRESETTING

const ilObjectXMLWriter::TIMING_PRESETTING = 2

◆ TIMING_TEMPORARILY_AVAILABLE

const ilObjectXMLWriter::TIMING_TEMPORARILY_AVAILABLE = 1

◆ TIMING_VISIBILITY_OFF

const ilObjectXMLWriter::TIMING_VISIBILITY_OFF = 0

Definition at line 24 of file class.ilObjectXMLWriter.php.

◆ TIMING_VISIBILITY_ON

const ilObjectXMLWriter::TIMING_VISIBILITY_ON = 1

Definition at line 25 of file class.ilObjectXMLWriter.php.


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