19 declare(strict_types=1);
35 private int $mode = self::MODE_UNDEFINED;
81 parent::startParsing();
85 $identifier_ids = $general->getIdentifierIds();
86 if (!isset($identifier_ids[0])) {
89 $identifier = $general->getIdentifier($identifier_ids[0]);
90 $identifier->setEntry(
93 $identifier->update();
108 $this->mode = $a_mode;
118 $this->current_item_create =
false;
119 $this->current_item_update =
false;
120 $this->current_item_delete =
false;
122 $this->current_link_id = null;
123 $this->current_title = null;
124 $this->current_target = null;
125 $this->current_active = null;
126 $this->current_parameters = [];
127 $this->current_description = null;
128 $this->current_internal = null;
138 xml_set_object($a_xml_parser, $this);
139 xml_set_element_handler(
144 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
154 if ($this->in_metadata) {
155 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
161 $this->in_metadata =
true;
167 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
172 $this->current_sorting_position = (
int) ($a_attribs[
'position'] ?: 0);
176 $this->
getMode() == self::MODE_CREATE ||
177 ($a_attribs[
'action'] ?? null) ===
'Create' 179 $this->current_item_create =
true;
181 if (!($a_attribs[
'id'] ??
false)) {
183 'Updating or deleting not possible, no id was given for element "Weblink"' 187 $this->
getMode() == self::MODE_UPDATE &&
188 ($a_attribs[
'action'] ?? null) ===
'Delete' 190 $this->current_item_delete =
true;
191 $this->web_link_repo->deleteItemByLinkId($a_attribs[
'id']);
194 $this->
getMode() == self::MODE_UPDATE &&
195 (!isset($a_attribs[
'action']) || $a_attribs[
'action'] ==
'Update')
197 $this->current_link_id = $a_attribs[
'id'];
198 $this->current_item_update =
true;
201 'Invalid action given for element "Weblink"' 207 $this->current_active = (bool) $a_attribs[
'active'];
210 if (isset($a_attribs[
'internal'])) {
211 $this->current_internal = (bool) $a_attribs[
'internal'];
222 switch ($a_attribs[
'type'] ?? null) {
235 $this->sorting_positions = array();
241 case 'ListDescription':
245 case 'DynamicParameter':
246 if (!($a_attribs[
'name'] ??
false)) {
248 'No attribute "name" given for element "Dynamic parameter". Aborting' 251 $name = $a_attribs[
'name'] ?? null;
253 switch ($a_attribs[
'type'] ?? null) {
262 case 'matriculation':
268 'Invalid attribute "type" given for element "Dynamic parameter". Aborting' 273 if ($this->current_item_update && ($a_attribs[
'id'] ?? null)) {
274 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
275 $old_param = $this->web_link_repo->getParameterinItemByParamId(
279 $param->replaces($old_param);
281 $this->current_parameters[] =
$param;
286 $this->is_list =
true;
293 $this->cdata = $this->
trimAndStrip((
string) $this->cdata);
295 if ($this->in_metadata) {
296 parent::handlerEndTag($a_xml_parser, $a_name);
301 $this->in_metadata =
false;
302 parent::handlerEndTag($a_xml_parser, $a_name);
306 if ($this->is_list || !$this->web_link_repo->doesOnlyOneItemExist()) {
308 $this->list_title ?? $this->
getWebLink()->getTitle(),
309 $this->list_description ?? $this->
getWebLink()->getDescription()
312 if (!$this->web_link_repo->doesListExist()) {
313 $this->web_link_repo->createList($list_draft);
315 $this->web_link_repo->updateList(
316 $this->web_link_repo->getList(),
322 $this->
getWebLink()->MDUpdateListener(
'General');
329 $sorting->savePost($this->sorting_positions);
331 $this->sorting_positions
337 if ($this->current_item_delete) {
341 if (!$this->current_item_create && !$this->current_item_update) {
343 'Invalid xml structure given. Missing start tag "WebLink"' 346 if (!$this->current_title || !$this->current_target) {
348 'Missing required elements "Title, Target"' 352 if ($this->current_item_update) {
353 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
355 $this->current_internal ?? $item->isInternal(),
356 $this->current_title ?? $item->getTitle(),
357 $this->current_description ?? $item->getDescription(),
358 $this->current_target ?? $item->getTarget(),
359 $this->current_active ?? $item->isActive(),
363 $this->web_link_repo->updateItem($item, $draft);
367 $this->current_title,
368 $this->current_description ?? null,
369 $this->current_target,
370 $this->current_active,
371 $this->current_parameters
373 $item = $this->web_link_repo->createItem($draft);
383 $this->current_title = trim($this->cdata);
387 $this->current_description = trim($this->cdata);
391 $this->current_target = trim($this->cdata);
395 $this->list_title = trim($this->cdata);
398 case 'ListDescription':
399 $this->list_description = trim($this->cdata);
409 if ($this->in_metadata) {
410 parent::handlerCharacterData($a_xml_parser, $a_data);
413 if ($a_data !=
"\n") {
415 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
416 $this->cdata .= $a_data;
XML parser for weblink xml.
setThrowException(bool $throw_exception)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getLogger(string $a_component_id)
Get component logger.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
trimAndStrip(string $input)
bool $current_item_update
bool $current_item_delete
trimAndStripAttribs(array $attribs)
handlerEndTag($a_xml_parser, string $a_name)
SaxParserException thrown by ilSaxParser if property throwException is set.
setWebLink(ilObjLinkResource $webl)
array $current_parameters
int $current_sorting_position
__construct(ilObjLinkResource $webr, string $xml)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setHandlers($a_xml_parser)
handlerBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
bool $current_item_create
handlerCharacterData($a_xml_parser, string $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
string $current_description
__construct(Container $dic, ilPlugin $plugin)
static _getInstance(int $a_obj_id)
ilWebLinkRepository $web_link_repo
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const VALUES
TODO Once the GUI is updated, undefined can be dropped.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setXMLContent(string $a_xml_content)