ILIAS  release_8 Revision v8.24
ilWebLinkXmlParser Class Reference

XML parser for weblink xml. More...

+ Inheritance diagram for ilWebLinkXmlParser:
+ Collaboration diagram for ilWebLinkXmlParser:

Public Member Functions

 __construct (ilObjLinkResource $webr, string $xml)
 
 startParsing ()
 stores xml data in array More...
 
 setWebLink (ilObjLinkResource $webl)
 
 getWebLink ()
 
 setMode (int $a_mode)
 
 getMode ()
 
 start ()
 
 setHandlers ($a_xml_parser)
 Set event handlers. More...
 
 handlerBeginTag ( $a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
- Public Member Functions inherited from ilMDSaxParser
 __construct (?string $a_xml_file='')
 
 enableMDParsing (bool $a_status)
 
 getMDParsingStatus ()
 
 setMDObject (ilMD $md)
 
 getMDObject ()
 
 inMetaData ()
 
 setHandlers ($a_xml_parser)
 Set event handlers. More...
 
 handlerBeginTag ($a_xml_parser, string $a_name, array $a_attribs)
 
 handlerEndTag ($a_xml_parser, string $a_name)
 
 handlerCharacterData ($a_xml_parser, string $a_data)
 
 __getCharacterData ()
 
 __pushParent (object $md_obj)
 
 __popParent ()
 
 __getParent ()
 
- Public Member Functions inherited from ilSaxParser
 __construct (?string $path_to_file='', ?bool $throw_exception=false)
 
 setXMLContent (string $a_xml_content)
 
 getXMLContent ()
 
 getInputType ()
 
 startParsing ()
 stores xml data in array More...
 
 createParser ()
 
 setHandlers ($a_xml_parser)
 
 parse ($a_xml_parser, $a_fp=null)
 

Data Fields

const MODE_UPDATE = 1
 
const MODE_CREATE = 2
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Protected Member Functions

 resetStoredValues ()
 
- Protected Member Functions inherited from ilMDSaxParser
 trimAndStripAttribs (array $attribs)
 
 trimAndStrip (string $input)
 
- Protected Member Functions inherited from ilSaxParser
 openXMLFile ()
 
 handleError (string $message)
 
 setThrowException (bool $throw_exception)
 

Protected Attributes

const MODE_UNDEFINED = 0
 
- Protected Attributes inherited from ilMDSaxParser
bool $md_in_md = false
 
string $md_chr_data = ''
 
ilMDIdentifier $md_ide = null
 
ilMDLanguage $md_lan = null
 
ilMDDescription $md_des = null
 
ilMDLifecycle $md_lif = null
 
ilMDContribute $md_con = null
 
ilMDEntity $md_ent = null
 
ilMDMetaMetadata $md_met = null
 
ilMDTechnical $md_tec = null
 
ilMDFormat $md_for = null
 
ilMDLocation $md_loc = null
 
ilMDRequirement $md_req = null
 
ilMDOrComposite $md_orc = null
 
ilMDEducational $md_edu = null
 
ilMDTypicalAgeRange $md_typ = null
 
ilMDRights $md_rig = null
 
ilMDRelation $md_rel = null
 
ilMDIdentifier_ $md_ide_ = null
 
ilMDAnnotation $md_ann = null
 
ilMDClassification $md_cla = null
 
ilMDTaxonPath $md_taxp = null
 
ilMDTaxon $md_tax = null
 
ilMDKeyword $md_key = null
 
array $md_parent = array()
 
ilMD $md = null
 
ilMDGeneral $md_gen = null
 
ilLogger $meta_log
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Attributes

ilObjLinkResource $webl
 
ilWebLinkRepository $web_link_repo
 
int $mode = self::MODE_UNDEFINED
 
bool $in_metadata = false
 
array $sorting_positions = []
 
string $cdata = ''
 
int $current_sorting_position = 0
 
bool $current_item_create = false
 
bool $current_item_update = false
 
bool $current_item_delete = false
 
int $current_link_id
 
string $current_title
 
string $current_target
 
bool $current_active
 
array $current_parameters = []
 
string $current_description
 
bool $current_internal
 
bool $is_list = false
 
string $list_title
 
string $list_description
 

Detailed Description

XML parser for weblink xml.

Author
Stefan Meyer smeye.nosp@m.r.il.nosp@m.ias@g.nosp@m.mx.d.nosp@m.e
Version
$Id$

Definition at line 27 of file class.ilWebLinkXmlParser.php.

Constructor & Destructor Documentation

◆ __construct()

ilWebLinkXmlParser::__construct ( ilObjLinkResource  $webr,
string  $xml 
)

Definition at line 60 of file class.ilWebLinkXmlParser.php.

61 {
63 $this->setXMLContent($xml);
64 $this->setWebLink($webr);
65 $this->web_link_repo = new ilWebLinkDatabaseRepository(
66 $this->getWebLink()->getId()
67 );
68
69 $this->setMDObject(
70 new ilMD(
71 $this->getWebLink()->getId(),
72 $this->getWebLink()->getId(),
73 'webr'
74 )
75 );
76 $this->setThrowException(true);
77 }
setXMLContent(string $a_xml_content)
setThrowException(bool $throw_exception)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setWebLink(ilObjLinkResource $webl)
$xml
Definition: metadata.php:351
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

References ILIAS\GlobalScreen\Provider\__construct(), ILIAS\Survey\Mode\getId(), getWebLink(), ilMDSaxParser\setMDObject(), ilSaxParser\setThrowException(), setWebLink(), and ilSaxParser\setXMLContent().

+ Here is the call graph for this function:

Member Function Documentation

◆ getMode()

ilWebLinkXmlParser::getMode ( )

Definition at line 111 of file class.ilWebLinkXmlParser.php.

111 : int
112 {
113 return $this->mode;
114 }

References $mode.

◆ getWebLink()

ilWebLinkXmlParser::getWebLink ( )

Definition at line 101 of file class.ilWebLinkXmlParser.php.

102 {
103 return $this->webl;
104 }
Class ilObjLinkResource.

References $webl.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilWebLinkXmlParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)
Parameters
XMLParser | resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 147 of file class.ilWebLinkXmlParser.php.

