ILIAS  release_8 Revision v8.23
class.ilMDXMLCopier.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 /******************************************************************************
5  *
6  * This file is part of ILIAS, a powerful learning management system.
7  *
8  * ILIAS is licensed with the GPL-3.0, you should have received a copy
9  * of said license along with the source code.
10  *
11  * If this is not the case or you just want to try ILIAS, you'll find
12  * us at:
13  * https://www.ilias.de
14  * https://github.com/ILIAS-eLearning
15  *
16  *****************************************************************************/
17 
26 {
27  private array $filter = [];
28  protected bool $in_meta_data = false;
29 
30  public function __construct($content, $a_rbac_id, $a_obj_id, $a_obj_type)
31  {
32  $this->setMDObject(new ilMD($a_rbac_id, $a_obj_id, $a_obj_type));
33 
35  $this->setXMLContent($content);
36 
37  // set filter of tags which are handled in this class
38  $this->__setFilter();
39  }
40 
41  public function startParsing(): void
42  {
43  // delete existing entries from creations process
44  $clone_md = $this->getMDObject();
45  $clone_md->deleteAll();
46 
47  // rewrite autogenerated entry
48  $identifier = new ilMDIdentifier(
49  $clone_md->getRBACId(),
50  $clone_md->getObjId(),
51  $clone_md->getObjType(),
52  );
53  $identifier->setEntry('il__' . $clone_md->getObjType() . '_' . $clone_md->getObjId());
54  $identifier->update();
55 
56  parent::startParsing();
57  }
58 
62  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
63  {
64  if ($this->in_meta_data && !$this->__inFilter($a_name)) {
65  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
66  return;
67  }
68 
69  switch ($a_name) {
70  case 'MetaData':
71  $this->in_meta_data = true;
72  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
73  break;
74 
75  case 'Identifier':
76  $par = $this->__getParent();
77  $this->md_ide = $par->addIdentifier();
78  $this->md_ide->setCatalog($a_attribs['Catalog'] ?? '');
79  $this->md_ide->setEntry('il__' . $this->md->getObjType() . '_' . $this->md->getObjId());
80  $this->md_ide->save();
81  $this->__pushParent($this->md_ide);
82  break;
83  }
84  }
85 
89  public function handlerEndTag($a_xml_parser, string $a_name): void
90  {
91  if ($this->in_meta_data && !$this->__inFilter($a_name)) {
92  parent::handlerEndTag($a_xml_parser, $a_name);
93  return;
94  }
95  switch ($a_name) {
96  case 'Identifier':
97  $par = $this->__getParent();
98  $par->update();
99  $this->__popParent();
100  break;
101 
102  case 'MetaData':
103  $this->in_meta_data = false;
104  parent::handlerEndTag($a_xml_parser, $a_name);
105  break;
106  }
107  }
108 
112  public function handlerCharacterData($a_xml_parser, string $a_data): void
113  {
114  if ($this->in_meta_data) {
115  parent::handlerCharacterData($a_xml_parser, $a_data);
116  }
117  }
118 
119  public function __setFilter(): void
120  {
121  $this->filter[] = 'Identifier';
122  }
123 
124  public function __inFilter(string $a_tag_name): bool
125  {
126  return in_array($a_tag_name, $this->filter, true);
127  }
128 }
handlerEndTag($a_xml_parser, string $a_name)
setEntry(string $a_entry)
handlerCharacterData($a_xml_parser, string $a_data)
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
__pushParent(object $md_obj)
__inFilter(string $a_tag_name)
__construct($content, $a_rbac_id, $a_obj_id, $a_obj_type)
__construct(Container $dic, ilPlugin $plugin)
setXMLContent(string $a_xml_content)