ILIAS  Release_4_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 /*
4  +-----------------------------------------------------------------------------+
5  | ILIAS open source |
6  +-----------------------------------------------------------------------------+
7  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
8  | |
9  | This program is free software; you can redistribute it and/or |
10  | modify it under the terms of the GNU General Public License |
11  | as published by the Free Software Foundation; either version 2 |
12  | of the License, or (at your option) any later version. |
13  | |
14  | This program is distributed in the hope that it will be useful, |
15  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
16  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17  | GNU General Public License for more details. |
18  | |
19  | You should have received a copy of the GNU General Public License |
20  | along with this program; if not, write to the Free Software |
21  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22  +-----------------------------------------------------------------------------+
23 */
24 
38 include_once "./classes/class.ilXmlWriter.php";
39 
41 {
42  const TIMING_DEACTIVATED = 0;
44  const TIMING_PRESETTING = 2;
45 
48 
49 
50  var $ilias;
51 
52  var $xml;
53  var $enable_operations = false;
54  var $objects = array();
55  var $user_id = 0;
56 
57  protected $check_permission = false;
58 
66  function ilObjectXMLWriter()
67  {
68  global $ilias,$ilUser;
69 
71 
72  $this->ilias =& $ilias;
73  $this->user_id = $ilUser->getId();
74  }
75 
76  public function enablePermissionCheck($a_status)
77  {
78  $this->check_permission = $a_status;
79  }
80 
81  public function isPermissionCheckEnabled()
82  {
84  }
85 
86  function setUserId($a_id)
87  {
88  $this->user_id = $a_id;
89  }
90  function getUserId()
91  {
92  return $this->user_id;
93  }
94 
95  function enableOperations($a_status)
96  {
97  $this->enable_operations = $a_status;
98 
99  return true;
100  }
101 
102  function enabledOperations()
103  {
105  }
106 
108  {
109  $this->objects = $objects;
110  }
111 
112  function __getObjects()
113  {
114  return $this->objects ? $this->objects : array();
115  }
116 
117  function start()
118  {
119  global $ilAccess,$objDefinition;
120 
121  $this->__buildHeader();
122 
123  foreach($this->__getObjects() as $object)
124  {
125  if(method_exists($object, 'getType') and $objDefinition->isRBACObject($object->getType()))
126  {
127  if($this->isPermissionCheckEnabled() and !$ilAccess->checkAccessOfUser($this->getUserId(),'read','',$object->getRefId()))
128  {
129  continue;
130  }
131  }
132  $this->__appendObject($object);
133  }
134  $this->__buildFooter();
135 
136  return true;
137  }
138 
139  function getXML()
140  {
141  return $this->xmlDumpMem(false);
142  }
143 
144 
145  // PRIVATE
146  function __appendObject(&$object)
147  {
148 
149  global $tree, $rbacreview;
150 
151  $id = $object->getId();
152  if ($object->getType() == "role" && $rbacreview->isRoleDeleted($id))
153  {
154  return;
155  }
156 
157  $attrs = array('type' => $object->getType(),
158  'obj_id' => $id);
159 
160  $this->xmlStartTag('Object',$attrs);
161  $this->xmlElement('Title',null,$object->getTitle());
162  $this->xmlElement('Description',null,$object->getDescription());
163  $this->xmlElement('Owner',null,$object->getOwner());
164  $this->xmlElement('CreateDate',null,$object->getCreateDate());
165  $this->xmlElement('LastUpdate',null,$object->getLastUpdateDate());
166  $this->xmlElement('ImportId',null,$object->getImportId());
167 
168  foreach(ilObject::_getAllReferences($object->getId()) as $ref_id)
169  {
170  if (!$tree->isInTree($ref_id))
171  continue;
172 
173  $attr = array('ref_id' => $ref_id, 'parent_id'=> $tree->getParentId(intval($ref_id)));
174  $attr['accessInfo'] = $this->__getAccessInfo($object,$ref_id);
175  $this->xmlStartTag('References',$attr);
176  $this->__appendTimeTargets($ref_id);
177  $this->__appendOperations($ref_id,$object->getType());
178  $this->__appendPath ($ref_id);
179  $this->xmlEndTag('References');
180  }
181  $this->xmlEndTag('Object');
182  }
183 
189  public function __appendTimeTargets($a_ref_id)
190  {
191  global $tree;
192 
193  if(!$tree->checkForParentType($a_ref_id,'crs')) {
194  return;
195  }
196  include_once('./Modules/Course/classes/class.ilCourseItems.php');
197  $time_targets = ilCourseItems::_getItem($a_ref_id);
198 
199  switch($time_targets['timing_type'])
200  {
203  break;
206  break;
209  break;
210  default:
212  break;
213  }
214 
215  $this->xmlStartTag('TimeTarget',array('type' => $type));
216 
217 # if($type == self::TIMING_TEMPORARILY_AVAILABLE)
218  {
219  $vis = $time_targets['visible'] == 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
220  $this->xmlElement('Timing',
221  array('starting_time' => $time_targets['timing_start'],
222  'ending_time' => $time_targets['timing_end'],
223  'visibility' => $vis));
224 
225  }
226 # if($type == self::TIMING_PRESETTING)
227  {
228  if($time_targets['changeable'] or 1)
229  {
230  $this->xmlElement('Suggestion',
231  array('starting_time' => $time_targets['suggestion_start'],
232  'ending_time' => $time_targets['suggestion_end'],
233  'changeable' => $time_targets['changeable'],
234  'earliest_start' => $time_targets['earliest_start'],
235  'latest_end' => $time_targets['latest_end']));
236  }
237  else
238  {
239  $this->xmlElement('Suggestion',
240  array('starting_time' => $time_targets['suggestion_start'],
241  'ending_time' => $time_targets['suggestion_end'],
242  'changeable' => $time_targets['changeable']));
243  }
244  }
245  $this->xmlEndTag('TimeTarget');
246  return;
247  }
248 
249 
250 
251  function __appendOperations($a_ref_id,$a_type)
252  {
253  global $ilAccess,$rbacreview;
254 
255  if($this->enabledOperations())
256  {
257  $ops = $rbacreview->getOperationsOnTypeString($a_type);
258  if (is_array($ops))
259  {
260  foreach($ops as $ops_id)
261  {
262  $operation = $rbacreview->getOperation($ops_id);
263 
264  if(count ($operation) && $ilAccess->checkAccessOfUser($this->getUserId(),$operation['operation'],'view',$a_ref_id))
265  {
266  $this->xmlElement('Operation',null,$operation['operation']);
267  }
268  }
269  }
270  }
271  return true;
272  }
273 
274 
275  function __appendPath ($refid){
277  }
278 
279  function __buildHeader()
280  {
281  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_object_4_0.dtd\">");
282  $this->xmlSetGenCmt("Export of ILIAS objects");
283  $this->xmlHeader();
284  $this->xmlStartTag("Objects");
285  return true;
286  }
287 
288  function __buildFooter()
289  {
290  $this->xmlEndTag('Objects');
291  }
292 
293  function __getAccessInfo(&$object,$ref_id)
294  {
295  global $ilAccess;
296 
297  include_once 'Services/AccessControl/classes/class.ilAccessHandler.php';
298 
299  $ilAccess->checkAccessOfUser($this->getUserId(),'read','view',$ref_id,$object->getType(),$object->getId());
300 
301  if(!$info = $ilAccess->getInfo())
302  {
303  return 'granted';
304  }
305  else
306  {
307  return $info[0]['type'];
308  }
309  }
310 
311 
312  public static function appendPathToObject ($writer, $refid){
313  global $tree, $lng;
314  $items = $tree->getPathFull($refid);
315  $writer->xmlStartTag("Path");
316  foreach ($items as $item) {
317  if ($item["ref_id"] == $refid)
318  continue;
319  if ($item["type"] == "root")
320  {
321  $item["title"] = $lng->txt("repository");
322  }
323  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
324  }
325  $writer->xmlEndTag("Path");
326  }
327 
328 }
329 
330 
331 ?>