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