ILIAS  release_4-4 Revision
ilCategoryXmlParser Class Reference

Group Import Parser. More...

+ Inheritance diagram for ilCategoryXmlParser:
+ Collaboration diagram for ilCategoryXmlParser:

Public Member Functions

 __construct ($a_xml, $a_parent_id)
 Constructor. More...
 
 getParentId ()
 Get parent id. More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private More...
 
 startParsing ()
 start the parser More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 Handler end tag. More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 setMode ($mode)
 Set import mode. More...
 
 setCategory ($cat)
 Set category object. More...
 
 getCategory ()
 
- Public Member Functions inherited from ilSaxParser
 ilSaxParser ($a_xml_file='', $throwException=false)
 Constructor setup ILIAS global object public. More...
 
 setXMLContent ($a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 create parser More...
 
 setOptions ($a_xml_parser)
 set parser options More...
 
 setHandlers ($a_xml_parser)
 set event handler should be overwritten by inherited class private More...
 
 openXMLFile ()
 open xml file More...
 
 parse ($a_xml_parser, $a_fp=null)
 parse xml file More...
 
 freeParser ($a_xml_parser)
 free xml parser handle More...
 
 setThrowException ($throwException)
 set error handling More...
 
- Public Member Functions inherited from PEAR
 PEAR ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). More...
 
getStaticProperty ($class, $var)
 If you have a class that's mostly/entirely static, and you need static properties, you can use this method to simulate them. More...
 
 registerShutdownFunc ($func, $args=array())
 Use this function to register a shutdown method for static classes. More...
 
 isError ($data, $code=null)
 Tell whether a value is a PEAR error. More...
 
 setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. More...
 
 expectError ($code=' *')
 This method is used to tell which errors you expect to get. More...
 
 popExpect ()
 This method pops one element off the expected error codes stack. More...
 
 _checkDelExpect ($error_code)
 This method checks unsets an error code if available. More...
 
 delExpect ($error_code)
 This method deletes all occurences of the specified element from the expected error codes stack. More...
 
raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false)
 This method is a wrapper that returns an instance of the configured error class with this object's default error handling applied. More...
 
throwError ($message=null, $code=null, $userinfo=null)
 Simpler form of raiseError with fewer options. More...
 
 staticPushErrorHandling ($mode, $options=null)
 
 staticPopErrorHandling ()
 
 pushErrorHandling ($mode, $options=null)
 Push a new error handler on top of the error handler options stack. More...
 
 popErrorHandling ()
 Pop the last error handler used. More...
 
 loadExtension ($ext)
 OS independant PHP extension load. More...
 

Data Fields

const MODE_CREATE = 1
 
const MODE_UPDATE = 2
 
- Data Fields inherited from ilSaxParser
 $input_type = null
 
 $xml_content = ''
 
 $ilias
 
 $lng
 
 $xml_file
 
 $throwException = false
 
- Data Fields inherited from PEAR
 $_debug = false
 
 $_default_error_mode = null
 
 $_default_error_options = null
 
 $_default_error_handler = ''
 
 $_error_class = 'PEAR_Error'
 
 $_expected_errors = array()
 

Protected Member Functions

 getCurrentTranslation ()
 Get current translation. More...
 
 save ()
 Save category object. More...
 
- Protected Member Functions inherited from ilSaxParser
 handleError ($message, $code)
 use given error handler to handle error message or internal ilias error message handle More...
 

Private Attributes

 $cat = null
 
 $parent_id = 0
 
 $current_translation = array()
 

Detailed Description

Group Import Parser.

Author
Stefan Meyer meyer.nosp@m.@lei.nosp@m.fos.c.nosp@m.om
Version
$Id$

Definition at line 38 of file class.ilCategoryXmlParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilCategoryXmlParser::__construct (   $a_xml,
  $a_parent_id 
)

Constructor.

Parameters
string$a_xml_filexml file

public

Definition at line 57 of file class.ilCategoryXmlParser.php.

References MODE_CREATE, and ilSaxParser\setXMLContent().

