19 declare(strict_types=1);
35 private int $mode = self::MODE_UNDEFINED;
83 parent::startParsing();
86 $this->
getWebLink()->setTitle($this->list_title ?? $this->first_item_title);
87 $this->
getWebLink()->setDescription($this->list_description ?? $this->first_item_description);
92 $identifier_ids =
$general->getIdentifierIds();
93 if (!isset($identifier_ids[0])) {
96 $identifier =
$general->getIdentifier($identifier_ids[0]);
97 $identifier->setEntry(
100 $identifier->update();
115 $this->mode = $a_mode;
125 $this->current_item_create =
false;
126 $this->current_item_update =
false;
127 $this->current_item_delete =
false;
129 $this->current_link_id = null;
130 $this->current_title = null;
131 $this->current_target = null;
132 $this->current_active = null;
133 $this->current_parameters = [];
134 $this->current_description = null;
135 $this->current_internal = null;
145 xml_set_object($a_xml_parser, $this);
146 xml_set_element_handler(
151 xml_set_character_data_handler($a_xml_parser,
'handlerCharacterData');
161 if ($this->in_metadata) {
162 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
168 $this->in_metadata =
true;
174 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
179 $this->current_sorting_position = (
int) ($a_attribs[
'position'] ?: 0);
183 $this->
getMode() == self::MODE_CREATE ||
184 ($a_attribs[
'action'] ?? null) ===
'Create' 186 $this->current_item_create =
true;
188 if (!($a_attribs[
'id'] ??
false)) {
190 'Updating or deleting not possible, no id was given for element "Weblink"' 194 $this->
getMode() == self::MODE_UPDATE &&
195 ($a_attribs[
'action'] ?? null) ===
'Delete' 197 $this->current_item_delete =
true;
198 $this->web_link_repo->deleteItemByLinkId($a_attribs[
'id']);
201 $this->
getMode() == self::MODE_UPDATE &&
202 (!isset($a_attribs[
'action']) || $a_attribs[
'action'] ==
'Update')
204 $this->current_link_id = $a_attribs[
'id'];
205 $this->current_item_update =
true;
208 'Invalid action given for element "Weblink"' 214 $this->current_active = (bool) $a_attribs[
'active'];
217 if (isset($a_attribs[
'internal'])) {
218 $this->current_internal = (bool) $a_attribs[
'internal'];
229 switch ($a_attribs[
'type'] ?? null) {
242 $this->sorting_positions = array();
248 case 'ListDescription':
252 case 'DynamicParameter':
253 if (!($a_attribs[
'name'] ??
false)) {
255 'No attribute "name" given for element "Dynamic parameter". Aborting' 258 $name = $a_attribs[
'name'] ?? null;
260 switch ($a_attribs[
'type'] ?? null) {
269 case 'matriculation':
275 'Invalid attribute "type" given for element "Dynamic parameter". Aborting' 280 if ($this->current_item_update && ($a_attribs[
'id'] ?? null)) {
281 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
282 $old_param = $this->web_link_repo->getParameterinItemByParamId(
286 $param->replaces($old_param);
288 $this->current_parameters[] =
$param;
293 $this->is_list =
true;
300 $this->cdata = $this->
trimAndStrip((
string) $this->cdata);
302 if ($this->in_metadata) {
303 parent::handlerEndTag($a_xml_parser, $a_name);
308 $this->in_metadata =
false;
309 parent::handlerEndTag($a_xml_parser, $a_name);
313 if ($this->is_list || !$this->web_link_repo->doesOnlyOneItemExist()) {
316 $this->list_description ?? $this->
getWebLink()->getDescription()
319 if (!$this->web_link_repo->doesListExist()) {
320 $this->web_link_repo->createList($list_draft);
322 $this->web_link_repo->updateList(
323 $this->web_link_repo->getList(),
333 $sorting->savePost($this->sorting_positions);
335 $this->sorting_positions
341 if ($this->current_item_delete) {
345 if (!$this->current_item_create && !$this->current_item_update) {
347 'Invalid xml structure given. Missing start tag "WebLink"' 350 if (!$this->current_title || !$this->current_target) {
352 'Missing required elements "Title, Target"' 356 if ($this->current_item_update) {
357 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
359 $this->current_internal ?? $item->isInternal(),
360 $this->current_title ?? $item->getTitle(),
361 $this->current_description ?? $item->getDescription(),
362 $this->current_target ?? $item->getTarget(),
363 $this->current_active ?? $item->isActive(),
367 $this->web_link_repo->updateItem($item, $draft);
371 $this->current_title,
372 $this->current_description ?? null,
373 $this->current_target,
374 $this->current_active,
375 $this->current_parameters
377 $item = $this->web_link_repo->createItem($draft);
387 $this->current_title = trim($this->cdata);
388 if (!isset($this->first_item_title)) {
394 $this->current_description = trim($this->cdata);
395 if (!isset($this->first_item_description)) {
401 $this->current_target = trim($this->cdata);
405 $this->list_title = trim($this->cdata);
408 case 'ListDescription':
409 $this->list_description = trim($this->cdata);
419 if ($this->in_metadata) {
420 parent::handlerCharacterData($a_xml_parser, $a_data);
423 if ($a_data !=
"\n") {
425 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
426 $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...
string $first_item_description
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)