ILIAS  Release_5_0_x_branch Revision 61816
 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  $this->__appendObject($object);
149  }
150  $this->__buildFooter();
151 
152  return true;
153  }
154 
155  function getXML()
156  {
157  return $this->xmlDumpMem(false);
158  }
159 
160 
161  // PRIVATE
162  function __appendObject(&$object)
163  {
164 
165  global $tree, $rbacreview;
166 
167  $id = $object->getId();
168  if ($object->getType() == "role" && $rbacreview->isRoleDeleted($id))
169  {
170  return;
171  }
172 
173  $attrs = array('type' => $object->getType(),
174  'obj_id' => $id);
175 
176  $this->xmlStartTag('Object',$attrs);
177  //$this->xmlElement('Title',null,$object->getTitle());
178  //$this->xmlElement('Description',null,$object->getDescription());
179 
180  // begin-patch fm
181  if($this->mode == self::MODE_SEARCH_RESULT)
182  {
183  $title = $object->getTitle();
184  if($this->highlighter->getTitle($object->getId(),0))
185  {
186  $title = $this->highlighter->getTitle($object->getId(),0);
187  }
188  $description = $object->getDescription();
189  if($this->highlighter->getDescription($object->getId(),0))
190  {
191  $description = $this->highlighter->getDescription($object->getId(),0);
192  }
193 
194  // Currently disabled
195  #$this->xmlElement('Title', null, $title);
196  #$this->xmlElement('Description',null,$description);
197  #$this->xmlElement('SearchResultContent', null, $this->highlighter->getContent($object->getId(),0));
198 
199  $this->xmlElement('Title',null,$object->getTitle());
200  $this->xmlElement('Description',null,$object->getDescription());
201  }
202  else
203  {
204  $this->xmlElement('Title',null,$object->getTitle());
205  $this->xmlElement('Description',null,$object->getDescription());
206  }
207  // end-patch fm
208 
209  $this->xmlElement('Owner',null,$object->getOwner());
210  $this->xmlElement('CreateDate',null,$object->getCreateDate());
211  $this->xmlElement('LastUpdate',null,$object->getLastUpdateDate());
212  $this->xmlElement('ImportId',null,$object->getImportId());
213 
214  $this->__appendObjectProperties($object);
215 
216  // begin-patch filemanager
217  if($this->enabledReferences())
218  {
219  $refs = ilObject::_getAllReferences($object->getId());
220  }
221  else
222  {
223  $refs = array($object->getRefId());
224  }
225 
226  foreach($refs as $ref_id)
227  // end-patch filemanager
228  {
229  if (!$tree->isInTree($ref_id))
230  continue;
231 
232  $attr = array('ref_id' => $ref_id, 'parent_id'=> $tree->getParentId(intval($ref_id)));
233  $attr['accessInfo'] = $this->__getAccessInfo($object,$ref_id);
234  $this->xmlStartTag('References',$attr);
235  $this->__appendTimeTargets($ref_id);
236  $this->__appendOperations($ref_id,$object->getType());
237  $this->__appendPath ($ref_id);
238  $this->xmlEndTag('References');
239  }
240  $this->xmlEndTag('Object');
241  }
242 
248  public function __appendTimeTargets($a_ref_id)
249  {
250  global $tree;
251 
252  if(!$tree->checkForParentType($a_ref_id,'crs')) {
253  return;
254  }
255  include_once('./Services/Object/classes/class.ilObjectActivation.php');
256  $time_targets = ilObjectActivation::getItem($a_ref_id);
257 
258  switch($time_targets['timing_type'])
259  {
261  $type = self::TIMING_DEACTIVATED;
262  break;
265  break;
267  $type = self::TIMING_PRESETTING;
268  break;
269  default:
270  $type = self::TIMING_DEACTIVATED;
271  break;
272  }
273 
274  $this->xmlStartTag('TimeTarget',array('type' => $type));
275 
276 # if($type == self::TIMING_TEMPORARILY_AVAILABLE)
277  {
278  $vis = $time_targets['visible'] == 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
279  $this->xmlElement('Timing',
280  array('starting_time' => $time_targets['timing_start'],
281  'ending_time' => $time_targets['timing_end'],
282  'visibility' => $vis));
283 
284  }
285 # if($type == self::TIMING_PRESETTING)
286  {
287  if($time_targets['changeable'] or 1)
288  {
289  $this->xmlElement('Suggestion',
290  array('starting_time' => $time_targets['suggestion_start'],
291  'ending_time' => $time_targets['suggestion_end'],
292  'changeable' => $time_targets['changeable'],
293  'earliest_start' => $time_targets['earliest_start'],
294  'latest_end' => $time_targets['latest_end']));
295  }
296  else
297  {
298  $this->xmlElement('Suggestion',
299  array('starting_time' => $time_targets['suggestion_start'],
300  'ending_time' => $time_targets['suggestion_end'],
301  'changeable' => $time_targets['changeable']));
302  }
303  }
304  $this->xmlEndTag('TimeTarget');
305  return;
306  }
307 
308 
313  public function __appendObjectProperties(ilObject $obj)
314  {
315  switch($obj->getType()) {
316 
317  case 'file':
318  include_once './Modules/File/classes/class.ilObjFileAccess.php';
320  $extension = ilObjFileAccess::_lookupSuffix($obj->getId());
321  $this->xmlStartTag('Properties');
322  $this->xmlElement("Property",array('name' => 'fileSize'),(int) $size);
323  $this->xmlElement("Property",array('name' => 'fileExtension'),(string) $extension);
324  // begin-patch fm
325  $this->xmlElement('Property',array('name' => 'fileVersion'), (string) ilObjFileAccess::_lookupVersion($obj->getId()));
326  // end-patch fm
327  $this->xmlEndTag('Properties');
328  break;
329  }
330 
331  }
332 
333 
334  function __appendOperations($a_ref_id,$a_type)
335  {
336  global $ilAccess,$rbacreview,$objDefinition;
337 
338  if($this->enabledOperations())
339  {
340  $ops = $rbacreview->getOperationsOnTypeString($a_type);
341  if (is_array($ops))
342  {
343  foreach($ops as $ops_id)
344  {
345  $operation = $rbacreview->getOperation($ops_id);
346 
347  if(count ($operation) && $ilAccess->checkAccessOfUser($this->getUserId(),$operation['operation'],'view',$a_ref_id))
348  {
349  $this->xmlElement('Operation',null,$operation['operation']);
350  }
351  }
352  }
353 
354  // Create operations
355  // Get creatable objects
356  $objects = $objDefinition->getCreatableSubObjects($a_type);
357  $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
358  $creation_operations = array();
359  foreach($objects as $type => $info)
360  {
361  $ops_id = $ops_ids[$type];
362 
363  if(!$ops_id)
364  {
365  continue;
366  }
367 
368  $operation = $rbacreview->getOperation($ops_id);
369 
370  if(count ($operation) && $ilAccess->checkAccessOfUser($this->getUserId(),$operation['operation'],'view',$a_ref_id))
371  {
372  $this->xmlElement('Operation',null,$operation['operation']);
373  }
374  }
375  }
376  return true;
377  }
378 
379 
380  function __appendPath ($refid){
382  }
383 
384  function __buildHeader()
385  {
386  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_object_4_0.dtd\">");
387  $this->xmlSetGenCmt("Export of ILIAS objects");
388  $this->xmlHeader();
389  $this->xmlStartTag("Objects");
390  return true;
391  }
392 
393  function __buildFooter()
394  {
395  $this->xmlEndTag('Objects');
396  }
397 
398  function __getAccessInfo(&$object,$ref_id)
399  {
400  global $ilAccess;
401 
402  include_once 'Services/AccessControl/classes/class.ilAccessHandler.php';
403 
404  $ilAccess->checkAccessOfUser($this->getUserId(),'read','view',$ref_id,$object->getType(),$object->getId());
405 
406  if(!$info = $ilAccess->getInfo())
407  {
408  return 'granted';
409  }
410  else
411  {
412  return $info[0]['type'];
413  }
414  }
415 
416 
417  public static function appendPathToObject ($writer, $refid){
418  global $tree, $lng;
419  $items = $tree->getPathFull($refid);
420  $writer->xmlStartTag("Path");
421  foreach ($items as $item) {
422  if ($item["ref_id"] == $refid)
423  continue;
424  if ($item["type"] == "root")
425  {
426  $item["title"] = $lng->txt("repository");
427  }
428  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
429  }
430  $writer->xmlEndTag("Path");
431  }
432 
433 }
434 
435 
436 ?>