ILIAS  eassessment Revision 61809
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilCategoryImportParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 require_once("./classes/class.ilSaxParser.php");
25 
35 {
36  var $parent; // current parent ref id
37  var $withrol; // must have value '1' when creating a hierarchy of local roles
38 
39 
47  function ilCategoryImportParser($a_xml_file, $a_parent,$withrol)
48 
49  {
50  $this->parent_cnt = 0;
51  $this->parent[$this->parent_cnt] = $a_parent;
52  $this->parent_cnt++;
53  $this->withrol = $withrol;
54  parent::ilSaxParser($a_xml_file);
55  }
56 
57 
63  function setHandlers($a_xml_parser)
64  {
65  xml_set_object($a_xml_parser,$this);
66  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
67  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
68  }
69 
73  function startParsing()
74  {
76  }
77 
85  function buildTag ($type, $name, $attr="")
86  {
87  $tag = "<";
88 
89  if ($type == "end")
90  $tag.= "/";
91 
92  $tag.= $name;
93 
94  if (is_array($attr))
95  {
96  while (list($k,$v) = each($attr))
97  $tag.= " ".$k."=\"$v\"";
98  }
99 
100  $tag.= ">";
101 
102  return $tag;
103  }
104 
108  function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
109 
110  {
111 
112  global $rbacadmin, $rbacreview, $rbacsystem;
113 
114  switch($a_name)
115  {
116  case "Category":
117  $cur_parent = $this->parent[$this->parent_cnt - 1];
118  require_once("Modules/Category/classes/class.ilObjCategory.php");
119  $this->category = new ilObjCategory;
120  $this->category->setImportId($a_attribs["Id"]." (#".$cur_parent.")");
121  $this->default_language = $a_attribs["DefaultLanguage"];
122  $this->category->setTitle($a_attribs["Id"]);
123  $this->category->create();
124  $this->category->createReference();
125  $this->category->putInTree($cur_parent);
126  $this->parent[$this->parent_cnt++] = $this->category->getRefId();
127 
128  // added for create local roles to categories imported
129  if ($this->withrol) {
130 
131  //CHECK ACCESS 'create' rolefolder
132  if (!$rbacsystem->checkAccess('create',$this->category->getRefId(),'rolf')) {
133  $this->ilias->raiseError($this->lng->txt("msg_no_perm_create_rolf"),$this->ilias->error_obj->WARNING);
134  }
135 
136  include_once ("classes/class.ilObject.php");
137  include_once ("./Services/AccessControl/classes/class.ilObjRole.php");
138 
139  // create a rolefolder
140  $rolfObj = $this->category->createRoleFolder("Local roles","Role Folder of category obj_no. ".$this->category->getRefId());
141  $parentRoles = $rbacreview->getParentRoleIds($rolfObj->getRefId(),true);
142 
143  // iterate through the chosen templates to create a rol for each checkbox checked
144  foreach($_POST["adopt"] as $postadopt) {
145 
146  $desc = $a_attribs["Id"]. " ".$parentRoles[$postadopt]["title"];
147  $roleObj = $rolfObj->createRole($desc,"Local rol for category ".$desc);
148  // adopt permissions from rol template selected
149  $rbacadmin->copyRoleTemplatePermissions($postadopt,$parentRoles[$postadopt]["parent"],$rolfObj->getRefId(),$roleObj->getId());
150  unset($roleObj);
151  }
152 
153  unset($rolfObj);
154  unset($parentRoles);
155 
156  // -----------------------------
157  }
158  break;
159 
160  case "CategorySpec":
161  $this->cur_spec_lang = $a_attribs["Language"];
162  break;
163 
164  }
165 
166  }
167 
168 
172  function handlerEndTag($a_xml_parser, $a_name)
173  {
174  global $ilias, $rbacadmin;
175 
176  switch($a_name)
177  {
178  case "Category":
179  unset($this->category);
180  unset($this->parent[$this->parent_cnt - 1]);
181  $this->parent_cnt--;
182  break;
183 
184  case "CategorySpec":
185  $is_def = 0;
186  if ($this->cur_spec_lang == $this->default_language)
187  {
188  $this->category->setTitle($this->cur_title);
189  $this->category->setDescription($this->cur_description);
190  $this->category->update();
191  $is_def = 1;
192  }
193  $this->category->addTranslation($this->cur_title,
194  $this->cur_description, $this->cur_spec_lang, $is_def);
195  break;
196 
197  case "Title":
198  $this->cur_title = $this->cdata;
199  break;
200 
201  case "Description":
202  $this->cur_description = $this->cdata;
203  break;
204  }
205 
206  $this->cdata = "";
207  }
208 
212  function handlerCharacterData($a_xml_parser, $a_data)
213  {
214  // i don't know why this is necessary, but
215  // the parser seems to convert "&gt;" to ">" and "&lt;" to "<"
216  // in character data, but we don't want that, because it's the
217  // way we mask user html in our content, so we convert back...
218  $a_data = str_replace("<","&lt;",$a_data);
219  $a_data = str_replace(">","&gt;",$a_data);
220 
221  // DELETE WHITESPACES AND NEWLINES OF CHARACTER DATA
222  $a_data = preg_replace("/\n/","",$a_data);
223  $a_data = preg_replace("/\t+/","",$a_data);
224  if(!empty($a_data))
225  {
226  $this->cdata .= $a_data;
227  }
228  }
229 
230 }
231 ?>