ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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 14 of file class.ilObjectXMLWriter.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjectXMLWriter::__construct ( )

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

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

36  {
37  global $DIC;
38 
39  $ilUser = $DIC['ilUser'];
40 
42  $this->user_id = $ilUser->getId();
43  }
global $DIC
Definition: shib_login.php:25
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ appendObjectProperties()

ilObjectXMLWriter::appendObjectProperties ( ilObject  $obj)
private

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

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

Referenced by getXML().

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

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

Referenced by getXML().

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

Referenced by getXML().

327  : void
328  {
329  self::appendPathToObject($this, $refid);
330  }
+ Here is the caller graph for this function:

◆ appendPathToObject()

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

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

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

Referenced by ilSoapRoleObjectXMLWriter\start().

360  : void
361  {
362  global $DIC;
363 
364  $tree = $DIC['tree'];
365  $lng = $DIC['lng'];
366  $items = $tree->getPathFull($refid);
367  $writer->xmlStartTag("Path");
368  foreach ($items as $item) {
369  if ((int) $item["ref_id"] === $refid) {
370  continue;
371  }
372  if ($item["type"] === "root") {
373  $item["title"] = $lng->txt("repository");
374  }
375  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
376  }
377  $writer->xmlEndTag("Path");
378  }
xmlEndTag(string $tag)
Writes an endtag.
global $DIC
Definition: shib_login.php:25
global $lng
Definition: privfeed.php:32
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 210 of file class.ilObjectXMLWriter.php.

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

Referenced by getXML().

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

References ilXmlWriter\xmlEndTag().

Referenced by start().

340  : void
341  {
342  $this->xmlEndTag('Objects');
343  }
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 332 of file class.ilObjectXMLWriter.php.

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

Referenced by start().

332  : void
333  {
334  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"" . ILIAS_HTTP_PATH . "/components/ILIAS/Export/xml/ilias_object_4_0.dtd\">");
335  $this->xmlSetGenCmt("Export of ILIAS objects");
336  $this->xmlHeader();
337  $this->xmlStartTag("Objects");
338  }
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 90 of file class.ilObjectXMLWriter.php.

References $enable_operations.

Referenced by appendOperations().

90  : bool
91  {
93  }
+ Here is the caller graph for this function:

◆ enabledReferences()

ilObjectXMLWriter::enabledReferences ( )

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

References $enable_references.

Referenced by getXML().

100  : bool
101  {
103  }
+ Here is the caller graph for this function:

◆ enableOperations()

ilObjectXMLWriter::enableOperations ( bool  $a_status)

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

85  : void
86  {
87  $this->enable_operations = $a_status;
88  }

◆ enablePermissionCheck()

ilObjectXMLWriter::enablePermissionCheck ( bool  $a_status)

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

65  : void
66  {
67  $this->check_permission = $a_status;
68  }

◆ enableReferences()

ilObjectXMLWriter::enableReferences ( bool  $a_stat)

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

95  : void
96  {
97  $this->enable_references = $a_stat;
98  }

◆ getAccessInfo()

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

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

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

Referenced by getXML().

345  : string
346  {
347  global $DIC;
348 
349  $ilAccess = $DIC['ilAccess'];
350 
351  $ilAccess->checkAccessOfUser($this->getUserId(), 'read', 'view', $ref_id, $object->getType(), $object->getId());
352 
353  if (!$info = $ilAccess->getInfo()) {
354  return 'granted';
355  }
356 
357  return $info[0]['type'];
358  }
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getHighlighter()

ilObjectXMLWriter::getHighlighter ( )

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

References $highlighter.

61  {
62  return $this->highlighter;
63  }
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 50 of file class.ilObjectXMLWriter.php.

References $mode.

50  : int
51  {
52  return $this->mode;
53  }

◆ getObjects()

ilObjectXMLWriter::getObjects ( )

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

References $objects.

Referenced by start().

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

◆ getUserId()

ilObjectXMLWriter::getUserId ( )

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

References $user_id.

Referenced by getAccessInfo().

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

◆ getXML()

◆ isPermissionCheckEnabled()

ilObjectXMLWriter::isPermissionCheckEnabled ( )

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

References $check_permission.

Referenced by start().

70  : bool
71  {
73  }
+ Here is the caller graph for this function:

◆ setHighlighter()

ilObjectXMLWriter::setHighlighter ( ilLuceneHighlighterResultParser  $a_highlighter)

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

55  : void
56  {
57  $this->highlighter = $a_highlighter;
58  }

◆ setMode()

ilObjectXMLWriter::setMode ( int  $a_mode)

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

45  : void
46  {
47  $this->mode = $a_mode;
48  }

◆ setObjects()

ilObjectXMLWriter::setObjects ( array  $objects)

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

References $objects.

105  : void
106  {
107  $this->objects = $objects;
108  }

◆ setUserId()

ilObjectXMLWriter::setUserId ( int  $a_id)

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

75  : void
76  {
77  $this->user_id = $a_id;
78  }

◆ start()

ilObjectXMLWriter::start ( )

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

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

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

Field Documentation

◆ $check_permission

bool ilObjectXMLWriter::$check_permission = false
protected

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

Referenced by isPermissionCheckEnabled().

◆ $enable_operations

bool ilObjectXMLWriter::$enable_operations = false
protected

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

Referenced by enabledOperations().

◆ $enable_references

bool ilObjectXMLWriter::$enable_references = true
protected

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

Referenced by enabledReferences().

◆ $highlighter

ilLuceneHighlighterResultParser ilObjectXMLWriter::$highlighter = null
private

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

Referenced by getHighlighter().

◆ $mode

int ilObjectXMLWriter::$mode = 0
private

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

Referenced by getMode().

◆ $objects

array ilObjectXMLWriter::$objects = array()
protected

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

Referenced by getObjects(), and setObjects().

◆ $user_id

int ilObjectXMLWriter::$user_id = 0
protected

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

Referenced by getUserId().

◆ $xml

string ilObjectXMLWriter::$xml
protected

Definition at line 28 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 22 of file class.ilObjectXMLWriter.php.

◆ TIMING_VISIBILITY_ON

const ilObjectXMLWriter::TIMING_VISIBILITY_ON = 1

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


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