ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilWebLinkXmlParser Class Reference

XML parser for weblink xml. More...

+ Inheritance diagram for ilWebLinkXmlParser:
+ Collaboration diagram for ilWebLinkXmlParser:

Public Member Functions

 __construct ($webr, $xml)
 Constructor. More...
 
 setWebLink (ilObject $webl)
 set weblink More...
 
 getWebLink ()
 Get weblink object. More...
 
 setMode ($a_mode)
 Set parsing mode. More...
 
 getMode ()
 Return parsing mode. More...
 
 start ()
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
- Public Member Functions inherited from ilMDSaxParser
 __construct ($a_xml_file='')
 Constructor. More...
 
 enableMDParsing ($a_status)
 
 getMDParsingStatus ()
 
 setMDObject (&$md)
 
getMDObject ()
 
 inMetaData ()
 
 setHandlers ($a_xml_parser)
 set event handlers More...
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 __getCharacterData ()
 
 __pushParent (&$md_obj)
 
__popParent ()
 
__getParent ()
 
 __construct ($a_xml_file='')
 Constructor. More...
 
 setMDObject (&$md)
 
 inMetaData ()
 
 handlerBeginTag ($a_xml_parser, $a_name, $a_attribs)
 handler for begin of element More...
 
 handlerEndTag ($a_xml_parser, $a_name)
 handler for end of element More...
 
 handlerCharacterData ($a_xml_parser, $a_data)
 handler for character data More...
 
 __getCharacterData ()
 
 __pushParent (&$md_obj)
 
__popParent ()
 
__getParent ()
 
