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