ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilFolderXmlParser.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /******************************************************************************
6  *
7  * This file is part of ILIAS, a powerful learning management system.
8  *
9  * ILIAS is licensed with the GPL-3.0, you should have received a copy
10  * of said license along with the source code.
11  *
12  * If this is not the case or you just want to try ILIAS, you'll find
13  * us at:
14  * https://www.ilias.de
15  * https://github.com/ILIAS-eLearning
16  *
17  *****************************************************************************/
24 {
26  private ilObject $folder;
27  protected string $cdata = "";
28 
29  public function __construct(ilObject $folder, string $xml)
30  {
31  global $DIC;
32 
33  $this->error = $DIC["ilErr"];
35  $this->setXMLContent($xml);
36  $this->setFolder($folder);
37  $this->setThrowException(true);
38  }
39 
40  public function setFolder(ilObject $folder): void
41  {
42  $this->folder = $folder;
43  }
44 
45  public function getFolder(): ilObject
46  {
47  return $this->folder;
48  }
49 
53  public function start(): void
54  {
55  $this->startParsing();
56  }
57 
58  public function setHandlers($a_xml_parser): void
59  {
60  xml_set_object($a_xml_parser, $this);
61  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
62  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
63  }
64 
71  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
72  {
73  switch ($a_name) {
74  case 'Folder':
75  case 'Title':
76  case 'Description':
77  break;
78 
79  case 'Sorting':
80  case 'Sort':
82  break;
83  }
84  }
85 
91  public function handlerEndTag($a_xml_parser, string $a_name): void
92  {
93  $GLOBALS['ilLog']->write(__METHOD__ . ': Called ' . $a_name);
94 
95  switch ($a_name) {
96  case 'Folder':
97  $this->getFolder()->update();
98  break;
99 
100  case 'Title':
101  $this->getFolder()->setTitle($this->trimAndStrip((string) $this->cdata));
102  break;
103 
104  case 'Description':
105  $this->getFolder()->setDescription($this->trimAndStrip((string) $this->cdata));
106  break;
107  }
108 
109  // Reset cdata
110  $this->cdata = '';
111  }
112 
118  public function handlerCharacterData($a_xml_parser, string $a_data): void
119  {
120  if ($a_data !== "\n") {
121  // Replace multiple tabs with one space
122  $a_data = preg_replace("/\t+/", " ", $a_data);
123  $this->cdata .= $a_data;
124  }
125  }
126 }
setThrowException(bool $throw_exception)
startParsing()
stores xml data in array
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
static _importContainerSortingSettings(array $attibs, int $obj_id)
sorting import for all container objects
global $DIC
Definition: feed.php:28
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(VocabulariesInterface $vocabularies)
$GLOBALS["DIC"]
Definition: wac.php:31
handlerCharacterData($a_xml_parser, string $a_data)
__construct(ilObject $folder, string $xml)
XML parser for folder xml.
setFolder(ilObject $folder)
Error Handling & global info handling.
handlerEndTag($a_xml_parser, string $a_name)
setXMLContent(string $a_xml_content)