58  {
59  parent::__construct(null);
60 
62  $this->parent_id = $a_parent_id;
63  $this->setXMLContent($a_xml);
64  }
setXMLContent($a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getCategory()

ilCategoryXmlParser::getCategory ( )

Definition at line 261 of file class.ilCategoryXmlParser.php.

References $cat.

Referenced by handlerBeginTag(), handlerEndTag(), and save().

262  {
263  return $this->cat;
264  }
+ Here is the caller graph for this function:

◆ getCurrentTranslation()

ilCategoryXmlParser::getCurrentTranslation ( )
protected

Get current translation.

Definition at line 78 of file class.ilCategoryXmlParser.php.

References $current_translation.

◆ getParentId()

ilCategoryXmlParser::getParentId ( )

Get parent id.

Returns
type

Definition at line 70 of file class.ilCategoryXmlParser.php.

References $parent_id.

Referenced by save().

+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilCategoryXmlParser::handlerBeginTag (   $a_xml_parser,
  $a_name,
  $a_attribs 
)

handler for begin of element

Definition at line 118 of file class.ilCategoryXmlParser.php.

References $ilErr, getCategory(), ilContainer\SORT_MANUAL, and ilContainer\SORT_TITLE.

119  {
120  global $ilErr;
121 
122  switch($a_name)
123  {
124  case "Category":
125  break;
126 
127  case 'Translations':
128  $this->getCategory()->removeTranslations();
129  break;
130 
131  case 'Translation':
132  $this->current_translation = array();
133  $this->current_translation['default'] = $a_attribs['default'] ? 1 : 0;
134  $this->current_translation['lang'] = $a_attribs['language'];
135  break;
136 
137  case 'Sorting':
138  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
139  $sort = new ilContainerSortingSettings($this->getCategory()->getId());
140 
141  switch($a_attribs['type'])
142  {
143  case 'Manual':
144  $sort->setSortMode(ilContainer::SORT_MANUAL);
145  break;
146 
147  default:
148  $sort->setSortMode(ilContainer::SORT_TITLE);
149  break;
150  }
151  $sort->update();
152  break;
153  }
154  }
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilCategoryXmlParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Definition at line 207 of file class.ilCategoryXmlParser.php.

208  {
209  #$a_data = str_replace("<","&lt;",$a_data);
210  #$a_data = str_replace(">","&gt;",$a_data);
211 
212  if(!empty($a_data))
213  {
214  $this->cdata .= $a_data;
215  }
216  }

◆ handlerEndTag()

ilCategoryXmlParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

Handler end tag.

Parameters
type$a_xml_parser
type$a_name

Definition at line 162 of file class.ilCategoryXmlParser.php.

References getCategory(), and save().

163  {
164  switch($a_name)
165  {
166  case "Category":
167  $this->save();
168  break;
169 
170  case 'Title':
171  $this->current_translation['title'] = trim($this->cdata);
172 
173  if($this->current_translation['default'])
174  {
175  $this->getCategory()->setTitle(trim($this->cdata));
176  }
177 
178  break;
179 
180  case 'Description':
181  $this->current_translation['description'] = trim($this->cdata);
182 
183  if($this->current_translation['default'])
184  {
185  $this->getCategory()->setDescription(trim($this->cdata));
186  }
187 
188  break;
189 
190  case 'Translation':
191  // Add translation
192  $this->getCategory()->addTranslation(
193  (string) $this->current_translation['title'],
194  (string) $this->current_translation['description'],
195  (string) $this->current_translation['lang'],
196  (int) $this->current_translation['default']
197  );
198  break;
199  }
200  $this->cdata = '';
201  }
save()
Save category object.
+ Here is the call graph for this function:

◆ save()

ilCategoryXmlParser::save ( )
protected

Save category object.

Returns
type

mode can be create or update

Definition at line 222 of file class.ilCategoryXmlParser.php.

References getCategory(), getParentId(), and MODE_CREATE.

Referenced by handlerEndTag().

223  {
224 
228  if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
229  {
230  $this->create();
231  $this->getCategory()->create();
232  $this->getCategory()->createReference();
233  $this->getCategory()->putInTree($this->getParentId());
234  $this->getCategory()->setPermissions($this->getParentId());
235  }
236  $this->getCategory()->update();
237  return true;
238  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCategory()

ilCategoryXmlParser::setCategory (   $cat)

Set category object.

Parameters
type$cat

Definition at line 256 of file class.ilCategoryXmlParser.php.

References $cat.

257  {
258  $this->cat = $cat;
259  }

◆ setHandlers()

ilCategoryXmlParser::setHandlers (   $a_xml_parser)

set event handler should be overwritten by inherited class private

Definition at line 90 of file class.ilCategoryXmlParser.php.

91  {
92  xml_set_object($a_xml_parser,$this);
93  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
94  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
95  }

◆ setMode()

ilCategoryXmlParser::setMode (   $mode)

Set import mode.

Parameters
type$mode

Definition at line 247 of file class.ilCategoryXmlParser.php.

248  {
249  $this->mode = $mode;
250  }

◆ startParsing()

ilCategoryXmlParser::startParsing ( )

start the parser

Definition at line 100 of file class.ilCategoryXmlParser.php.

References MODE_CREATE.

101  {
102  parent::startParsing();
103 
104  if ($this->mode == ilCategoryXmlParser::MODE_CREATE)
105  {
106  return is_object($this->cat) ? $this->cat->getRefId() : false;
107  }
108  else
109  {
110  return is_object($this->cat) ? $this->cat->update() : false;
111  }
112  }

Field Documentation

◆ $cat

ilCategoryXmlParser::$cat = null
private

Definition at line 43 of file class.ilCategoryXmlParser.php.

Referenced by getCategory(), and setCategory().

◆ $current_translation

ilCategoryXmlParser::$current_translation = array()
private

Definition at line 46 of file class.ilCategoryXmlParser.php.

Referenced by getCurrentTranslation().

◆ $parent_id

ilCategoryXmlParser::$parent_id = 0
private

Definition at line 44 of file class.ilCategoryXmlParser.php.

Referenced by getParentId().

◆ MODE_CREATE

const ilCategoryXmlParser::MODE_CREATE = 1

◆ MODE_UPDATE

const ilCategoryXmlParser::MODE_UPDATE = 2

The documentation for this class was generated from the following file: