ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilExportFileParser.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  *****************************************************************************/
23 {
24  private string $entity = '';
25  private string $install_id = '';
26  private string $install_url = '';
27  private string $schema_version = '';
28  // currently not used.
29  private array $expfiles = [];
30  private string $current_id = '';
31  protected string $item_xml = "";
32  protected bool $in_export_item = false;
33  protected string $chr_data = "";
34 
35  private object $callback_obj;
36  private string $callback_func;
38 
43  public function __construct(string $a_file, object $a_callback_obj, string $a_callback_func)
44  {
45  $this->callback_obj = $a_callback_obj;
46  $this->callback_func = $a_callback_func;
47 
48  parent::__construct($a_file, true);
49  $this->startParsing();
50  }
51 
55  public function setHandlers($a_xml_parser): void
56  {
57  xml_set_object($a_xml_parser, $this);
58  xml_set_element_handler($a_xml_parser, 'handleBeginTag', 'handleEndTag');
59  xml_set_character_data_handler($a_xml_parser, 'handleCharacterData');
60  }
61 
65  public function startParsing(): void
66  {
67  parent::startParsing();
68  }
69 
70  public function handleBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
71  {
72  if ($this->in_export_item) {
73  $this->export_item_writer->xmlStartTag($a_name, $a_attribs);
74  }
75 
76  switch ($a_name) {
77  case "exp:Export":
78  $this->entity = $a_attribs["Entity"];
79  $this->install_id = $a_attribs["InstallationId"];
80  $this->install_url = $a_attribs["InstallationUrl"];
81  $this->schema_version = $a_attribs["SchemaVersion"];
82  break;
83 
84  case "exp:ExportItem":
85  $this->in_export_item = true;
86  $this->current_id = $a_attribs["Id"];
87  $this->export_item_writer = new ilXmlWriter();
88  $this->item_xml = "";
89  $this->expfiles[] = array(
90  "component" => $a_attribs["Component"] ?? null,
91  "path" => $a_attribs["Path"] ?? null
92  );
93  break;
94  }
95  }
96 
97  public function handleEndTag($a_xml_parser, string $a_name): void
98  {
99  switch ($a_name) {
100  case "exp:ExportItem":
101  $this->in_export_item = false;
102  $cf = $this->callback_func;
103  $this->callback_obj->$cf(
104  $this->entity,
105  $this->schema_version,
106  $this->current_id,
107  $this->export_item_writer->xmlDumpMem(false),
110  );
111  break;
112 
113  }
114 
115  if ($this->in_export_item) {
116  $this->export_item_writer->xmlEndTag($a_name);
117  }
118 
119  $this->chr_data = "";
120  }
121 
125  public function handleCharacterData($a_xml_parser, string $a_data): void
126  {
127  $this->chr_data .= $a_data;
128  if ($this->in_export_item) {
129  $this->export_item_writer->xmlData($a_data);
130  }
131  }
132 }
handleCharacterData($a_xml_parser, string $a_data)
End Tag.
handleBeginTag($a_xml_parser, string $a_name, array $a_attribs)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(string $a_file, object $a_callback_obj, string $a_callback_func)
ilExportFileParser constructor.
handleEndTag($a_xml_parser, string $a_name)
__construct(Container $dic, ilPlugin $plugin)