ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilCopyWizardSettingsXMLParser.php
Go to the documentation of this file.
1 <?php
2 /*
3  * Created on 26.02.2008
4  *
5  * To change the template for this generated file go to
6  * Window - Preferences - PHPeclipse - PHP - Code Templates
7  */
8 
9 include_once "./Services/Xml/classes/class.ilSaxParser.php";
10 include_once "./Services/Xml/exceptions/class.ilSaxParserException.php";
11 include_once "./Services/CopyWizard/classes/class.ilCopyWizardOptions.php";
12 
14 {
15  private $options;
16  private $source_id;
17  private $target_id;
18  private $default_action;
19 
27  public function __construct($xml)
28  {
29  parent::__construct('', true);
30  $this->setXMLContent($xml);
31  }
32 
39  public function setHandlers($a_xml_parser)
40  {
41  xml_set_object($a_xml_parser, $this);
42  xml_set_element_handler($a_xml_parser, 'handlerBeginTag', 'handlerEndTag');
43  xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
44  }
45 
53  public function handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
54  {
55  global $DIC;
56 
57  $objDefinition = $DIC['objDefinition'];
58  $ilAccess = $DIC['ilAccess'];
59  $tree = $DIC['tree'];
60 
61  switch ($a_name) {
62  case 'Settings':
63  $this->options = array();
64  $this->source_id = (int) $a_attribs["source_id"];
65  if (ilObject::_isInTrash($this->source_id)) {
66  throw new ilSaxParserException("Source id " . $this->source_id . " is in trash");
67  }
68  $this->target_id = (int) $a_attribs["target_id"];
69  if (ilObject::_isInTrash($this->target_id)) {
70  throw new ilSaxParserException("target id" . $this->target_id . " is in trash");
71  }
72 
73  $this->default_action = ilCopyWizardSettingsXMLParser::getActionForString($a_attribs["default_action"]);
74  break;
75  case 'Option':
76  $id = (int) $a_attribs["id"];
78  throw new ilSaxParserException("Id $id is in trash");
79  }
80  if (!$tree->isInTree($id)) {
81  throw new ilSaxParserException("Id $id does not exist");
82  }
83 
86 
87 
88  switch ($action) {
90  $perm_copy = $ilAccess->checkAccess('copy', '', $id);
91  $copy = $objDefinition->allowCopy($type);
92 
93  if ($perm_copy && $copy) {
94  $this->options [$id] = array("type" => $action);
95  } elseif ($copy && !$perm_copy) {
96  throw new ilSaxParserException("Missing copy permission for object " . $id);
97  } elseif (!$copy) {
98  throw new ilSaxParserException("Copy for object " . $id . " of type " . $type . " is not supported");
99  }
100  break;
102  $perm_link = $ilAccess->checkAccess('write', '', $id);
103  $link = $objDefinition->allowLink($type);
104 
105  if ($perm_link && $link) {
106  $this->options [$id] = array("type" => $action);
107  } elseif ($copy && !$perm_link) {
108  throw new ilSaxParserException("Missing write permission for object " . $id);
109  } elseif (!$link) {
110  throw new ilSaxParserException("Link for object " . $id . " of type " . $type . " is not supported");
111  }
112  break;
113  }
114  }
115  }
116 
117 
123  public function getOptions()
124  {
125  return is_array($this->options) ? $this->options : array();
126  }
127 
133  public function getSourceId()
134  {
135  return $this->source_id;
136  }
137 
143  public function getTargetId()
144  {
145  return $this->target_id;
146  }
147 
148  private static function getActionForString($s)
149  {
150  if ($s == "COPY") {
152  }
153  if ($s == "LINK") {
155  }
157  }
158 
159  public function handlerEndTag($a_xml_parser, $a_name)
160  {
161  }
162 
169  public function handlerCharacterData($a_xml_parser, $a_data)
170  {
171  }
172 }
handlerBeginTag($a_xml_parser, $a_name, $a_attribs)
handler for begin of element
$action
$type
global $DIC
Definition: saml.php:7
if(!array_key_exists('StateId', $_REQUEST)) $id
static _isInTrash($a_ref_id)
checks wether object is in trash
SaxParserException thrown by ilSaxParser if property throwException is set.
$s
Definition: pwgen.php:45
Base class for sax-based expat parsing extended classes need to overwrite the method setHandlers and ...
static getTypeByRefId($a_ref_id, $stop_on_error=true)
get object type by reference id
setHandlers($a_xml_parser)
set event handlers
handlerCharacterData($a_xml_parser, $a_data)
handler for character data
setXMLContent($a_xml_content)