ILIAS  trunk Revision v11.0_alpha-2638-g80c1d007f79
class.ilObjectXMLWriter.php
Go to the documentation of this file.
1 <?php
2 
29 {
30  public const MODE_SEARCH_RESULT = 1;
31 
32  public const TIMING_DEACTIVATED = 0;
33  public const TIMING_TEMPORARILY_AVAILABLE = 1;
34  public const TIMING_PRESETTING = 2;
35 
36  public const TIMING_VISIBILITY_OFF = 0;
37  public const TIMING_VISIBILITY_ON = 1;
38 
39  private int $mode = 0;
41 
42  protected string $xml;
43  protected bool $enable_operations = false;
44  protected bool $enable_references = true;
45  protected array $objects = array();
46  protected int $user_id = 0;
47  protected bool $check_permission = false;
48 
49  public function __construct()
50  {
51  global $DIC;
52 
53  $ilUser = $DIC['ilUser'];
54 
56  $this->user_id = $ilUser->getId();
57  }
58 
59  public function setMode(int $a_mode): void
60  {
61  $this->mode = $a_mode;
62  }
63 
64  public function getMode(): int
65  {
66  return $this->mode;
67  }
68 
69  public function setHighlighter(ilLuceneHighlighterResultParser $a_highlighter): void
70  {
71  $this->highlighter = $a_highlighter;
72  }
73 
75  {
76  return $this->highlighter;
77  }
78 
79  public function enablePermissionCheck(bool $a_status): void
80  {
81  $this->check_permission = $a_status;
82  }
83 
84  public function isPermissionCheckEnabled(): bool
85  {
87  }
88 
89  public function setUserId(int $a_id): void
90  {
91  $this->user_id = $a_id;
92  }
93 
94  public function getUserId(): int
95  {
96  return $this->user_id;
97  }
98 
99  public function enableOperations(bool $a_status): void
100  {
101  $this->enable_operations = $a_status;
102  }
103 
104  public function enabledOperations(): bool
105  {
107  }
108 
109  public function enableReferences(bool $a_stat): void
110  {
111  $this->enable_references = $a_stat;
112  }
113 
114  public function enabledReferences(): bool
115  {
117  }
118 
119  public function setObjects(array $objects): void
120  {
121  $this->objects = $objects;
122  }
123 
124  public function getObjects(): array
125  {
126  return $this->objects;
127  }
128 
129  public function start(): bool
130  {
131  global $DIC;
132 
133  $ilAccess = $DIC['ilAccess'];
134  $objDefinition = $DIC['objDefinition'];
135 
136  $this->buildHeader();
137  foreach ($this->getObjects() as $object) {
138  if (method_exists($object, 'getType') &&
139  $this->isPermissionCheckEnabled() &&
140  $objDefinition->isRBACObject($object->getType()) &&
141  !$ilAccess->checkAccessOfUser(
142  $this->getUserId(),
143  'read',
144  '',
145  $object->getRefId()
146  )) {
147  continue;
148  }
149  $this->appendObject($object);
150  }
151  $this->buildFooter();
152  return true;
153  }
154 
155  public function getXML(): string
156  {
157  return $this->xmlDumpMem(false);
158  }
159 
160  private function appendObject(ilObject $object): void
161  {
162  global $DIC;
163 
164  $tree = $DIC['tree'];
165  $rbacreview = $DIC['rbacreview'];
166 
168  $objectDefinition = $DIC['objDefinition'];
169 
170  $id = $object->getId();
171  if ($object->getType() === "role" && $rbacreview->isRoleDeleted($id)) {
172  return;
173  }
174 
175  $attrs = [
176  'type' => $object->getType(),
177  'obj_id' => $id
178  ];
179 
180  if ($objectDefinition->supportsOfflineHandling($object->getType())) {
181  $attrs['offline'] = (int) $object->getOfflineStatus();
182  }
183 
184  $this->xmlStartTag('Object', $attrs);
185  $this->xmlElement('Title', null, $object->getTitle());
186  $this->xmlElement('Description', null, $object->getDescription());
187  $this->xmlElement('Owner', null, $object->getOwner());
188  $this->xmlElement('CreateDate', null, $object->getCreateDate());
189  $this->xmlElement('LastUpdate', null, $object->getLastUpdateDate());
190  $this->xmlElement('ImportId', null, $object->getImportId());
191 
192  $this->appendObjectProperties($object);
193 
194  if ($this->enabledReferences()) {
195  $refs = ilObject::_getAllReferences($object->getId());
196  } else {
197  $refs = [$object->getRefId()];
198  }
199 
200  foreach ($refs as $ref_id) {
201  if (!$tree->isInTree($ref_id)) {
202  continue;
203  }
204 
205  $attr = array(
206  'ref_id' => $ref_id,
207  'parent_id' => $tree->getParentId($ref_id)
208  );
209  $attr['accessInfo'] = $this->getAccessInfo($object, $ref_id);
210  $this->xmlStartTag('References', $attr);
211  $this->appendTimeTargets($ref_id);
212  $this->appendOperations($ref_id, $object->getType());
213  $this->appendPath($ref_id);
214  $this->xmlEndTag('References');
215  }
216  $this->xmlEndTag('Object');
217  }
218 
224  private function appendTimeTargets(int $a_ref_id): void
225  {
226  global $DIC;
227 
228  $tree = $DIC['tree'];
229 
230  if (!$tree->checkForParentType($a_ref_id, 'crs')) {
231  return;
232  }
233  $time_targets = ilObjectActivation::getItem($a_ref_id);
234 
235  switch ($time_targets['timing_type']) {
237  $type = self::TIMING_TEMPORARILY_AVAILABLE;
238  break;
240  $type = self::TIMING_PRESETTING;
241  break;
243  default:
244  $type = self::TIMING_DEACTIVATED;
245  break;
246  }
247 
248  $this->xmlStartTag('TimeTarget', array('type' => $type));
249 
250  $vis = (int) $time_targets['visible'] === 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
251  $this->xmlElement(
252  'Timing',
253  array('starting_time' => $time_targets['timing_start'],
254  'ending_time' => $time_targets['timing_end'],
255  'visibility' => $vis
256  )
257  );
258 
259  $this->xmlElement(
260  'Suggestion',
261  array(
262  'starting_time' => $time_targets['suggestion_start'],
263  'ending_time' => $time_targets['suggestion_end'],
264  'changeable' => $time_targets['changeable']
265  )
266  );
267  $this->xmlEndTag('TimeTarget');
268  }
269 
270  private function appendObjectProperties(ilObject $obj): void
271  {
272  switch ($obj->getType()) {
273  case 'file':
274  if (!$obj instanceof ilObjFile) {
275  break;
276  }
277  $size = $obj->getFileSize();
278  $extension = $obj->getFileExtension();
279  $this->xmlStartTag('Properties');
280  $this->xmlElement("Property", array('name' => 'fileSize'), (string) $size);
281  $this->xmlElement("Property", array('name' => 'fileExtension'), (string) $extension);
282  $this->xmlElement(
283  'Property',
284  array('name' => 'fileVersion'),
285  (string) $obj->getVersion()
286  );
287  $this->xmlEndTag('Properties');
288  break;
289  }
290  }
291 
292  private function appendOperations(int $a_ref_id, string $a_type): void
293  {
294  global $DIC;
295 
296  $ilAccess = $DIC['ilAccess'];
297  $rbacreview = $DIC['rbacreview'];
298  $objDefinition = $DIC['objDefinition'];
299 
300  if ($this->enabledOperations()) {
301  $ops = $rbacreview->getOperationsOnTypeString($a_type);
302  if (is_array($ops)) {
303  foreach ($ops as $ops_id) {
304  $operation = $rbacreview->getOperation($ops_id);
305 
306  if (count($operation) && $ilAccess->checkAccessOfUser(
307  $this->getUserId(),
308  $operation['operation'],
309  'view',
310  $a_ref_id
311  )) {
312  $this->xmlElement('Operation', null, $operation['operation']);
313  }
314  }
315  }
316 
317  $objects = $objDefinition->getCreatableSubObjects($a_type);
318  $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
319  $creation_operations = array();
320  foreach ($objects as $type => $info) {
321  $ops_id = $ops_ids[$type] ?? null;
322 
323  if (!$ops_id) {
324  continue;
325  }
326 
327  $operation = $rbacreview->getOperation($ops_id);
328 
329  if (count($operation) && $ilAccess->checkAccessOfUser(
330  $this->getUserId(),
331  $operation['operation'],
332  'view',
333  $a_ref_id
334  )) {
335  $this->xmlElement('Operation', null, $operation['operation']);
336  }
337  }
338  }
339  }
340 
341  private function appendPath(int $refid): void
342  {
343  self::appendPathToObject($this, $refid);
344  }
345 
346  private function buildHeader(): void
347  {
348  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"" . ILIAS_HTTP_PATH . "/components/ILIAS/Export/xml/ilias_object_4_0.dtd\">");
349  $this->xmlSetGenCmt("Export of ILIAS objects");
350  $this->xmlHeader();
351  $this->xmlStartTag("Objects");
352  }
353 
354  private function buildFooter(): void
355  {
356  $this->xmlEndTag('Objects');
357  }
358 
359  private function getAccessInfo(ilObject $object, int $ref_id): string
360  {
361  global $DIC;
362 
363  $ilAccess = $DIC['ilAccess'];
364 
365  $ilAccess->checkAccessOfUser($this->getUserId(), 'read', 'view', $ref_id, $object->getType(), $object->getId());
366 
367  if (!$info = $ilAccess->getInfo()) {
368  return 'granted';
369  }
370 
371  return $info[0]['type'];
372  }
373 
374  public static function appendPathToObject(ilXmlWriter $writer, int $refid): void
375  {
376  global $DIC;
377 
378  $tree = $DIC['tree'];
379  $lng = $DIC['lng'];
380  $items = $tree->getPathFull($refid);
381  $writer->xmlStartTag("Path");
382  foreach ($items as $item) {
383  if ((int) $item["ref_id"] === $refid) {
384  continue;
385  }
386  if ($item["type"] === "root") {
387  $item["title"] = $lng->txt("repository");
388  }
389  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
390  }
391  $writer->xmlEndTag("Path");
392  }
393 }
enableOperations(bool $a_status)
Parses result XML from lucene search highlight.
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.
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
static lookupCreateOperationIds(array $a_type_arr)
Lookup operation ids.
xmlSetDtdDef(string $dtdDef)
Sets dtd definition.
$ref_id
Definition: ltiauth.php:65
Class ilObjFile.
global $DIC
Definition: shib_login.php:26
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:23
__construct(Container $dic, ilPlugin $plugin)
global $lng
Definition: privfeed.php:31
xmlStartTag(string $tag, ?array $attrs=null, bool $empty=false, bool $encode=true, bool $escape=true)
Writes a starttag.
appendObjectProperties(ilObject $obj)
$info
Definition: entry_point.php:21
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)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...