151 : void {
152 global $DIC;
153 $a_attribs = $this->trimAndStripAttribs($a_attribs);
154 if ($this->in_metadata) {
155 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
156 return;
157 }
158
159 switch ($a_name) {
160 case "MetaData":
161 $this->in_metadata = true;
162
163 // Delete old meta data
164 $md = new ilMD($this->getWebLink()->getId(), 0, 'webr');
165 $md->deleteAll();
166
167 parent::handlerBeginTag($a_xml_parser, $a_name, $a_attribs);
168 break;
169
170 case 'WebLink':
171
172 $this->current_sorting_position = (int) ($a_attribs['position'] ?: 0);
173 $this->resetStoredValues();
174
175 if (
176 $this->getMode() == self::MODE_CREATE ||
177 ($a_attribs['action'] ?? null) === 'Create'
178 ) {
179 $this->current_item_create = true;
180 } else {
181 if (!($a_attribs['id'] ?? false)) {
183 'Updating or deleting not possible, no id was given for element "Weblink"'
184 );
185 }
186 if (
187 $this->getMode() == self::MODE_UPDATE &&
188 ($a_attribs['action'] ?? null) === 'Delete'
189 ) {
190 $this->current_item_delete = true;
191 $this->web_link_repo->deleteItemByLinkId($a_attribs['id']);
192 break;
193 } elseif (
194 $this->getMode() == self::MODE_UPDATE &&
195 (!isset($a_attribs['action']) || $a_attribs['action'] == 'Update')
196 ) {
197 $this->current_link_id = $a_attribs['id'];
198 $this->current_item_update = true;
199 } else {
201 'Invalid action given for element "Weblink"'
202 );
203 }
204 }
205
206 // Active
207 $this->current_active = (bool) $a_attribs['active'];
208
209 // internal
210 if (isset($a_attribs['internal'])) {
211 $this->current_internal = (bool) $a_attribs['internal'];
212 }
213 break;
214
215 case 'Sorting':
216
217 $sort = new ilContainerSortingSettings(
218 $this->getWebLink()->getId()
219 );
220 $sort->delete();
221
222 switch ($a_attribs['type'] ?? null) {
223 case 'Manual':
224 $sort->setSortMode(ilContainer::SORT_MANUAL);
225 break;
226
227 case 'Title':
228 default:
229 $sort->setSortMode(ilContainer::SORT_TITLE);
230 }
231 $sort->save();
232 break;
233
234 case 'WebLinks':
235 $this->sorting_positions = array();
236 // no break
237 case 'Title':
238 case 'Description':
239 case 'Target':
240 case 'ListTitle':
241 case 'ListDescription':
242 // Nothing to do
243 break;
244
245 case 'DynamicParameter':
246 if (!($a_attribs['name'] ?? false)) {
248 'No attribute "name" given for element "Dynamic parameter". Aborting'
249 );
250 }
251 $name = $a_attribs['name'] ?? null;
252
253 switch ($a_attribs['type'] ?? null) {
254 case 'userName':
255 $value = ilWebLinkBaseParameter::VALUES['login'];
256 break;
257
258 case 'userId':
259 $value = ilWebLinkBaseParameter::VALUES['user_id'];
260 break;
261
262 case 'matriculation':
263 $value = ilWebLinkBaseParameter::VALUES['matriculation'];
264 break;
265
266 default:
268 'Invalid attribute "type" given for element "Dynamic parameter". Aborting'
269 );
270 }
271
272 $param = new ilWebLinkDraftParameter($value, $name);
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(
276 $item,
277 $a_attribs['id']
278 );
279 $param->replaces($old_param);
280 }
281 $this->current_parameters[] = $param;
282
283 break;
284
285 case 'ListSettings':
286 $this->is_list = true;
287 break;
288 }
289 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
trimAndStripAttribs(array $attribs)
deleteAll()
Definition: class.ilMD.php:301
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
$param
Definition: xapitoken.php:46

