ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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 
5 include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6 
20 {
21  // begin-patch fm
22  const MODE_SEARCH_RESULT = 1;
23 
24  private $mode = 0;
25  private $highlighter = null;
26  // end-patch fm
27 
28 
29  const TIMING_DEACTIVATED = 0;
31  const TIMING_PRESETTING = 2;
32 
35 
36 
37  public $ilias;
38 
39  public $xml;
40  public $enable_operations = false;
41  // begin-patch filemanager
42  private $enable_references = true;
43  // end-patch filemanager
44  public $objects = array();
45  public $user_id = 0;
46 
47  protected $check_permission = false;
48 
56  public function __construct()
57  {
58  global $DIC;
59 
60  $ilias = $DIC['ilias'];
61  $ilUser = $DIC['ilUser'];
62 
63  parent::__construct();
64 
65  $this->ilias =&$ilias;
66  $this->user_id = $ilUser->getId();
67  }
68 
69  // begin-patch fm
70  public function setMode($a_mode)
71  {
72  $this->mode = $a_mode;
73  }
74 
75  public function setHighlighter($a_highlighter)
76  {
77  $this->highlighter = $a_highlighter;
78  }
79  // end-patch fm
80 
81 
82  public function enablePermissionCheck($a_status)
83  {
84  $this->check_permission = $a_status;
85  }
86 
87  public function isPermissionCheckEnabled()
88  {
90  }
91 
92  public function setUserId($a_id)
93  {
94  $this->user_id = $a_id;
95  }
96  public function getUserId()
97  {
98  return $this->user_id;
99  }
100 
101  public function enableOperations($a_status)
102  {
103  $this->enable_operations = $a_status;
104 
105  return true;
106  }
107 
108  public function enabledOperations()
109  {
111  }
112 
113  // begin-patch filemanager
114  public function enableReferences($a_stat)
115  {
116  $this->enable_references = $a_stat;
117  }
118 
119  public function enabledReferences()
120  {
122  }
123  // end-patch filemanager
124 
125 
126  public function setObjects($objects)
127  {
128  $this->objects = $objects;
129  }
130 
131  public function __getObjects()
132  {
133  return $this->objects ? $this->objects : array();
134  }
135 
136  public function start()
137  {
138  global $DIC;
139 
140  $ilAccess = $DIC['ilAccess'];
141  $objDefinition = $DIC['objDefinition'];
142 
143  $this->__buildHeader();
144 
145  foreach ($this->__getObjects() as $object) {
146  if (method_exists($object, 'getType') and $objDefinition->isRBACObject($object->getType())) {
147  if ($this->isPermissionCheckEnabled() and !$ilAccess->checkAccessOfUser($this->getUserId(), 'read', '', $object->getRefId())) {
148  continue;
149  }
150  }
151  $this->__appendObject($object);
152  }
153  $this->__buildFooter();
154 
155  return true;
156  }
157 
158  public function getXML()
159  {
160  return $this->xmlDumpMem(false);
161  }
162 
163 
164  // PRIVATE
165  public function __appendObject(ilObject $object)
166  {
167  global $DIC;
168 
169  $tree = $DIC['tree'];
170  $rbacreview = $DIC['rbacreview'];
171 
175  $objectDefinition = $DIC['objDefinition'];
176 
177  $id = $object->getId();
178  if ($object->getType() == "role" && $rbacreview->isRoleDeleted($id)) {
179  return;
180  }
181 
182  $attrs = array(
183  'type' => $object->getType(),
184  'obj_id' => $id
185  );
186 
187  if ($objectDefinition->supportsOfflineHandling($object->getType())) {
188  $attrs['offline'] = (int) $object->getOfflineStatus();
189  }
190 
191  $this->xmlStartTag('Object', $attrs);
192  //$this->xmlElement('Title',null,$object->getTitle());
193  //$this->xmlElement('Description',null,$object->getDescription());
194 
195  // begin-patch fm
196  if ($this->mode == self::MODE_SEARCH_RESULT) {
197  $title = $object->getTitle();
198  if ($this->highlighter->getTitle($object->getId(), 0)) {
199  $title = $this->highlighter->getTitle($object->getId(), 0);
200  }
201  $description = $object->getDescription();
202  if ($this->highlighter->getDescription($object->getId(), 0)) {
203  $description = $this->highlighter->getDescription($object->getId(), 0);
204  }
205 
206  // Currently disabled
207  #$this->xmlElement('Title', null, $title);
208  #$this->xmlElement('Description',null,$description);
209  #$this->xmlElement('SearchResultContent', null, $this->highlighter->getContent($object->getId(),0));
210 
211  $this->xmlElement('Title', null, $object->getTitle());
212  $this->xmlElement('Description', null, $object->getDescription());
213  } else {
214  $this->xmlElement('Title', null, $object->getTitle());
215  $this->xmlElement('Description', null, $object->getDescription());
216  }
217  // end-patch fm
218 
219  $this->xmlElement('Owner', null, $object->getOwner());
220  $this->xmlElement('CreateDate', null, $object->getCreateDate());
221  $this->xmlElement('LastUpdate', null, $object->getLastUpdateDate());
222  $this->xmlElement('ImportId', null, $object->getImportId());
223 
224  $this->__appendObjectProperties($object);
225 
226  // begin-patch filemanager
227  if ($this->enabledReferences()) {
228  $refs = ilObject::_getAllReferences($object->getId());
229  } else {
230  $refs = array($object->getRefId());
231  }
232 
233  foreach ($refs as $ref_id) {
234  // end-patch filemanager
235  if (!$tree->isInTree($ref_id)) {
236  continue;
237  }
238 
239  $attr = array(
240  'ref_id' => $ref_id,
241  'parent_id'=> $tree->getParentId(intval($ref_id))
242  );
243  $attr['accessInfo'] = $this->__getAccessInfo($object, $ref_id);
244  $this->xmlStartTag('References', $attr);
245  $this->__appendTimeTargets($ref_id);
246  $this->__appendOperations($ref_id, $object->getType());
247  $this->__appendPath($ref_id);
248  $this->xmlEndTag('References');
249  }
250  $this->xmlEndTag('Object');
251  }
252 
258  public function __appendTimeTargets($a_ref_id)
259  {
260  global $DIC;
261 
262  $tree = $DIC['tree'];
263 
264  if (!$tree->checkForParentType($a_ref_id, 'crs')) {
265  return;
266  }
267  include_once('./Services/Object/classes/class.ilObjectActivation.php');
268  $time_targets = ilObjectActivation::getItem($a_ref_id);
269 
270  switch ($time_targets['timing_type']) {
272  $type = self::TIMING_DEACTIVATED;
273  break;
275  $type = self::TIMING_TEMPORARILY_AVAILABLE;
276  break;
278  $type = self::TIMING_PRESETTING;
279  break;
280  default:
281  $type = self::TIMING_DEACTIVATED;
282  break;
283  }
284 
285  $this->xmlStartTag('TimeTarget', array('type' => $type));
286 
287  # if($type == self::TIMING_TEMPORARILY_AVAILABLE)
288  {
289  $vis = $time_targets['visible'] == 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
290  $this->xmlElement(
291  'Timing',
292  array('starting_time' => $time_targets['timing_start'],
293  'ending_time' => $time_targets['timing_end'],
294  'visibility' => $vis)
295  );
296 
297  }
298  # if($type == self::TIMING_PRESETTING)
299  {
300  $this->xmlElement(
301  'Suggestion',
302  array(
303  'starting_time' => $time_targets['suggestion_start'],
304  'ending_time' => $time_targets['suggestion_end'],
305  'changeable' => $time_targets['changeable'])
306  );
307  }
308  $this->xmlEndTag('TimeTarget');
309  return;
310  }
311 
312 
317  public function __appendObjectProperties(ilObject $obj)
318  {
319  switch ($obj->getType()) {
320 
321  case 'file':
322  include_once './Modules/File/classes/class.ilObjFileAccess.php';
324  $extension = ilObjFileAccess::_lookupSuffix($obj->getId());
325  $this->xmlStartTag('Properties');
326  $this->xmlElement("Property", array('name' => 'fileSize'), (int) $size);
327  $this->xmlElement("Property", array('name' => 'fileExtension'), (string) $extension);
328  // begin-patch fm
329  $this->xmlElement('Property', array('name' => 'fileVersion'), (string) ilObjFileAccess::_lookupVersion($obj->getId()));
330  // end-patch fm
331  $this->xmlEndTag('Properties');
332  break;
333  }
334  }
335 
336 
337  public function __appendOperations($a_ref_id, $a_type)
338  {
339  global $DIC;
340 
341  $ilAccess = $DIC['ilAccess'];
342  $rbacreview = $DIC['rbacreview'];
343  $objDefinition = $DIC['objDefinition'];
344 
345  if ($this->enabledOperations()) {
346  $ops = $rbacreview->getOperationsOnTypeString($a_type);
347  if (is_array($ops)) {
348  foreach ($ops as $ops_id) {
349  $operation = $rbacreview->getOperation($ops_id);
350 
351  if (count($operation) && $ilAccess->checkAccessOfUser($this->getUserId(), $operation['operation'], 'view', $a_ref_id)) {
352  $this->xmlElement('Operation', null, $operation['operation']);
353  }
354  }
355  }
356 
357  // Create operations
358  // Get creatable objects
359  $objects = $objDefinition->getCreatableSubObjects($a_type);
360  $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
361  $creation_operations = array();
362  foreach ($objects as $type => $info) {
363  $ops_id = $ops_ids[$type];
364 
365  if (!$ops_id) {
366  continue;
367  }
368 
369  $operation = $rbacreview->getOperation($ops_id);
370 
371  if (count($operation) && $ilAccess->checkAccessOfUser($this->getUserId(), $operation['operation'], 'view', $a_ref_id)) {
372  $this->xmlElement('Operation', null, $operation['operation']);
373  }
374  }
375  }
376  return true;
377  }
378 
379 
380  public function __appendPath($refid)
381  {
383  }
384 
385  public function __buildHeader()
386  {
387  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_object_4_0.dtd\">");
388  $this->xmlSetGenCmt("Export of ILIAS objects");
389  $this->xmlHeader();
390  $this->xmlStartTag("Objects");
391  return true;
392  }
393 
394  public function __buildFooter()
395  {
396  $this->xmlEndTag('Objects');
397  }
398 
399  public function __getAccessInfo(&$object, $ref_id)
400  {
401  global $DIC;
402 
403  $ilAccess = $DIC['ilAccess'];
404 
405  include_once 'Services/AccessControl/classes/class.ilAccess.php';
406 
407  $ilAccess->checkAccessOfUser($this->getUserId(), 'read', 'view', $ref_id, $object->getType(), $object->getId());
408 
409  if (!$info = $ilAccess->getInfo()) {
410  return 'granted';
411  } else {
412  return $info[0]['type'];
413  }
414  }
415 
416 
417  public static function appendPathToObject($writer, $refid)
418  {
419  global $DIC;
420 
421  $tree = $DIC['tree'];
422  $lng = $DIC['lng'];
423  $items = $tree->getPathFull($refid);
424  $writer->xmlStartTag("Path");
425  foreach ($items as $item) {
426  if ($item["ref_id"] == $refid) {
427  continue;
428  }
429  if ($item["type"] == "root") {
430  $item["title"] = $lng->txt("repository");
431  }
432  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
433  }
434  $writer->xmlEndTag("Path");
435  }
436 }
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
$size
Definition: RandomTest.php:84
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
$type
global $DIC
Definition: saml.php:7
__appendTimeTargets($a_ref_id)
Append time target settings for items inside of courses.
xmlDumpMem($format=true)
Returns xml document from memory.
static getItem($a_ref_id)
Get item data.
getOfflineStatus()
Get offline status.
if(!array_key_exists('StateId', $_REQUEST)) $id
XML writer class.
getCreateDate()
get create date public
getOwner()
get object owner
static _getAllReferences($a_id)
get all reference ids of object
xmlEndTag($tag)
Writes an endtag.
static lookupCreateOperationIds($a_type_arr)
Lookup operation ids.
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes. ...
$a_type
Definition: workflow.php:92
getId()
get object id public
$lng
static appendPathToObject($writer, $refid)
getTitle()
get object title public
getDescription()
get object description
getImportId()
get import id
$ilUser
Definition: imgupload.php:18
redirection script todo: (a better solution should control the processing via a xml file) ...
xmlHeader()
Writes xml header public.
static _lookupSuffix($a_id)
lookup suffix
getType()
get object type public
__appendOperations($a_ref_id, $a_type)
setHighlighter($a_highlighter)
__appendObjectProperties(ilObject $obj)
Append object properties.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
__getAccessInfo(&$object, $ref_id)
getRefId()
get reference id public
static _lookupVersion($a_id)
lookup version
getLastUpdateDate()
get last update date public
$info
Definition: index.php:5