- Public Member Functions inherited from ilSaxParser
 __construct ($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
 __construct ($error_class=null)
 Constructor. More...
 
 _PEAR ()
 Destructor (the emulated type of...). 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...
 
 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_UNDEFINED = 0
 
const MODE_UPDATE = 1
 
const MODE_CREATE = 2
 
- Data Fields inherited from ilMDSaxParser
 $md_in_md = false
 
 $md_chr_data = ''
 
 $md_cur_el = null
 
 $md_parsing_enabled = null
 
 $md = null
 
 $md_gen
 
- 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()
 

Private Attributes

 $webl
 
 $mode = self::MODE_UNDEFINED
 
 $in_metadata = false
 
 $sorting_positions = array()
 
 $current_sorting_position = 0
 

Additional Inherited Members

- Static Public Member Functions inherited from PEAR
static & 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...
 
static setErrorHandling ($mode=null, $options=null)
 Sets how errors generated by this object should be handled. 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...
 
- Protected Attributes inherited from ilMDSaxParser
 $meta_log
 

Detailed Description

XML parser for weblink xml.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 20 of file class.ilWebLinkXmlParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilWebLinkXmlParser::__construct (   $webr,
  $xml 
)

Constructor.

Definition at line 37 of file class.ilWebLinkXmlParser.php.

References getWebLink(), ilMDSaxParser\setMDObject(), ilSaxParser\setThrowException(), setWebLink(), and ilSaxParser\setXMLContent().

38  {
39  parent::__construct();
40  $this->setXMLContent($xml);
41  $this->setWebLink($webr);
42 
43  $this->setMDObject(new ilMD($this->getWebLink()->getId(),$this->getWebLink()->getId(),'webr'));
44  $this->setThrowException(true);
45  }
setThrowException($throwException)
set error handling
getWebLink()
Get weblink object.
setWebLink(ilObject $webl)
set weblink
setXMLContent($a_xml_content)
+ Here is the call graph for this function:

Member Function Documentation

◆ getMode()

ilWebLinkXmlParser::getMode ( )

Return parsing mode.

Returns

Definition at line 80 of file class.ilWebLinkXmlParser.php.

References $mode.

Referenced by handlerBeginTag().

81  {
82  return $this->mode;
83  }
+ Here is the caller graph for this function:

◆ getWebLink()

ilWebLinkXmlParser::getWebLink ( )

Get weblink object.

Returns
ilObject

Definition at line 61 of file class.ilWebLinkXmlParser.php.

References $webl.

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

62  {
63  return $this->webl;
64  }
+ Here is the caller graph for this function:

◆ handlerBeginTag()

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

handler for begin of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
array$a_attribselement attributes array

Definition at line 117 of file class.ilWebLinkXmlParser.php.

References $ilErr, ilMDSaxParser\$md, $valid, array, getMode(), ilParameterAppender\getParameterIds(), getWebLink(), LINKS_LOGIN, LINKS_MATRICULATION, LINKS_USER_ID, ilContainer\SORT_MANUAL, and ilContainer\SORT_TITLE.

118  {
119  global $ilErr;
120 
121  if($this->in_metadata)
122  {
123  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
124  return;
125  }
126 
127  switch($a_name)
128  {
129  case "MetaData":
130  $this->in_metadata = true;
131 
132  // Delete old meta data
133  $md = new ilMD($this->getWebLink()->getId(),0,'webr');
134  $md->deleteAll();
135 
136  parent::handlerBeginTag($a_xml_parser,$a_name,$a_attribs);
137  break;
138 
139  case 'WebLink':
140 
141  $this->current_sorting_position = ($a_attribs['position'] ? $a_attribs['position'] : 0);
142  $this->current_link_update = false;
143  $this->current_link_delete = false;
144  $this->current_parameters = array();
145 
146  if($this->getMode() == self::MODE_CREATE or (isset($a_attribs['action']) and $a_attribs['action'] == 'Create'))
147  {
148  // New weblink
149  $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
150  }
151  elseif($this->getMode() == self::MODE_UPDATE and $a_attribs['action'] == 'Delete')
152  {
153  $this->current_link_delete = true;
154  $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
155  $this->current_link->delete($a_attribs['id']);
156  break;
157  }
158  elseif($this->getMode() == self::MODE_UPDATE and ($a_attribs['action'] == 'Update' or !isset($a_attribs['action'])))
159  {
160  $this->current_link = new ilLinkResourceItems($this->getWebLink()->getId());
161  $this->current_link->readItem($a_attribs['id']);
162  $this->current_link_update = true;
163 
164  // Delete all dynamic parameter
165  include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
166  foreach(ilParameterAppender::getParameterIds($this->getWebLink()->getId(), $a_attribs['id']) as $param_id)
167  {
168  $param = new ilParameterAppender($this->getWebLink()->getId());
169  $param->delete($param_id);
170  }
171  }
172  else
173  {
174  throw new ilWebLinkXmlParserException('Invalid action given for element "Weblink"');
175  }
176 
177  // Active
178  $this->current_link->setActiveStatus($a_attribs['active'] ? 1 : 0);
179 
180  // Valid
181  if(!isset($a_attribs['valid']))
182  {
183  $valid = 1;
184  }
185  else
186  {
187  $valid = $a_attribs['valid'] ? 1 : 0;
188  }
189  $this->current_link->setValidStatus($valid);
190 
191  // Disable check
192  $this->current_link->setDisableCheckStatus($a_attribs['disableValidation'] ? 1 : 0);
193 
194  // internal
195  if(isset($a_attribs['internal']))
196  {
197  $this->current_link->setInternal($a_attribs['internal']);
198  }
199  break;
200 
201 
202  case 'Sorting':
203 
204  include_once './Services/Container/classes/class.ilContainerSortingSettings.php';
205  $sort = new ilContainerSortingSettings($this->getWebLink()->getId());
206  $sort->delete();
207 
208  switch($a_attribs['type'])
209  {
210  case 'Manual':
211  $sort->setSortMode(ilContainer::SORT_MANUAL);
212  break;
213 
214  case 'Title':
215  default:
216  $sort->setSortMode(ilContainer::SORT_TITLE);
217  }
218  $sort->save();
219  break;
220 
221  case 'WebLinks':
222  $this->sorting_positions = array();
223  case 'Title':
224  case 'Description':
225  case 'Target':
226  // Nothing to do
227  break;
228 
229  case 'DynamicParameter':
230 
231  $param = new ilParameterAppender($this->getWebLink()->getId());
232  $param->setName($a_attribs['name']);
233 
234  switch($a_attribs['type'])
235  {
236  case 'userName':
237 # $GLOBALS['ilLog']->write("VALUE: ".LINKS_LOGIN);
238  $param->setValue(LINKS_LOGIN);
239  break;
240 
241  case 'userId':
242 # $GLOBALS['ilLog']->write("VALUE: ".LINKS_USER_ID);
243  $param->setValue(LINKS_USER_ID);
244  break;
245 
246  case 'matriculation':
247 # $GLOBALS['ilLog']->write("VALUE: ".LINKS_MATRICULATION);
248  $param->setValue(LINKS_MATRICULATION);
249  break;
250 
251  default:
252  throw new ilWebLinkXmlParserException('Invalid attribute "type" given for element "Dynamic parameter". Aborting');
253  break;
254  }
255 
256  $this->current_parameters[] = $param;
257  break;
258  }
259  }
global $ilErr
Definition: raiseError.php:16
static getParameterIds($a_webr_id, $a_link_id)
Get Parameter ids of link.
$valid
const LINKS_MATRICULATION
const LINKS_LOGIN
getMode()
Return parsing mode.
getWebLink()
Get weblink object.
Create styles array
The data for the language used.
Class ilObjLinkResourceGUI.
Class ilParameterAppender.
const LINKS_USER_ID
+ Here is the call graph for this function:

◆ handlerCharacterData()

ilWebLinkXmlParser::handlerCharacterData (   $a_xml_parser,
  $a_data 
)

handler for character data

Parameters
resource$a_xml_parserxml parser
string$a_datacharacter data

Definition at line 367 of file class.ilWebLinkXmlParser.php.

368  {
369  if($this->in_metadata)
370  {
371  parent::handlerCharacterData($a_xml_parser,$a_data);
372  }
373 
374  if($a_data != "\n")
375  {
376  // Replace multiple tabs with one space
377  $a_data = preg_replace("/\t+/"," ",$a_data);
378  $this->cdata .= $a_data;
379  }
380  }

◆ handlerEndTag()

ilWebLinkXmlParser::handlerEndTag (   $a_xml_parser,
  $a_name 
)

handler for end of element

Parameters
resource$a_xml_parserxml parser
string$a_nameelement name
Exceptions
ilSaxParserExceptionif invalid xml structure is given
ilWebLinkXMLParserExceptionmissing elements

Definition at line 269 of file class.ilWebLinkXmlParser.php.

References $GLOBALS, ilContainerSorting\_getInstance(), ilLoggerFactory\getLogger(), and getWebLink().

270  {
271  if($this->in_metadata)
272  {
273  parent::handlerEndTag($a_xml_parser,$a_name);
274  }
275 
276  $GLOBALS['ilLog']->write(__METHOD__.': Called '.$a_name);
277 
278  switch($a_name)
279  {
280  case 'MetaData':
281  $this->in_metadata = false;
282  parent::handlerEndTag($a_xml_parser,$a_name);
283  break;
284 
285  case 'WebLinks':
286  $this->getWebLink()->MDUpdateListener('General');
287  $this->getWebLink()->update();
288 
289  // save sorting
290  include_once './Services/Container/classes/class.ilContainerSorting.php';
291  $sorting = ilContainerSorting::_getInstance($this->getWebLink()->getId());
292  $sorting->savePost($this->sorting_positions);
293  ilLoggerFactory::getLogger('webr')->dump($this->sorting_positions);
294  break;
295 
296  case 'WebLink':
297 
298  if($this->current_link_delete)
299  {
300  break;
301  }
302  if(!$this->current_link)
303  {
304  throw new ilSaxParserException('Invalid xml structure given. Missing start tag "WebLink"');
305  }
306  if(!$this->current_link->validate())
307  {
308  throw new ilWebLinkXmlParserException('Missing required elements "Title, Target"');
309  }
310 
311  if($this->current_link_update)
312  {
313  $this->current_link->update();
314  }
315  else
316  {
317  $this->current_link->add();
318  }
319 
320  // Save dynamic parameters
321  foreach($this->current_parameters as $param)
322  {
323  $param->add($this->current_link->getLinkId());
324  }
325 
326 
327  // store positions
328  $this->sorting_positions[$this->current_link->getLinkId()] = (int) $this->current_sorting_position;
329 
330  unset($this->current_link);
331  break;
332 
333  case 'Title':
334  if($this->current_link)
335  {
336  $this->current_link->setTitle(trim($this->cdata));
337  }
338  break;
339 
340  case 'Description':
341  if($this->current_link)
342  {
343  $this->current_link->setDescription(trim($this->cdata));
344  }
345  break;
346 
347  case 'Target':
348  if($this->current_link)
349  {
350  $this->current_link->setTarget(trim($this->cdata));
351  }
352  break;
353  }
354 
355  // Reset cdata
356  $this->cdata = '';
357  }
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
SaxParserException thrown by ilSaxParser if property throwException is set.
getWebLink()
Get weblink object.
static getLogger($a_component_id)
Get component logger.
static _getInstance($a_obj_id)
get instance by obj_id
+ Here is the call graph for this function:

◆ setHandlers()

ilWebLinkXmlParser::setHandlers (   $a_xml_parser)

set event handlers

Parameters
resourcereference to the xml parser private

Definition at line 103 of file class.ilWebLinkXmlParser.php.

104  {
105  xml_set_object($a_xml_parser,$this);
106  xml_set_element_handler($a_xml_parser,'handlerBeginTag','handlerEndTag');
107  xml_set_character_data_handler($a_xml_parser,'handlerCharacterData');
108  }

◆ setMode()

ilWebLinkXmlParser::setMode (   $a_mode)

Set parsing mode.

Parameters
int$a_mode
Returns

Definition at line 71 of file class.ilWebLinkXmlParser.php.

72  {
73  $this->mode = $a_mode;
74  }

◆ setWebLink()

ilWebLinkXmlParser::setWebLink ( ilObject  $webl)

set weblink

Parameters
ilObject$webl
Returns

Definition at line 52 of file class.ilWebLinkXmlParser.php.

References $webl.

Referenced by __construct().

53  {
54  $this->webl = $webl;
55  }
+ Here is the caller graph for this function:

◆ start()

ilWebLinkXmlParser::start ( )
Returns
Exceptions
ilSaxParserExceptionif invalid xml structure is given
ilWebLinkXMLParserExceptionmissing elements

Definition at line 92 of file class.ilWebLinkXmlParser.php.

References ilSaxParser\startParsing().

93  {
94  return $this->startParsing();
95  }
startParsing()
stores xml data in array
+ Here is the call graph for this function:

Field Documentation

◆ $current_sorting_position

ilWebLinkXmlParser::$current_sorting_position = 0
private

Definition at line 32 of file class.ilWebLinkXmlParser.php.

◆ $in_metadata

ilWebLinkXmlParser::$in_metadata = false
private

Definition at line 29 of file class.ilWebLinkXmlParser.php.

◆ $mode

ilWebLinkXmlParser::$mode = self::MODE_UNDEFINED
private

Definition at line 27 of file class.ilWebLinkXmlParser.php.

Referenced by getMode().

◆ $sorting_positions

ilWebLinkXmlParser::$sorting_positions = array()
private

Definition at line 31 of file class.ilWebLinkXmlParser.php.

◆ $webl

ilWebLinkXmlParser::$webl
private

Definition at line 26 of file class.ilWebLinkXmlParser.php.

Referenced by getWebLink(), and setWebLink().

◆ MODE_CREATE

const ilWebLinkXmlParser::MODE_CREATE = 2

◆ MODE_UNDEFINED

const ilWebLinkXmlParser::MODE_UNDEFINED = 0

Definition at line 22 of file class.ilWebLinkXmlParser.php.

◆ MODE_UPDATE

const ilWebLinkXmlParser::MODE_UPDATE = 1

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