ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilCopyWizardSettingsXMLParser.php
Go to the documentation of this file.
1 <?php
2 
3 /******************************************************************************
4  * This file is part of ILIAS, a powerful learning management system.
5  * ILIAS is licensed with the GPL-3.0, you should have received a copy
6  * of said license along with the source code.
7  * If this is not the case or you just want to try ILIAS, you'll find
8  * us at:
9  * https://www.ilias.de
10  * https://github.com/ILIAS-eLearning
11  *****************************************************************************/
13 {
14  private array $options = [];
15  private int $source_id = 0;
16  private int $target_id = 0;
17 
18  public function __construct(string $xml)
19  {
20  parent::__construct('', true);
21  $this->setXMLContent($xml);
22  }
23 
28  public function setHandlers($a_xml_parser) : void
29  {
30  xml_set_object($a_xml_parser, $this);
31  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
32  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
33  }
34 
38  public function handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs) : void
39  {
40  global $DIC;
41 
42  $objDefinition = $DIC['objDefinition'];
43  $ilAccess = $DIC['ilAccess'];
44  $tree = $DIC['tree'];
45 
46  switch ($a_name) {
47  case 'Settings':
48  $this->options = array();
49  $this->source_id = (int) $a_attribs["source_id"];
50  if (ilObject::_isInTrash($this->source_id)) {
51  throw new ilSaxParserException("Source id " . $this->source_id . " is in trash");
52  }
53  $this->target_id = (int) $a_attribs["target_id"];
54  if (ilObject::_isInTrash($this->target_id)) {
55  throw new ilSaxParserException("target id" . $this->target_id . " is in trash");
56  }
57  break;
58  case 'Option':
59  $id = (int) $a_attribs["id"];
61  throw new ilSaxParserException("Id $id is in trash");
62  }
63  if (!$tree->isInTree($id)) {
64  throw new ilSaxParserException("Id $id does not exist");
65  }
66 
67  $action = self::getActionForString($a_attribs["action"]);
69 
70  switch ($action) {
72  $perm_copy = $ilAccess->checkAccess('copy', '', $id);
73  $copy = $objDefinition->allowCopy($type);
74 
75  if ($perm_copy && $copy) {
76  $this->options [$id] = array("type" => $action);
77  } elseif ($copy && !$perm_copy) {
78  throw new ilSaxParserException("Missing copy permission for object " . $id);
79  } elseif (!$copy) {
80  throw new ilSaxParserException("Copy for object " . $id . " of type " . $type . " is not supported");
81  }
82  break;
84  $perm_link = $ilAccess->checkAccess('write', '', $id);
85  $link = $objDefinition->allowLink($type);
86 
87  if ($perm_link && $link) {
88  $this->options [$id] = array("type" => $action);
89  } elseif ($link && !$perm_link) {
90  throw new ilSaxParserException("Missing write permission for object " . $id);
91  } elseif (!$link) {
92  throw new ilSaxParserException("Link for object " . $id . " of type " . $type . " is not supported");
93  }
94  break;
95  }
96  }
97  }
98 
99  public function getOptions() : array
100  {
101  return $this->options;
102  }
103 
104  public function getSourceId() : ?int
105  {
106  return $this->source_id;
107  }
108 
109  public function getTargetId() : ?int
110  {
111  return $this->target_id;
112  }
113 
114  private static function getActionForString($s) : int
115  {
116  if ($s === "COPY") {
118  }
119 
120  if ($s === "LINK") {
122  }
123 
125  }
126 
130  public function handlerEndTag($a_xml_parser, string $a_name) : void
131  {
132  }
133 
137  public function handlerCharacterData($a_xml_parser, string $a_data) : void
138  {
139  }
140 }
handlerBeginTag($a_xml_parser, string $a_name, array $a_attribs)
handlerCharacterData($a_xml_parser, string $a_data)
$type
SaxParserException thrown by ilSaxParser if property throwException is set.
static getTypeByRefId(int $ref_id, bool $stop_on_error=true)
get object type by reference id
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
static _isInTrash(int $ref_id)
$xml
Definition: metadata.php:351
__construct(Container $dic, ilPlugin $plugin)
$id
plugin.php for ilComponentBuildPluginInfoObjectiveTest::testAddPlugins
Definition: plugin.php:23
setXMLContent(string $a_xml_content)