ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilContainerReferenceXmlParser.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("./Services/Xml/classes/class.ilSaxParser.php");
25 require_once('./Services/User/classes/class.ilObjUser.php');
26 include_once('./Services/Calendar/classes/class.ilDateTime.php');
27 
28 
39 {
40  const MODE_CREATE = 1;
41  const MODE_UPDATE = 2;
42 
43  private $ref = null;
44  private $parent_id = 0;
45 
54  public function __construct($a_xml, $a_parent_id = 0)
55  {
56  parent::__construct(null);
57 
59  $this->setXMLContent($a_xml);
60  }
61 
66  public function getParentId()
67  {
68  return $this->parent_id;
69  }
70 
76  public function setHandlers($a_xml_parser)
77  {
78  xml_set_object($a_xml_parser,$this);
79  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
80  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
81  }
82 
86  public function startParsing()
87  {
89 
90  if($this->ref instanceof ilContainerReference)
91  {
92  return $this->ref;
93  }
94  return 0;
95  }
96 
97 
101  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
102  {
103  global $ilErr;
104 
105  switch($a_name)
106  {
107  case "ContainerReference":
108  break;
109 
110  case 'Title':
111  switch($a_attribs['type'])
112  {
115  break;
116 
117  default:
119  break;
120  }
121  break;
122 
123  case 'Target':
124  $this->getReference()->setTargetId($a_attribs['id']);
125  break;
126  }
127  }
128 
129 
135  public function handlerEndTag($a_xml_parser, $a_name)
136  {
137  switch($a_name)
138  {
139  case "ContainerReference":
140  $this->save();
141  break;
142 
143  case 'Title':
144  if($this->getReference()->getTitleType() == ilContainerReference::TITLE_TYPE_CUSTOM)
145  {
146  $this->getReference()->setTitle(trim($this->cdata));
147  }
148  break;
149  }
150  $this->cdata = '';
151  }
152 
153 
157  function handlerCharacterData($a_xml_parser, $a_data)
158  {
159  #$a_data = str_replace("<","&lt;",$a_data);
160  #$a_data = str_replace(">","&gt;",$a_data);
161 
162  if(!empty($a_data))
163  {
164  $this->cdata .= $a_data;
165  }
166  }
167 
172  protected function save()
173  {
177  if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
178  {
179  $this->create();
180  $this->getReference()->create();
181  $this->getReference()->createReference();
182  $this->getReference()->putInTree($this->getParentId());
183  $this->getReference()->setPermissions($this->getParentId());
184  }
185  $this->getReference()->update();
186  return true;
187  }
188 
189 
190 
191 
196  public function setMode($mode)
197  {
198  $this->mode = $mode;
199  }
200 
201 
207  {
208  $this->ref = $ref;
209  }
210 
215  public function getReference()
216  {
217  return $this->ref;
218  }
219 }
220 ?>