ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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  var $ilias;
38 
39  var $xml;
40  var $enable_operations = false;
41  // begin-patch filemanager
42  private $enable_references = true;
43  // end-patch filemanager
44  var $objects = array();
45  var $user_id = 0;
46 
47  protected $check_permission = false;
48 
56  function ilObjectXMLWriter()
57  {
58  global $ilias,$ilUser;
59 
61 
62  $this->ilias =& $ilias;
63  $this->user_id = $ilUser->getId();
64  }
65 
66  // begin-patch fm
67  public function setMode($a_mode)
68  {
69  $this->mode = $a_mode;
70  }
71 
72  public function setHighlighter($a_highlighter)
73  {
74  $this->highlighter = $a_highlighter;
75  }
76  // end-patch fm
77 
78 
79  public function enablePermissionCheck($a_status)
80  {
81  $this->check_permission = $a_status;
82  }
83 
84  public function isPermissionCheckEnabled()
85  {
87  }
88 
89  function setUserId($a_id)
90  {
91  $this->user_id = $a_id;
92  }
93  function getUserId()
94  {
95  return $this->user_id;
96  }
97 
98  function enableOperations($a_status)
99  {
100  $this->enable_operations = $a_status;
101 
102  return true;
103  }
104 
105  function enabledOperations()
106  {
108  }
109 
110  // begin-patch filemanager
111  public function enableReferences($a_stat)
112  {
113  $this->enable_references = $a_stat;
114  }
115 
116  public function enabledReferences()
117  {
119  }
120  // end-patch filemanager
121 
122 
124  {
125  $this->objects = $objects;
126  }
127 
128  function __getObjects()
129  {
130  return $this->objects ? $this->objects : array();
131  }
132 
133  function start()
134  {
135  global $ilAccess,$objDefinition;
136 
137  $this->__buildHeader();
138 
139  foreach($this->__getObjects() as $object)
140  {
141  if(method_exists($object, 'getType') and $objDefinition->isRBACObject($object->getType()))
142  {
143  if($this->isPermissionCheckEnabled() and !$ilAccess->checkAccessOfUser($this->getUserId(),'read','',$object->getRefId()))
144  {
145  continue;
146  }
147  }
148  if (is_object($object))
149  $this->__appendObject($object);
150  }
151  $this->__buildFooter();
152 
153  return true;
154  }
155 
156  function getXML()
157  {
158  return $this->xmlDumpMem(false);
159  }
160 
161 
162  // PRIVATE
163  function __appendObject($object)
164  {
165 
166  global $tree, $rbacreview;
167 
168  $id = $object->getId();
169  if ($object->getType() == "role" && $rbacreview->isRoleDeleted($id))
170  {
171  return;
172  }
173 
174  $attrs = array('type' => $object->getType(),
175  'obj_id' => $id);
176 
177  $this->xmlStartTag('Object',$attrs);
178  //$this->xmlElement('Title',null,$object->getTitle());
179  //$this->xmlElement('Description',null,$object->getDescription());
180 
181  // begin-patch fm
182  if($this->mode == self::MODE_SEARCH_RESULT)
183  {
184  $title = $object->getTitle();
185  if($this->highlighter->getTitle($object->getId(),0))
186  {
187  $title = $this->highlighter->getTitle($object->getId(),0);
188  }
189  $description = $object->getDescription();
190  if($this->highlighter->getDescription($object->getId(),0))
191  {
192  $description = $this->highlighter->getDescription($object->getId(),0);
193  }
194 
195  // Currently disabled
196  #$this->xmlElement('Title', null, $title);
197  #$this->xmlElement('Description',null,$description);
198  #$this->xmlElement('SearchResultContent', null, $this->highlighter->getContent($object->getId(),0));
199 
200  $this->xmlElement('Title',null,$object->getTitle());
201  $this->xmlElement('Description',null,$object->getDescription());
202  }
203  else
204  {
205  $this->xmlElement('Title',null,$object->getTitle());
206  $this->xmlElement('Description',null,$object->getDescription());
207  }
208  // end-patch fm
209 
210  $this->xmlElement('Owner',null,$object->getOwner());
211  $this->xmlElement('CreateDate',null,$object->getCreateDate());
212  $this->xmlElement('LastUpdate',null,$object->getLastUpdateDate());
213  $this->xmlElement('ImportId',null,$object->getImportId());
214 
215  $this->__appendObjectProperties($object);
216 
217  // begin-patch filemanager
218  if($this->enabledReferences())
219  {
220  $refs = ilObject::_getAllReferences($object->getId());
221  }
222  else
223  {
224  $refs = array($object->getRefId());
225  }
226 
227  foreach($refs as $ref_id)
228  // end-patch filemanager
229  {
230  if (!$tree->isInTree($ref_id))
231  continue;
232 
233  $attr = array('ref_id' => $ref_id, 'parent_id'=> $tree->getParentId(intval($ref_id)));
234  $attr['accessInfo'] = $this->__getAccessInfo($object,$ref_id);
235  $this->xmlStartTag('References',$attr);
236  $this->__appendTimeTargets($ref_id);
237  $this->__appendOperations($ref_id,$object->getType());
238  $this->__appendPath ($ref_id);
239  $this->xmlEndTag('References');
240  }
241  $this->xmlEndTag('Object');
242  }
243 
249  public function __appendTimeTargets($a_ref_id)
250  {
251  global $tree;
252 
253  if(!$tree->checkForParentType($a_ref_id,'crs')) {
254  return;
255  }
256  include_once('./Services/Object/classes/class.ilObjectActivation.php');
257  $time_targets = ilObjectActivation::getItem($a_ref_id);
258 
259  switch($time_targets['timing_type'])
260  {
262  $type = self::TIMING_DEACTIVATED;
263  break;
266  break;
268  $type = self::TIMING_PRESETTING;
269  break;
270  default:
271  $type = self::TIMING_DEACTIVATED;
272  break;
273  }
274 
275  $this->xmlStartTag('TimeTarget',array('type' => $type));
276 
277 # if($type == self::TIMING_TEMPORARILY_AVAILABLE)
278  {
279  $vis = $time_targets['visible'] == 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
280  $this->xmlElement('Timing',
281  array('starting_time' => $time_targets['timing_start'],
282  'ending_time' => $time_targets['timing_end'],
283  'visibility' => $vis));
284 
285  }
286 # if($type == self::TIMING_PRESETTING)
287  {
288  if($time_targets['changeable'] or 1)
289  {
290  $this->xmlElement('Suggestion',
291  array('starting_time' => $time_targets['suggestion_start'],
292  'ending_time' => $time_targets['suggestion_end'],
293  'changeable' => $time_targets['changeable'],
294  'earliest_start' => $time_targets['earliest_start'],
295  'latest_end' => $time_targets['latest_end']));
296  }
297  else
298  {
299  $this->xmlElement('Suggestion',
300  array('starting_time' => $time_targets['suggestion_start'],
301  'ending_time' => $time_targets['suggestion_end'],
302  'changeable' => $time_targets['changeable']));
303  }
304  }
305  $this->xmlEndTag('TimeTarget');
306  return;
307  }
308 
309 
314  public function __appendObjectProperties(ilObject $obj)
315  {
316  switch($obj->getType()) {
317 
318  case 'file':
319  include_once './Modules/File/classes/class.ilObjFileAccess.php';
321  $extension = ilObjFileAccess::_lookupSuffix($obj->getId());
322  $this->xmlStartTag('Properties');
323  $this->xmlElement("Property",array('name' => 'fileSize'),(int) $size);
324  $this->xmlElement("Property",array('name' => 'fileExtension'),(string) $extension);
325  // begin-patch fm
326  $this->xmlElement('Property',array('name' => 'fileVersion'), (string) ilObjFileAccess::_lookupVersion($obj->getId()));
327  // end-patch fm
328  $this->xmlEndTag('Properties');
329  break;
330  }
331 
332  }
333 
334 
335  function __appendOperations($a_ref_id,$a_type)
336  {
337  global $ilAccess,$rbacreview,$objDefinition;
338 
339  if($this->enabledOperations())
340  {
341  $ops = $rbacreview->getOperationsOnTypeString($a_type);
342  if (is_array($ops))
343  {
344  foreach($ops as $ops_id)
345  {
346  $operation = $rbacreview->getOperation($ops_id);
347 
348  if(count ($operation) && $ilAccess->checkAccessOfUser($this->getUserId(),$operation['operation'],'view',$a_ref_id))
349  {
350  $this->xmlElement('Operation',null,$operation['operation']);
351  }
352  }
353  }
354 
355  // Create operations
356  // Get creatable objects
357  $objects = $objDefinition->getCreatableSubObjects($a_type);
358  $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
359  $creation_operations = array();
360  foreach($objects as $type => $info)
361  {
362  $ops_id = $ops_ids[$type];
363 
364  if(!$ops_id)
365  {
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  {
373  $this->xmlElement('Operation',null,$operation['operation']);
374  }
375  }
376  }
377  return true;
378  }
379 
380 
381  function __appendPath ($refid){
383  }
384 
385  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  function __buildFooter()
395  {
396  $this->xmlEndTag('Objects');
397  }
398 
399  function __getAccessInfo(&$object,$ref_id)
400  {
401  global $ilAccess;
402 
403  include_once 'Services/AccessControl/classes/class.ilAccessHandler.php';
404 
405  $ilAccess->checkAccessOfUser($this->getUserId(),'read','view',$ref_id,$object->getType(),$object->getId());
406 
407  if(!$info = $ilAccess->getInfo())
408  {
409  return 'granted';
410  }
411  else
412  {
413  return $info[0]['type'];
414  }
415  }
416 
417 
418  public static function appendPathToObject ($writer, $refid){
419  global $tree, $lng;
420  $items = $tree->getPathFull($refid);
421  $writer->xmlStartTag("Path");
422  foreach ($items as $item) {
423  if ($item["ref_id"] == $refid)
424  continue;
425  if ($item["type"] == "root")
426  {
427  $item["title"] = $lng->txt("repository");
428  }
429  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
430  }
431  $writer->xmlEndTag("Path");
432  }
433 
434 }
435 
436 
437 ?>