◆ handlerCharacterData()

ilWebLinkXmlParser::handlerCharacterData (   $a_xml_parser,
string  $a_data 
)
Parameters
resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 407 of file class.ilWebLinkXmlParser.php.

407 : void
408 {
409 if ($this->in_metadata) {
410 parent::handlerCharacterData($a_xml_parser, $a_data);
411 }
412
413 if ($a_data != "\n") {
414 // Replace multiple tabs with one space
415 $a_data = preg_replace("/\t+/", " ", $a_data);
416 $this->cdata .= $a_data;
417 }
418 }

◆ handlerEndTag()

ilWebLinkXmlParser::handlerEndTag (   $a_xml_parser,
string  $a_name 
)
Parameters
resource$a_xml_parser

Reimplemented from ilMDSaxParser.

Definition at line 291 of file class.ilWebLinkXmlParser.php.

291 : void
292 {
293 $this->cdata = $this->trimAndStrip((string) $this->cdata);
294
295 if ($this->in_metadata) {
296 parent::handlerEndTag($a_xml_parser, $a_name);
297 }
298
299 switch ($a_name) {
300 case 'MetaData':
301 $this->in_metadata = false;
302 parent::handlerEndTag($a_xml_parser, $a_name);
303 break;
304
305 case 'WebLinks':
306 if ($this->is_list || !$this->web_link_repo->doesOnlyOneItemExist()) {
307 $list_draft = new ilWebLinkDraftList(
308 $this->list_title ?? $this->getWebLink()->getTitle(),
309 $this->list_description ?? $this->getWebLink()->getDescription()
310 );
311
312 if (!$this->web_link_repo->doesListExist()) {
313 $this->web_link_repo->createList($list_draft);
314 } else {
315 $this->web_link_repo->updateList(
316 $this->web_link_repo->getList(),
317 $list_draft
318 );
319 }
320 }
321
322 $this->getWebLink()->MDUpdateListener('General');
323 $this->getWebLink()->update();
324
325 // save sorting
327 $this->getWebLink()->getId()
328 );
329 $sorting->savePost($this->sorting_positions);
330 ilLoggerFactory::getLogger('webr')->dump(
331 $this->sorting_positions
332 );
333 break;
334
335 case 'WebLink':
336
337 if ($this->current_item_delete) {
338 //Deletion is already handled in the begin tag.
339 break;
340 }
341 if (!$this->current_item_create && !$this->current_item_update) {
342 throw new ilSaxParserException(
343 'Invalid xml structure given. Missing start tag "WebLink"'
344 );
345 }
346 if (!$this->current_title || !$this->current_target) {
348 'Missing required elements "Title, Target"'
349 );
350 }
351
352 if ($this->current_item_update) {
353 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
354 $draft = new ilWebLinkDraftItem(
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(),
360 $this->current_parameters
361 );
362
363 $this->web_link_repo->updateItem($item, $draft);
364 } else {
365 $draft = new ilWebLinkDraftItem(
366 $this->current_internal ?? ilLinkInputGUI::isInternalLink($this->current_target),
367 $this->current_title,
368 $this->current_description ?? null,
369 $this->current_target,
370 $this->current_active,
371 $this->current_parameters
372 );
373 $item = $this->web_link_repo->createItem($draft);
374 }
375
376 // store positions
377 $this->sorting_positions[$item->getLinkId()] = $this->current_sorting_position;
378
379 $this->resetStoredValues();
380 break;
381
382 case 'Title':
383 $this->current_title = trim($this->cdata);
384 break;
385
386 case 'Description':
387 $this->current_description = trim($this->cdata);
388 break;
389
390 case 'Target':
391 $this->current_target = trim($this->cdata);
392 break;
393
394 case 'ListTitle':
395 $this->list_title = trim($this->cdata);
396 break;
397
398 case 'ListDescription':
399 $this->list_description = trim($this->cdata);
400 break;
401 }
402
403 // Reset cdata
404 $this->cdata = '';
405 }
static _getInstance(int $a_obj_id)
static isInternalLink(string $a_value)
static getLogger(string $a_component_id)
Get component logger.
trimAndStrip(string $input)
SaxParserException thrown by ilSaxParser if property throwException is set.
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...

