ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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
5include_once "./Services/Xml/classes/class.ilXmlWriter.php";
6
20{
21 // begin-patch fm
23
24 private $mode = 0;
25 private $highlighter = null;
26 // end-patch fm
27
28
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 $ilias,$ilUser;
59
60 parent::__construct();
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 public function setUserId($a_id)
90 {
91 $this->user_id = $a_id;
92 }
93 public function getUserId()
94 {
95 return $this->user_id;
96 }
97
98 public function enableOperations($a_status)
99 {
100 $this->enable_operations = $a_status;
101
102 return true;
103 }
104
105 public 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
123 public function setObjects($objects)
124 {
125 $this->objects = $objects;
126 }
127
128 public function __getObjects()
129 {
130 return $this->objects ? $this->objects : array();
131 }
132
133 public function start()
134 {
135 global $ilAccess,$objDefinition;
136
137 $this->__buildHeader();
138
139 foreach ($this->__getObjects() as $object) {
140 if (method_exists($object, 'getType') and $objDefinition->isRBACObject($object->getType())) {
141 if ($this->isPermissionCheckEnabled() and !$ilAccess->checkAccessOfUser($this->getUserId(), 'read', '', $object->getRefId())) {
142 continue;
143 }
144 }
145 $this->__appendObject($object);
146 }
147 $this->__buildFooter();
148
149 return true;
150 }
151
152 public function getXML()
153 {
154 return $this->xmlDumpMem(false);
155 }
156
157
158 // PRIVATE
159 public function __appendObject(&$object)
160 {
161 global $tree, $rbacreview;
162
163 $id = $object->getId();
164 if ($object->getType() == "role" && $rbacreview->isRoleDeleted($id)) {
165 return;
166 }
167
168 $attrs = array('type' => $object->getType(),
169 'obj_id' => $id);
170
171 $this->xmlStartTag('Object', $attrs);
172 //$this->xmlElement('Title',null,$object->getTitle());
173 //$this->xmlElement('Description',null,$object->getDescription());
174
175 // begin-patch fm
176 if ($this->mode == self::MODE_SEARCH_RESULT) {
177 $title = $object->getTitle();
178 if ($this->highlighter->getTitle($object->getId(), 0)) {
179 $title = $this->highlighter->getTitle($object->getId(), 0);
180 }
181 $description = $object->getDescription();
182 if ($this->highlighter->getDescription($object->getId(), 0)) {
183 $description = $this->highlighter->getDescription($object->getId(), 0);
184 }
185
186 // Currently disabled
187 #$this->xmlElement('Title', null, $title);
188 #$this->xmlElement('Description',null,$description);
189 #$this->xmlElement('SearchResultContent', null, $this->highlighter->getContent($object->getId(),0));
190
191 $this->xmlElement('Title', null, $object->getTitle());
192 $this->xmlElement('Description', null, $object->getDescription());
193 } else {
194 $this->xmlElement('Title', null, $object->getTitle());
195 $this->xmlElement('Description', null, $object->getDescription());
196 }
197 // end-patch fm
198
199 $this->xmlElement('Owner', null, $object->getOwner());
200 $this->xmlElement('CreateDate', null, $object->getCreateDate());
201 $this->xmlElement('LastUpdate', null, $object->getLastUpdateDate());
202 $this->xmlElement('ImportId', null, $object->getImportId());
203
204 $this->__appendObjectProperties($object);
205
206 // begin-patch filemanager
207 if ($this->enabledReferences()) {
208 $refs = ilObject::_getAllReferences($object->getId());
209 } else {
210 $refs = array($object->getRefId());
211 }
212
213 foreach ($refs as $ref_id) {
214 // end-patch filemanager
215 if (!$tree->isInTree($ref_id)) {
216 continue;
217 }
218
219 $attr = array('ref_id' => $ref_id, 'parent_id'=> $tree->getParentId(intval($ref_id)));
220 $attr['accessInfo'] = $this->__getAccessInfo($object, $ref_id);
221 $this->xmlStartTag('References', $attr);
222 $this->__appendTimeTargets($ref_id);
223 $this->__appendOperations($ref_id, $object->getType());
224 $this->__appendPath($ref_id);
225 $this->xmlEndTag('References');
226 }
227 $this->xmlEndTag('Object');
228 }
229
235 public function __appendTimeTargets($a_ref_id)
236 {
237 global $tree;
238
239 if (!$tree->checkForParentType($a_ref_id, 'crs')) {
240 return;
241 }
242 include_once('./Services/Object/classes/class.ilObjectActivation.php');
243 $time_targets = ilObjectActivation::getItem($a_ref_id);
244
245 switch ($time_targets['timing_type']) {
248 break;
251 break;
254 break;
255 default:
257 break;
258 }
259
260 $this->xmlStartTag('TimeTarget', array('type' => $type));
261
262 # if($type == self::TIMING_TEMPORARILY_AVAILABLE)
263 {
264 $vis = $time_targets['visible'] == 0 ? self::TIMING_VISIBILITY_OFF : self::TIMING_VISIBILITY_ON;
265 $this->xmlElement(
266 'Timing',
267 array('starting_time' => $time_targets['timing_start'],
268 'ending_time' => $time_targets['timing_end'],
269 'visibility' => $vis)
270 );
271
272 }
273 # if($type == self::TIMING_PRESETTING)
274 {
275 if ($time_targets['changeable'] or 1) {
276 $this->xmlElement(
277 'Suggestion',
278 array('starting_time' => $time_targets['suggestion_start'],
279 'ending_time' => $time_targets['suggestion_end'],
280 'changeable' => $time_targets['changeable'],
281 'earliest_start' => $time_targets['earliest_start'],
282 'latest_end' => $time_targets['latest_end'])
283 );
284 } else {
285 $this->xmlElement(
286 'Suggestion',
287 array('starting_time' => $time_targets['suggestion_start'],
288 'ending_time' => $time_targets['suggestion_end'],
289 'changeable' => $time_targets['changeable'])
290 );
291 }
292 }
293 $this->xmlEndTag('TimeTarget');
294 return;
295 }
296
297
302 public function __appendObjectProperties(ilObject $obj)
303 {
304 switch ($obj->getType()) {
305
306 case 'file':
307 include_once './Modules/File/classes/class.ilObjFileAccess.php';
309 $extension = ilObjFileAccess::_lookupSuffix($obj->getId());
310 $this->xmlStartTag('Properties');
311 $this->xmlElement("Property", array('name' => 'fileSize'), (int) $size);
312 $this->xmlElement("Property", array('name' => 'fileExtension'), (string) $extension);
313 // begin-patch fm
314 $this->xmlElement('Property', array('name' => 'fileVersion'), (string) ilObjFileAccess::_lookupVersion($obj->getId()));
315 // end-patch fm
316 $this->xmlEndTag('Properties');
317 break;
318 }
319 }
320
321
322 public function __appendOperations($a_ref_id, $a_type)
323 {
324 global $ilAccess,$rbacreview,$objDefinition;
325
326 if ($this->enabledOperations()) {
327 $ops = $rbacreview->getOperationsOnTypeString($a_type);
328 if (is_array($ops)) {
329 foreach ($ops as $ops_id) {
330 $operation = $rbacreview->getOperation($ops_id);
331
332 if (count($operation) && $ilAccess->checkAccessOfUser($this->getUserId(), $operation['operation'], 'view', $a_ref_id)) {
333 $this->xmlElement('Operation', null, $operation['operation']);
334 }
335 }
336 }
337
338 // Create operations
339 // Get creatable objects
340 $objects = $objDefinition->getCreatableSubObjects($a_type);
341 $ops_ids = ilRbacReview::lookupCreateOperationIds(array_keys($objects));
342 $creation_operations = array();
343 foreach ($objects as $type => $info) {
344 $ops_id = $ops_ids[$type];
345
346 if (!$ops_id) {
347 continue;
348 }
349
350 $operation = $rbacreview->getOperation($ops_id);
351
352 if (count($operation) && $ilAccess->checkAccessOfUser($this->getUserId(), $operation['operation'], 'view', $a_ref_id)) {
353 $this->xmlElement('Operation', null, $operation['operation']);
354 }
355 }
356 }
357 return true;
358 }
359
360
361 public function __appendPath($refid)
362 {
364 }
365
366 public function __buildHeader()
367 {
368 $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"" . ILIAS_HTTP_PATH . "/xml/ilias_object_4_0.dtd\">");
369 $this->xmlSetGenCmt("Export of ILIAS objects");
370 $this->xmlHeader();
371 $this->xmlStartTag("Objects");
372 return true;
373 }
374
375 public function __buildFooter()
376 {
377 $this->xmlEndTag('Objects');
378 }
379
380 public function __getAccessInfo(&$object, $ref_id)
381 {
382 global $ilAccess;
383
384 include_once 'Services/AccessControl/classes/class.ilAccess.php';
385
386 $ilAccess->checkAccessOfUser($this->getUserId(), 'read', 'view', $ref_id, $object->getType(), $object->getId());
387
388 if (!$info = $ilAccess->getInfo()) {
389 return 'granted';
390 } else {
391 return $info[0]['type'];
392 }
393 }
394
395
396 public static function appendPathToObject($writer, $refid)
397 {
398 global $tree, $lng;
399 $items = $tree->getPathFull($refid);
400 $writer->xmlStartTag("Path");
401 foreach ($items as $item) {
402 if ($item["ref_id"] == $refid) {
403 continue;
404 }
405 if ($item["type"] == "root") {
406 $item["title"] = $lng->txt("repository");
407 }
408 $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
409 }
410 $writer->xmlEndTag("Path");
411 }
412}
$size
Definition: RandomTest.php:84
An exception for terminatinating execution or to throw for unit testing.
static _lookupFileSize($a_id)
Quickly looks up the file size from the database and returns the number of bytes.
static _lookupVersion($a_id)
lookup version
static _lookupSuffix($a_id)
lookup suffix
static getItem($a_ref_id)
Get item data.
__appendOperations($a_ref_id, $a_type)
setHighlighter($a_highlighter)
__getAccessInfo(&$object, $ref_id)
__appendTimeTargets($a_ref_id)
Append time target settings for items inside of courses.
static appendPathToObject($writer, $refid)
__appendObjectProperties(ilObject $obj)
Append object properties.
Class ilObject Basic functions for all objects.
getType()
get object type @access public
static _getAllReferences($a_id)
get all reference ids of object
getId()
get object id @access public
static lookupCreateOperationIds($a_type_arr)
Lookup operation ids.
XML writer class.
xmlEndTag($tag)
Writes an endtag.
xmlSetGenCmt($genCmt)
Sets generated comment.
xmlDumpMem($format=true)
Returns xml document from memory.
xmlHeader()
Writes xml header @access public.
xmlElement($tag, $attrs=null, $data=null, $encode=true, $escape=true)
Writes a basic element (no children, just textual content)
xmlStartTag($tag, $attrs=null, $empty=false, $encode=true, $escape=true)
Writes a starttag.
xmlSetDtdDef($dtdDef)
Sets dtd definition.
if(!array_key_exists('StateId', $_REQUEST)) $id
$info
Definition: index.php:5
redirection script todo: (a better solution should control the processing via a xml file)
global $lng
Definition: privfeed.php:17
$type
$ilUser
Definition: imgupload.php:18
$a_type
Definition: workflow.php:92