ILIAS  Release_3_10_x_branch Revision 61812
 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  var $ilias;
43 
44  var $xml;
45  var $enable_operations = false;
46  var $objects = array();
47  var $user_id = 0;
48 
56  function ilObjectXMLWriter()
57  {
58  global $ilias,$ilUser;
59 
61 
62  $this->ilias =& $ilias;
63  $this->user_id = $ilUser->getId();
64  }
65 
66  function setUserId($a_id)
67  {
68  $this->user_id = $a_id;
69  }
70  function getUserId()
71  {
72  return $this->user_id;
73  }
74 
75  function enableOperations($a_status)
76  {
77  $this->enable_operations = $a_status;
78 
79  return true;
80  }
81 
82  function enabledOperations()
83  {
85  }
86 
87  function setObjects($objects)
88  {
89  $this->objects = $objects;
90  }
91 
92  function __getObjects()
93  {
94  return $this->objects ? $this->objects : array();
95  }
96 
97  function start()
98  {
99  /*if(!count($objects = $this->__getObjects()))
100  {
101  return false;
102  }*/
103 
104  $this->__buildHeader();
105 
106  foreach($this->__getObjects() as $object)
107  {
108  $this->__appendObject($object);
109  }
110  $this->__buildFooter();
111 
112  return true;
113  }
114 
115  function getXML()
116  {
117  return $this->xmlDumpMem(FALSE);
118  }
119 
120 
121  // PRIVATE
122  function __appendObject(&$object)
123  {
124 
125  global $tree, $rbacreview;
126 
127  $id = $object->getId();
128  if ($object->getType() == "role" && $rbacreview->isRoleDeleted($id))
129  {
130  return;
131  }
132 
133  $attrs = array('type' => $object->getType(),
134  'obj_id' => $id);
135 
136  $this->xmlStartTag('Object',$attrs);
137  $this->xmlElement('Title',null,$object->getTitle());
138  $this->xmlElement('Description',null,$object->getDescription());
139  $this->xmlElement('Owner',null,$object->getOwner());
140  $this->xmlElement('CreateDate',null,$object->getCreateDate());
141  $this->xmlElement('LastUpdate',null,$object->getLastUpdateDate());
142  $this->xmlElement('ImportId',null,$object->getImportId());
143 
144  foreach(ilObject::_getAllReferences($object->getId()) as $ref_id)
145  {
146  if (!$tree->isInTree($ref_id))
147  continue;
148 
149  $attr = array('ref_id' => $ref_id, 'parent_id'=> $tree->getParentId(intval($ref_id)));
150  $attr['accessInfo'] = $this->__getAccessInfo($object,$ref_id);
151  $this->xmlStartTag('References',$attr);
152  $this->__appendOperations($ref_id,$object->getType());
153  $this->__appendPath ($ref_id);
154  $this->xmlEndTag('References');
155  }
156  $this->xmlEndTag('Object');
157  }
158 
159  function __appendOperations($a_ref_id,$a_type)
160  {
161  global $ilAccess,$rbacreview;
162 
163  if($this->enabledOperations())
164  {
165  $ops = $rbacreview->getOperationsOnTypeString($a_type);
166  if (is_array($ops))
167  {
168  foreach($ops as $ops_id)
169  {
170  $operation = $rbacreview->getOperation($ops_id);
171 
172  if(count ($operation) && $ilAccess->checkAccessOfUser($this->getUserId(),$operation['operation'],'view',$a_ref_id))
173  {
174  $this->xmlElement('Operation',null,$operation['operation']);
175  }
176  }
177  }
178  }
179  return true;
180  }
181 
182 
183  function __appendPath ($refid){
185  }
186 
187  function __buildHeader()
188  {
189  $this->xmlSetDtdDef("<!DOCTYPE Objects PUBLIC \"-//ILIAS//DTD ILIAS Repositoryobjects//EN\" \"".ILIAS_HTTP_PATH."/xml/ilias_object_3_10.dtd\">");
190  $this->xmlSetGenCmt("Export of ILIAS objects");
191  $this->xmlHeader();
192  $this->xmlStartTag("Objects");
193  return true;
194  }
195 
196  function __buildFooter()
197  {
198  $this->xmlEndTag('Objects');
199  }
200 
201  function __getAccessInfo(&$object,$ref_id)
202  {
203  global $ilAccess;
204 
205  include_once 'Services/AccessControl/classes/class.ilAccessHandler.php';
206 
207  $ilAccess->checkAccessOfUser($this->getUserId(),'read','view',$ref_id,$object->getType(),$object->getId());
208 
209  if(!$info = $ilAccess->getInfo())
210  {
211  return 'granted';
212  }
213  else
214  {
215  return $info[0]['type'];
216  }
217  }
218 
219 
220  public static function appendPathToObject ($writer, $refid){
221  global $tree, $lng;
222  $items = $tree->getPathFull($refid);
223  $writer->xmlStartTag("Path");
224  foreach ($items as $item) {
225  if ($item["ref_id"] == $refid)
226  continue;
227  if ($item["type"] == "root")
228  {
229  $item["title"] = $lng->txt("repository");
230  }
231  $writer->xmlElement("Element", array("ref_id" => $item["ref_id"], "type" => $item["type"]), $item["title"]);
232  }
233  $writer->xmlEndTag("Path");
234  }
235 
236 }
237 
238 
239 ?>