ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
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 
27 {
28  private array $filter = [];
29  protected bool $in_meta_data = false;
30 
31  public function __construct($content, $a_rbac_id, $a_obj_id, $a_obj_type)
32  {
33  $this->setMDObject(new ilMD($a_rbac_id, $a_obj_id, $a_obj_type));
34 
36  $this->setXMLContent($content);
37 
38  // set filter of tags which are handled in this class
39  $this->__setFilter();
40  }
41 
42  public function startParsing(): void
43  {
44  // delete existing entries from creations process
45  $clone_md = $this->getMDObject();
46  $clone_md->deleteAll();
47 
48  // rewrite autogenerated entry
49  $identifier = new ilMDIdentifier(
50  $clone_md->getRBACId(),
51  $clone_md->getObjId(),
52  $clone_md->getObjType(),
53  );
54  $identifier->setEntry('il__' . $clone_md->getObjType() . '_' . $clone_md->getObjId());
55  $identifier->update();
56 
57  parent::startParsing();
58  }
59 
63  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs): void
64  {
65  if ($this->in_meta_data && !$this->__inFilter($a_name)) {
66  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
67  return;
68  }
69 
70  switch ($a_name) {
71  case 'MetaData':
72  $this->in_meta_data = true;
73  parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
74  break;
75 
76  case 'Identifier':
77  $par = $this->__getParent();
78  $this->md_ide = $par->addIdentifier();
79  $this->md_ide->setCatalog($a_attribs['Catalog'] ?? '');
80  $this->md_ide->setEntry('il__' . $this->md->getObjType() . '_' . $this->md->getObjId());
81  $this->md_ide->save();
82  $this->__pushParent($this->md_ide);
83  break;
84  }
85  }
86 
90  public function handlerEndTag($a_xml_parser, string $a_name): void
91  {
92  if ($this->in_meta_data && !$this->__inFilter($a_name)) {
93  parent::handlerEndTag($a_xml_parser, $a_name);
94  return;
95  }
96  switch ($a_name) {
97  case 'Identifier':
98  $par = $this->__getParent();
99  $par->update();
100  $this->__popParent();
101  break;
102 
103  case 'MetaData':
104  $this->in_meta_data = false;
105  parent::handlerEndTag($a_xml_parser, $a_name);
106  break;
107  }
108  }
109 
113  public function handlerCharacterData($a_xml_parser, string $a_data): void
114  {
115  if ($this->in_meta_data) {
116  parent::handlerCharacterData($a_xml_parser, $a_data);
117  }
118  }
119 
120  public function __setFilter(): void
121  {
122  $this->filter[] = 'Identifier';
123  }
124 
125  public function __inFilter(string $a_tag_name): bool
126  {
127  return in_array($a_tag_name, $this->filter, true);
128  }
129 }
handlerEndTag($a_xml_parser, string $a_name)
setEntry(string $a_entry)
__construct(VocabulariesInterface $vocabularies)
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)
filter(string $filter_id, $class_path, string $cmd, bool $activated=true, bool $expanded=true)
setXMLContent(string $a_xml_content)