References ilContainerSorting\_getInstance(), ILIAS\Survey\Mode\getId(), ilLoggerFactory\getLogger(), and ilLinkInputGUI\isInternalLink().

+ Here is the call graph for this function:

◆ resetStoredValues()

ilWebLinkXmlParser::resetStoredValues ( )
protected

Definition at line 116 of file class.ilWebLinkXmlParser.php.

116 : void
117 {
118 $this->current_item_create = false;
119 $this->current_item_update = false;
120 $this->current_item_delete = false;
121
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;
129 }

◆ setHandlers()

ilWebLinkXmlParser::setHandlers (   $a_xml_parser)

Set event handlers.

Parameters
XMLParser|resourcereference to the xml parser

Reimplemented from ilMDSaxParser.

Definition at line 136 of file class.ilWebLinkXmlParser.php.

136 : void
137 {
138 xml_set_object($a_xml_parser, $this);
139 xml_set_element_handler(
140 $a_xml_parser,
141 'handlerBeginTag',
142 'handlerEndTag'
143 );
144 xml_set_character_data_handler($a_xml_parser, 'handlerCharacterData');
145 }

◆ setMode()

ilWebLinkXmlParser::setMode ( int  $a_mode)

Definition at line 106 of file class.ilWebLinkXmlParser.php.

106 : void
107 {
108 $this->mode = $a_mode;
109 }

◆ setWebLink()

ilWebLinkXmlParser::setWebLink ( ilObjLinkResource  $webl)

Definition at line 96 of file class.ilWebLinkXmlParser.php.

96 : void
97 {
98 $this->webl = $webl;
99 }

References $webl.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ start()

ilWebLinkXmlParser::start ( )

Definition at line 131 of file class.ilWebLinkXmlParser.php.

131 : void
132 {
133 $this->startParsing();
134 }
startParsing()
stores xml data in array

References startParsing().

+ Here is the call graph for this function:

◆ startParsing()

ilWebLinkXmlParser::startParsing ( )

stores xml data in array

Exceptions
ilSaxParserException

Reimplemented from ilSaxParser.

Definition at line 79 of file class.ilWebLinkXmlParser.php.

