ILIAS  Release_4_2_x_branch Revision 61807
 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  const TIMING_DEACTIVATED = 0;
23  const TIMING_PRESETTING = 2;
24 
27 
28 
29  var $ilias;
30 
31  var $xml;
32  var $enable_operations = false;
33  var $objects = array();
34  var $user_id = 0;
35 
36  protected $check_permission = false;
37 
45  function ilObjectXMLWriter()
46  {
47  global $ilias,$ilUser;
48 
50 
51  $this->ilias =& $ilias;
52  $this->user_id = $ilUser->getId();
53  }
54 
55  public function enablePermissionCheck($a_status)
56  {
57  $this->check_permission = $a_status;
58  }
59 
60  public function isPermissionCheckEnabled()
61  {
63  }
64 
65  function setUserId($a_id)
66  {
67  $this->user_id = $a_id;
68  }
69  function getUserId()
70  {
71  return $this->user_id;
72  }
73 
74  function enableOperations($a_status)
75  {
76  $this->enable_operations = $a_status;
77 
78  return true;
79  }
80 
81  function enabledOperations()
82  {
84  }
85 
86  function setObjects($objects)
87  {
88  $this->objects = $objects;
89  }
90 
91  function __getObjects()
92  {
93  return $this->objects ? $this->objects : array();
94  }
95 
96  function start()
97  {
98  global $ilAccess,$objDefinition;
99 
100  $this->__buildHeader();
101 
102  foreach($this->__getObjects() as $object)
103  {
104  if(method_exists($object, 'getType') and $objDefinition->isRBACObject($object->getType()))
105  {
106  if($this->isPermissionCheckEnabled() and !$ilAccess->checkAccessOfUser($this->getUserId(),'read','',$object->getRefId()))
107  {
108  continue;
109  }
110  }
111  $this->__appendObject($object);
112  }
113  $this->__buildFooter();
114 
115  return true;
116  }
117 
118  function getXML()
119  {
120  return $this->xmlDumpMem(false);
121  }
122 
123 
124  // PRIVATE
125  function __appendObject(&$object)
126  {
127 
128  global $tree, $rbacreview;
129 
130  $id = $object->getId();
131  if ($object->getType() == "role" && $rbacreview->isRoleDeleted($id))
132  {
133  return;
134  }
135 
136  $attrs = array('type' => $object->getType(),
137  'obj_id' => $id);
138 
139  $this->xmlStartTag('Object',$attrs);
140  $this->xmlElement('Title',null,$object->getTitle());
141  $this->xmlElement('Description',null,$object->getDescription());
142  $this->xmlElement('Owner',null,$object->getOwner());
143  $this->xmlElement('CreateDate',null,$object->getCreateDate());
144  $this->xmlElement('LastUpdate',null,$object->getLastUpdateDate());
145  $this->xmlElement('ImportId',null,$object->getImportId());
146 
147  foreach(ilObject::_getAllReferences($object->getId()) as $ref_id)
148  {
149  if (!$tree->isInTree($ref_id))
150  continue;
151 
152  $attr = array('ref_id' => $ref_id, 'parent_id'=> $tree->getParentId(intval($ref_id)));
153  $attr['accessInfo'] = $this->__getAccessInfo($object,$ref_id);
154  $this->xmlStartTag('References',$attr);
155  $this->__appendTimeTargets($ref_id);
156  $this->__appendOperations($ref_id,$object->getType());
157  $this->__appendPath ($ref_id);
158  $this->xmlEndTag('References');
159  }
160  $this->xmlEndTag('Object');
161  }
162 
168  public function __appendTimeTargets($a_ref_id)
169  {
170  global $tree;
171 
172  if(!$tree->checkForParentType($a_ref_id,'crs')) {
173  return;
174  }
175  include_once('./Modules/Course/classes/class.ilCourseItems.php');
176  $time_targets = ilCourseItems::_getItem($a_ref_id);
177 
178  switch($time_targets['timing_type'])
179  {
181  $type = self::TIMING_DEACTIVATED;
182  break;
185  break;
187  $type = self::TIMING_PRESETTING;
188  break;
189  default:
190  $type = self::TIMING_DEACTIVATED;
191  break;
192  }
193 
194  $this->xmlStartTag('TimeTarget',array('type' => $type));
195 
196 # if($type == self::TIMING_TEMPORARILY_AVAILABLE)
197  {
198  $vis = $time_targets['visible'] == 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
199  $this->xmlElement('Timing',
200  array('starting_time' => $time_targets['timing_start'],
201  'ending_time' => $time_targets['timing_end'],
202  'visibility' => $vis));
203 
204  }
205 # if($type == self::TIMING_PRESETTING)
206  {
207  if($time_targets['changeable'] or 1)
208  {
209  $this->xmlElement('Suggestion',
210  array('starting_time' => $time_targets['suggestion_start'],
211  'ending_time' => $time_targets['suggestion_end'],
212  'changeable' => $time_targets['changeable'],
213  'earliest_start' => $time_targets['earliest_start'],
214  'latest_end' => $time_targets['latest_end']));
215  }
216  else
217  {
218  $this->xmlElement('Suggestion',
219  array('starting_time' => $time_targets['suggestion_start'],
220  'ending_time' => $time_targets['suggestion_end'],
221  'changeable' => $time_targets['changeable']));
222  }
223  }
224  $this->xmlEndTag('TimeTarget');
225  return;
226  }
227 
228 
229 
230  function __appendOperations($a_ref_id,$a_type)
231  {
232  global $ilAccess,$rbacreview;
233 
234  if($this->enabledOperations())
235  {
236  $ops = $rbacreview->getOperationsOnTypeString($a_type);
237  if (is_array($ops))
238  {
239  foreach($ops as $ops_id)
240  {
241  $operation = $rbacreview->getOperation($ops_id);
242 
243  if(count ($operation) && $ilAccess->checkAccessOfUser($this->getUserId(),$operation['operation'],'view',$a_ref_id))
244  {
245  $this->xmlElement('Operation',null,$operation['operation']);
246  }
247  }
248  }
249  }
250  return true;
251  }
252 
253 
254  function __appendPath ($refid){
256  }
257 
258  function __buildHeader()
259  {
260  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_object_4_0.dtd\">");
261  $this->xmlSetGenCmt("Export of ILIAS objects");
262  $this->xmlHeader();
263  $this->xmlStartTag("Objects");
264  return true;
265  }
266 
267  function __buildFooter()
268  {
269  $this->xmlEndTag('Objects');
270  }
271 
272  function __getAccessInfo(&$object,$ref_id)
273  {
274  global $ilAccess;
275 
276  include_once 'Services/AccessControl/classes/class.ilAccessHandler.php';
277 
278  $ilAccess->checkAccessOfUser($this->getUserId(),'read','view',$ref_id,$object->getType(),$object->getId());
279 
280  if(!$info = $ilAccess->getInfo())
281  {
282  return 'granted';
283  }
284  else
285  {
286  return $info[0]['type'];
287  }
288  }
289 
290 
291  public static function appendPathToObject ($writer, $refid){
292  global $tree, $lng;
293  $items = $tree->getPathFull($refid);
294  $writer->xmlStartTag("Path");
295  foreach ($items as $item) {
296  if ($item["ref_id"] == $refid)
297  continue;
298  if ($item["type"] == "root")
299  {
300  $item["title"] = $lng->txt("repository");
301  }
302  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
303  }
304  $writer->xmlEndTag("Path");
305  }
306 
307 }
308 
309 
310 ?>