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;
156 if ($this->in_metadata) {
157 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
163 $this->in_metadata =
true;
169 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
174 $this->current_sorting_position = (
int) ($a_attribs[
'position'] ?: 0);
178 $this->
getMode() == self::MODE_CREATE ||
179 ($a_attribs[
'action'] ??
null) ===
'Create' 181 $this->current_item_create =
true;
183 if (!($a_attribs[
'id'] ??
false)) {
185 'Updating or deleting not possible, no id was given for element "Weblink"' 189 $this->
getMode() == self::MODE_UPDATE &&
190 ($a_attribs[
'action'] ?? null) ===
'Delete' 192 $this->current_item_delete =
true;
193 $this->web_link_repo->deleteItemByLinkId($a_attribs[
'id']);
196 $this->
getMode() == self::MODE_UPDATE &&
197 (!isset($a_attribs[
'action']) || $a_attribs[
'action'] ==
'Update')
199 $this->current_link_id = $a_attribs[
'id'];
200 $this->current_item_update =
true;
203 'Invalid action given for element "Weblink"' 209 $this->current_active = (bool) $a_attribs[
'active'];
212 if (isset($a_attribs[
'internal'])) {
213 $this->current_internal = (bool) $a_attribs[
'internal'];
224 switch ($a_attribs[
'type'] ?? null) {
237 $this->sorting_positions = array();
243 case 'ListDescription':
247 case 'DynamicParameter':
248 if (!($a_attribs[
'name'] ??
false)) {
250 'No attribute "name" given for element "Dynamic parameter". Aborting' 253 $name = $a_attribs[
'name'] ??
null;
255 switch ($a_attribs[
'type'] ?? null) {
264 case 'matriculation':
270 'Invalid attribute "type" given for element "Dynamic parameter". Aborting' 275 if ($this->current_item_update && ($a_attribs[
'id'] ?? null)) {
276 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
277 $old_param = $this->web_link_repo->getParameterinItemByParamId(
281 $param->replaces($old_param);
283 $this->current_parameters[] =
$param;
288 $this->is_list =
true;
295 $this->cdata = $this->
trimAndStrip((
string) $this->cdata);
297 if ($this->in_metadata) {
298 parent::handlerEndTag($a_xml_parser, $a_name);
303 $this->in_metadata =
false;
304 parent::handlerEndTag($a_xml_parser, $a_name);
308 if ($this->is_list || !$this->web_link_repo->doesOnlyOneItemExist()) {
311 $this->list_description ?? $this->
getWebLink()->getDescription()
314 if (!$this->web_link_repo->doesListExist()) {
315 $this->web_link_repo->createList($list_draft);
317 $this->web_link_repo->updateList(
318 $this->web_link_repo->getList(),
328 $sorting->savePost($this->sorting_positions);
330 $this->sorting_positions
336 if ($this->current_item_delete) {
340 if (!$this->current_item_create && !$this->current_item_update) {
342 'Invalid xml structure given. Missing start tag "WebLink"' 345 if (!$this->current_title || !$this->current_target) {
347 'Missing required elements "Title, Target"' 351 if ($this->current_item_update) {
352 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
354 $this->current_internal ?? $item->isInternal(),
355 $this->current_title ?? $item->getTitle(),
356 $this->current_description ?? $item->getDescription(),
357 $this->current_target ?? $item->getTarget(),
358 $this->current_active ?? $item->isActive(),
362 $this->web_link_repo->updateItem($item, $draft);
366 $this->current_title,
367 $this->current_description ??
null,
368 $this->current_target,
369 $this->current_active,
370 $this->current_parameters
372 $item = $this->web_link_repo->createItem($draft);
382 $this->current_title = trim($this->cdata);
383 if (!isset($this->first_item_title)) {
389 $this->current_description = trim($this->cdata);
390 if (!isset($this->first_item_description)) {
396 $this->current_target = trim($this->cdata);
400 $this->list_title = trim($this->cdata);
403 case 'ListDescription':
404 $this->list_description = trim($this->cdata);
414 if ($this->in_metadata) {
415 parent::handlerCharacterData($a_xml_parser, $a_data);
418 if ($a_data !=
"\n") {
420 $a_data = preg_replace(
"/\t+/",
" ", $a_data);
421 $this->cdata .= $a_data;
XML parser for weblink xml.
setThrowException(bool $throw_exception)
Draft class for creating and updating a parameter attached to Web Link items.
string $first_item_description
static getLogger(string $a_component_id)
Get component logger.
trimAndStrip(string $input)
bool $current_item_update
bool $current_item_delete
trimAndStripAttribs(array $attribs)
handlerEndTag($a_xml_parser, string $a_name)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setWebLink(ilObjLinkResource $webl)
array $current_parameters
int $current_sorting_position
__construct(ilObjLinkResource $webr, string $xml)
while($session_entry=$r->fetchRow(ilDBConstants::FETCHMODE_ASSOC)) return null
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setHandlers($a_xml_parser)
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
handlerBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
bool $current_item_create
handlerCharacterData($a_xml_parser, string $a_data)
Draft class for creating or updating a Web Link list.
string $current_description
__construct(Container $dic, ilPlugin $plugin)
static _getInstance(int $a_obj_id)
ilWebLinkRepository $web_link_repo
Draft class for creating and updating a Web Link item.
setXMLContent(string $a_xml_content)