79 : void
80 {
81 parent::startParsing();
82
83 // rewrite autogenerated entry
84 $general = $this->getMDObject()->getGeneral();
85 $identifier_ids = $general->getIdentifierIds();
86 if (!isset($identifier_ids[0])) {
87 return;
88 }
89 $identifier = $general->getIdentifier($identifier_ids[0]);
90 $identifier->setEntry(
91 'il__' . $this->getMDObject()->getObjType() . '_' . $this->getMDObject()->getObjId()
92 );
93 $identifier->update();
94 }

References ilMDSaxParser\getMDObject().

Referenced by start().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $cdata

string ilWebLinkXmlParser::$cdata = ''
private

Definition at line 38 of file class.ilWebLinkXmlParser.php.

◆ $current_active

bool ilWebLinkXmlParser::$current_active
private

Definition at line 48 of file class.ilWebLinkXmlParser.php.

◆ $current_description

string ilWebLinkXmlParser::$current_description
private

Definition at line 53 of file class.ilWebLinkXmlParser.php.

◆ $current_internal

bool ilWebLinkXmlParser::$current_internal
private

Definition at line 54 of file class.ilWebLinkXmlParser.php.

◆ $current_item_create

bool ilWebLinkXmlParser::$current_item_create = false
private

Definition at line 41 of file class.ilWebLinkXmlParser.php.

◆ $current_item_delete

bool ilWebLinkXmlParser::$current_item_delete = false
private

Definition at line 43 of file class.ilWebLinkXmlParser.php.

◆ $current_item_update

bool ilWebLinkXmlParser::$current_item_update = false
private

Definition at line 42 of file class.ilWebLinkXmlParser.php.

◆ $current_link_id

int ilWebLinkXmlParser::$current_link_id
private

Definition at line 45 of file class.ilWebLinkXmlParser.php.

◆ $current_parameters

array ilWebLinkXmlParser::$current_parameters = []
private

Definition at line 52 of file class.ilWebLinkXmlParser.php.

◆ $current_sorting_position

int ilWebLinkXmlParser::$current_sorting_position = 0
private

Definition at line 40 of file class.ilWebLinkXmlParser.php.

◆ $current_target

string ilWebLinkXmlParser::$current_target
private

Definition at line 47 of file class.ilWebLinkXmlParser.php.

◆ $current_title

string ilWebLinkXmlParser::$current_title
private

Definition at line 46 of file class.ilWebLinkXmlParser.php.

◆ $in_metadata

bool ilWebLinkXmlParser::$in_metadata = false
private

Definition at line 36 of file class.ilWebLinkXmlParser.php.

◆ $is_list

bool ilWebLinkXmlParser::$is_list = false
private

Definition at line 56 of file class.ilWebLinkXmlParser.php.

◆ $list_description

string ilWebLinkXmlParser::$list_description
private

Definition at line 58 of file class.ilWebLinkXmlParser.php.

◆ $list_title

string ilWebLinkXmlParser::$list_title
private

Definition at line 57 of file class.ilWebLinkXmlParser.php.

◆ $mode

int ilWebLinkXmlParser::$mode = self::MODE_UNDEFINED
private

Definition at line 35 of file class.ilWebLinkXmlParser.php.

Referenced by getMode().

◆ $sorting_positions

array ilWebLinkXmlParser::$sorting_positions = []
private

Definition at line 37 of file class.ilWebLinkXmlParser.php.

◆ $web_link_repo

ilWebLinkRepository ilWebLinkXmlParser::$web_link_repo
private

Definition at line 34 of file class.ilWebLinkXmlParser.php.

◆ $webl

ilObjLinkResource ilWebLinkXmlParser::$webl
private

Definition at line 33 of file class.ilWebLinkXmlParser.php.

Referenced by getWebLink(), and setWebLink().

◆ MODE_CREATE

const ilWebLinkXmlParser::MODE_CREATE = 2

◆ MODE_UNDEFINED

const ilWebLinkXmlParser::MODE_UNDEFINED = 0
protected

Definition at line 29 of file class.ilWebLinkXmlParser.php.

◆ MODE_UPDATE

const ilWebLinkXmlParser::MODE_UPDATE = 1

The documentation for this class was generated from the following file: