ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
class.ilObjectXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
3 /* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4 
15 {
16  public const MODE_SEARCH_RESULT = 1;
17 
18  public const TIMING_DEACTIVATED = 0;
19  public const TIMING_TEMPORARILY_AVAILABLE = 1;
20  public const TIMING_PRESETTING = 2;
21 
22  public const TIMING_VISIBILITY_OFF = 0;
23  public const TIMING_VISIBILITY_ON = 1;
24 
25  private int $mode = 0;
27 
28  protected string $xml;
29  protected bool $enable_operations = false;
30  protected bool $enable_references = true;
31  protected array $objects = array();
32  protected int $user_id = 0;
33  protected bool $check_permission = false;
34 
35  public function __construct()
36  {
37  global $DIC;
38 
39  $ilUser = $DIC['ilUser'];
40 
42  $this->user_id = $ilUser->getId();
43  }
44 
45  public function setMode(int $a_mode): void
46  {
47  $this->mode = $a_mode;
48  }
49 
50  public function getMode(): int
51  {
52  return $this->mode;
53  }
54 
55  public function setHighlighter(ilLuceneHighlighterResultParser $a_highlighter): void
56  {
57  $this->highlighter = $a_highlighter;
58  }
59 
61  {
62  return $this->highlighter;
63  }
64 
65  public function enablePermissionCheck(bool $a_status): void
66  {
67  $this->check_permission = $a_status;
68  }
69 
70  public function isPermissionCheckEnabled(): bool
71  {
73  }
74 
75  public function setUserId(int $a_id): void
76  {
77  $this->user_id = $a_id;
78  }
79 
80  public function getUserId(): int
81  {
82  return $this->user_id;
83  }
84 
85  public function enableOperations(bool $a_status): void
86  {
87  $this->enable_operations = $a_status;
88  }
89 
90  public function enabledOperations(): bool
91  {
93  }
94 
95  public function enableReferences(bool $a_stat): void
96  {
97  $this->enable_references = $a_stat;
98  }
99 
100  public function enabledReferences(): bool
101  {
103  }
104 
105  public function setObjects(array $objects): void
106  {
107  $this->objects = $objects;
108  }
109 
110  public function getObjects(): array
111  {
112  return $this->objects;
113  }
114 
115  public function start(): 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  }
140 
141  public function getXML(): string
142  {
143  return $this->xmlDumpMem(false);
144  }
145 
146  private function appendObject(ilObject $object): void
147  {
148  global $DIC;
149 
150  $tree = $DIC['tree'];
151  $rbacreview = $DIC['rbacreview'];
152 
154  $objectDefinition = $DIC['objDefinition'];
155 
156  $id = $object->getId();
157  if ($object->getType() === "role" && $rbacreview->isRoleDeleted($id)) {
158  return;
159  }
160 
161  $attrs = [
162  'type' => $object->getType(),
163  'obj_id' => $id
164  ];
165 
166  if ($objectDefinition->supportsOfflineHandling($object->getType())) {
167  $attrs['offline'] = (int) $object->getOfflineStatus();
168  }
169 
170  $this->xmlStartTag('Object', $attrs);
171  $this->xmlElement('Title', null, $object->getTitle());
172  $this->xmlElement('Description', null, $object->getDescription());
173  $this->xmlElement('Owner', null, $object->getOwner());
174  $this->xmlElement('CreateDate', null, $object->getCreateDate());
175  $this->xmlElement('LastUpdate', null, $object->getLastUpdateDate());
176  $this->xmlElement('ImportId', null, $object->getImportId());
177 
178  $this->appendObjectProperties($object);
179 
180  if ($this->enabledReferences()) {
181  $refs = ilObject::_getAllReferences($object->getId());
182  } else {
183  $refs = [$object->getRefId()];
184  }
185 
186  foreach ($refs as $ref_id) {
187  if (!$tree->isInTree($ref_id)) {
188  continue;
189  }
190 
191  $attr = array(
192  'ref_id' => $ref_id,
193  'parent_id' => $tree->getParentId($ref_id)
194  );
195  $attr['accessInfo'] = $this->getAccessInfo($object, $ref_id);
196  $this->xmlStartTag('References', $attr);
197  $this->appendTimeTargets($ref_id);
198  $this->appendOperations($ref_id, $object->getType());
199  $this->appendPath($ref_id);
200  $this->xmlEndTag('References');
201  }
202  $this->xmlEndTag('Object');
203  }
204 
210  private function appendTimeTargets(int $a_ref_id): 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  }
255 
256  private function appendObjectProperties(ilObject $obj): 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  }
277 
278  private function appendOperations(int $a_ref_id, string $a_type): 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  }
326 
327  private function appendPath(int $refid): void
328  {
329  self::appendPathToObject($this, $refid);
330  }
331 
332  private function buildHeader(): 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  }
339 
340  private function buildFooter(): void
341  {
342  $this->xmlEndTag('Objects');
343  }
344 
345  private function getAccessInfo(ilObject $object, int $ref_id): 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  }
359 
360  public static function appendPathToObject(ilXmlWriter $writer, int $refid): 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  }
379 }
enableOperations(bool $a_status)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setHighlighter(ilLuceneHighlighterResultParser $a_highlighter)
static _getAllReferences(int $id)
get all reference ids for object ID
xmlSetGenCmt(string $genCmt)
Sets generated comment.
getCreateDate()
Get create date in YYYY-MM-DD HH-MM-SS format.
getAccessInfo(ilObject $object, int $ref_id)
xmlEndTag(string $tag)
Writes an endtag.
static lookupCreateOperationIds(array $a_type_arr)
Lookup operation ids.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
$ref_id
Definition: ltiauth.php:66
Class ilObjFile.
global $DIC
Definition: shib_login.php:25
ilLuceneHighlighterResultParser $highlighter
appendOperations(int $a_ref_id, string $a_type)
xmlHeader()
Writes xml header.
static getItem(int $ref_id)
enablePermissionCheck(bool $a_status)
appendTimeTargets(int $a_ref_id)
Append time target settings for items inside of courses.
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:24
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:32
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
appendObjectProperties(ilObject $obj)
xmlElement(string $tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
getLastUpdateDate()
Get last update date in YYYY-MM-DD HH-MM-SS format.
xmlDumpMem(bool $format=true)
Returns xml document from memory.
static appendPathToObject(ilXmlWriter $writer, int $refid)
XML writer class Class to simplify manual writing of xml documents.