ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilWebLinkXmlParser Class Reference
+ 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)
 
 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 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 int MODE_UPDATE = 1
 
const int MODE_CREATE = 2
 
- Data Fields inherited from ilSaxParser
string $xml_file
 
bool $throw_exception = false
 

Protected Member Functions

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

Protected Attributes

const int MODE_UNDEFINED = 0
 
- Protected Attributes inherited from ilSaxParser
ilLanguage $lng = null
 

Private Attributes

ilObjLinkResource $webl
 
ilWebLinkRepository $web_link_repo
 
int $mode = self::MODE_UNDEFINED
 
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
 
string $first_item_title
 
string $first_item_description
 

Detailed Description

Constructor & Destructor Documentation

◆ __construct()

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

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

59 {
61 $this->setXMLContent($xml);
62 $this->setWebLink($webr);
63 $this->web_link_repo = new ilWebLinkDatabaseRepository(
64 $this->getWebLink()->getId()
65 );
66
67 $this->setThrowException(true);
68 }
setXMLContent(string $a_xml_content)
setThrowException(bool $throw_exception)
setWebLink(ilObjLinkResource $webl)
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc

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

+ Here is the call graph for this function:

Member Function Documentation

◆ getMode()

ilWebLinkXmlParser::getMode ( )

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

95 : int
96 {
97 return $this->mode;
98 }

References $mode.

◆ getWebLink()

ilWebLinkXmlParser::getWebLink ( )

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

References $webl.

Referenced by __construct(), and startParsing().

+ Here is the caller graph for this function:

◆ handlerBeginTag()

ilWebLinkXmlParser::handlerBeginTag (   $a_xml_parser,
string  $a_name,
array  $a_attribs 
)

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

130 : void {
131 global $DIC;
132 $a_attribs = $this->trimAndStripAttribs($a_attribs);
133
134 switch ($a_name) {
135 case 'WebLink':
136
137 $this->current_sorting_position = (int) ($a_attribs['position'] ?: 0);
138 $this->resetStoredValues();
139
140 if (
141 $this->getMode() == self::MODE_CREATE ||
142 ($a_attribs['action'] ?? null) === 'Create'
143 ) {
144 $this->current_item_create = true;
145 } else {
146 if (!($a_attribs['id'] ?? false)) {
148 'Updating or deleting not possible, no id was given for element "Weblink"'
149 );
150 }
151 if (
152 $this->getMode() == self::MODE_UPDATE &&
153 ($a_attribs['action'] ?? null) === 'Delete'
154 ) {
155 $this->current_item_delete = true;
156 $this->web_link_repo->deleteItemByLinkId($a_attribs['id']);
157 break;
158 } elseif (
159 $this->getMode() == self::MODE_UPDATE &&
160 (!isset($a_attribs['action']) || $a_attribs['action'] == 'Update')
161 ) {
162 $this->current_link_id = $a_attribs['id'];
163 $this->current_item_update = true;
164 } else {
166 'Invalid action given for element "Weblink"'
167 );
168 }
169 }
170
171 // Active
172 $this->current_active = (bool) $a_attribs['active'];
173
174 // internal
175 if (isset($a_attribs['internal'])) {
176 $this->current_internal = (bool) $a_attribs['internal'];
177 }
178 break;
179
180 case 'Sorting':
181
182 $sort = new ilContainerSortingSettings(
183 $this->getWebLink()->getId()
184 );
185 $sort->delete();
186
187 switch ($a_attribs['type'] ?? null) {
188 case 'Manual':
189 $sort->setSortMode(ilContainer::SORT_MANUAL);
190 break;
191
192 case 'Title':
193 default:
194 $sort->setSortMode(ilContainer::SORT_TITLE);
195 }
196 $sort->save();
197 break;
198
199 case 'WebLinks':
200 $this->sorting_positions = array();
201 // no break
202 case 'Title':
203 case 'Description':
204 case 'Target':
205 case 'ListTitle':
206 case 'ListDescription':
207 // Nothing to do
208 break;
209
210 case 'DynamicParameter':
211 if (!($a_attribs['name'] ?? false)) {
213 'No attribute "name" given for element "Dynamic parameter". Aborting'
214 );
215 }
216 $name = $a_attribs['name'] ?? null;
217
218 switch ($a_attribs['type'] ?? null) {
219 case 'userName':
220 $value = ilWebLinkBaseParameter::VALUES['login'];
221 break;
222
223 case 'userId':
224 $value = ilWebLinkBaseParameter::VALUES['user_id'];
225 break;
226
227 case 'matriculation':
228 $value = ilWebLinkBaseParameter::VALUES['matriculation'];
229 break;
230
231 default:
233 'Invalid attribute "type" given for element "Dynamic parameter". Aborting'
234 );
235 }
236
237 $param = new ilWebLinkDraftParameter($value, $name);
238 if ($this->current_item_update && ($a_attribs['id'] ?? null)) {
239 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
240 $old_param = $this->web_link_repo->getParameterinItemByParamId(
241 $item,
242 $a_attribs['id']
243 );
244 $param->replaces($old_param);
245 }
246 $this->current_parameters[] = $param;
247
248 break;
249
250 case 'ListSettings':
251 $this->is_list = true;
252 break;
253 }
254 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
Draft class for creating and updating a parameter attached to Web Link items.
trimAndStripAttribs(array $attribs)
global $DIC
Definition: shib_login.php:26
$param
Definition: xapitoken.php:46

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerCharacterData()

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

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

366 : void
367 {
368 if ($a_data != "\n") {
369 // Replace multiple tabs with one space
370 $a_data = preg_replace("/\t+/", " ", $a_data);
371 $this->cdata .= $a_data;
372 }
373 }

Referenced by setHandlers().

+ Here is the caller graph for this function:

◆ handlerEndTag()

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

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

256 : void
257 {
258 $this->cdata = $this->trimAndStrip($this->cdata);
259
260 switch ($a_name) {
261 case 'WebLinks':
262 if ($this->is_list || !$this->web_link_repo->doesOnlyOneItemExist()) {
263 $list_draft = new ilWebLinkDraftList(
264 $this->list_title ?? $this->getWebLink()->getTitle(),
265 $this->list_description ?? $this->getWebLink()->getDescription()
266 );
267
268 if (!$this->web_link_repo->doesListExist()) {
269 $this->web_link_repo->createList($list_draft);
270 } else {
271 $this->web_link_repo->updateList(
272 $this->web_link_repo->getList(),
273 $list_draft
274 );
275 }
276 }
277
278 // save sorting
280 $this->getWebLink()->getId()
281 );
282 $sorting->savePost($this->sorting_positions);
283 ilLoggerFactory::getLogger('webr')->dump(
284 $this->sorting_positions
285 );
286 break;
287
288 case 'WebLink':
289
290 if ($this->current_item_delete) {
291 //Deletion is already handled in the begin tag.
292 break;
293 }
294 if (!$this->current_item_create && !$this->current_item_update) {
295 throw new ilSaxParserException(
296 'Invalid xml structure given. Missing start tag "WebLink"'
297 );
298 }
299 if (!$this->current_title || !$this->current_target) {
301 'Missing required elements "Title, Target"'
302 );
303 }
304
305 if ($this->current_item_update) {
306 $item = $this->web_link_repo->getItemByLinkId($this->current_link_id);
307 $draft = new ilWebLinkDraftItem(
308 $this->current_internal ?? $item->isInternal(),
309 $this->current_title ?? $item->getTitle(),
310 $this->current_description ?? $item->getDescription(),
311 $this->current_target ?? $item->getTarget(),
312 $this->current_active ?? $item->isActive(),
313 $this->current_parameters
314 );
315
316 $this->web_link_repo->updateItem($item, $draft);
317 } else {
318 $draft = new ilWebLinkDraftItem(
319 $this->current_internal ?? ilLinkInputGUI::isInternalLink($this->current_target),
320 $this->current_title,
321 $this->current_description ?? null,
322 $this->current_target,
323 $this->current_active,
324 $this->current_parameters
325 );
326 $item = $this->web_link_repo->createItem($draft);
327 }
328
329 // store positions
330 $this->sorting_positions[$item->getLinkId()] = $this->current_sorting_position;
331
332 $this->resetStoredValues();
333 break;
334
335 case 'Title':
336 $this->current_title = trim($this->cdata);
337 if (!isset($this->first_item_title)) {
338 $this->first_item_title = $this->current_title;
339 }
340 break;
341
342 case 'Description':
343 $this->current_description = trim($this->cdata);
344 if (!isset($this->first_item_description)) {
345 $this->first_item_description = $this->current_description;
346 }
347 break;
348
349 case 'Target':
350 $this->current_target = trim($this->cdata);
351 break;
352
353 case 'ListTitle':
354 $this->list_title = trim($this->cdata);
355 break;
356
357 case 'ListDescription':
358 $this->list_description = trim($this->cdata);
359 break;
360 }
361
362 // Reset cdata
363 $this->cdata = '';
364 }
static _getInstance(int $a_obj_id)
static isInternalLink(string $a_value)
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...
Draft class for creating and updating a Web Link item.
Draft class for creating or updating a Web Link list.

References ilContainerSorting\_getInstance(), ILIAS\Survey\Mode\getId(), ilLoggerFactory\getLogger(), ILIAS\GlobalScreen\Scope\Footer\Factory\getTitle(), and ilLinkInputGUI\isInternalLink().

Referenced by setHandlers().

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

◆ resetStoredValues()

ilWebLinkXmlParser::resetStoredValues ( )
protected

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

100 : void
101 {
102 $this->current_item_create = false;
103 $this->current_item_update = false;
104 $this->current_item_delete = false;
105
106 $this->current_link_id = null;
107 $this->current_title = null;
108 $this->current_target = null;
109 $this->current_active = null;
110 $this->current_parameters = [];
111 $this->current_description = null;
112 $this->current_internal = null;
113 }

◆ setHandlers()

ilWebLinkXmlParser::setHandlers (   $a_xml_parser)
Parameters
XMLParser | resource$a_xml_parser
Returns
void

Reimplemented from ilSaxParser.

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

120 : void
121 {
122 xml_set_element_handler($a_xml_parser, $this->handlerBeginTag(...), $this->handlerEndTag(...));
123 xml_set_character_data_handler($a_xml_parser, $this->handlerCharacterData(...));
124 }
handlerBeginTag( $a_xml_parser, string $a_name, array $a_attribs)
handlerCharacterData($a_xml_parser, string $a_data)
handlerEndTag($a_xml_parser, string $a_name)

References handlerBeginTag(), handlerCharacterData(), and handlerEndTag().

+ Here is the call graph for this function:

◆ setMode()

ilWebLinkXmlParser::setMode ( int  $a_mode)

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

90 : void
91 {
92 $this->mode = $a_mode;
93 }

◆ setWebLink()

ilWebLinkXmlParser::setWebLink ( ilObjLinkResource  $webl)

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

80 : void
81 {
82 $this->webl = $webl;
83 }

References $webl.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ start()

ilWebLinkXmlParser::start ( )

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

115 : void
116 {
117 $this->startParsing();
118 }
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 70 of file class.ilWebLinkXmlParser.php.

70 : void
71 {
72 parent::startParsing();
73
74 // set title and description
75 $this->getWebLink()->setTitle($this->list_title ?? $this->first_item_title);
76 $this->getWebLink()->setDescription($this->list_description ?? $this->first_item_description);
77 $this->getWebLink()->update();
78 }

References getWebLink().

Referenced by start().

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

◆ trimAndStrip()

ilWebLinkXmlParser::trimAndStrip ( string  $input)
protected

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

384 : string
385 {
386 return ilUtil::stripSlashes(trim($input));
387 }
static stripSlashes(string $a_str, bool $a_strip_html=true, string $a_allow="")

References ilUtil\stripSlashes().

+ Here is the call graph for this function:

◆ trimAndStripAttribs()

ilWebLinkXmlParser::trimAndStripAttribs ( array  $attribs)
protected

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

375 : array
376 {
377 $ret = [];
378 foreach ($attribs as $k => $v) {
379 $ret[$k] = $this->trimAndStrip((string) $v);
380 }
381 return $ret;
382 }

Field Documentation

◆ $cdata

string ilWebLinkXmlParser::$cdata = ''
private

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

◆ $current_active

bool ilWebLinkXmlParser::$current_active
private

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

◆ $current_description

string ilWebLinkXmlParser::$current_description
private

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

◆ $current_internal

bool ilWebLinkXmlParser::$current_internal
private

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

◆ $current_item_create

bool ilWebLinkXmlParser::$current_item_create = false
private

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

◆ $current_item_delete

bool ilWebLinkXmlParser::$current_item_delete = false
private

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

◆ $current_item_update

bool ilWebLinkXmlParser::$current_item_update = false
private

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

◆ $current_link_id

int ilWebLinkXmlParser::$current_link_id
private

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

◆ $current_parameters

array ilWebLinkXmlParser::$current_parameters = []
private

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

◆ $current_sorting_position

int ilWebLinkXmlParser::$current_sorting_position = 0
private

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

◆ $current_target

string ilWebLinkXmlParser::$current_target
private

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

◆ $current_title

string ilWebLinkXmlParser::$current_title
private

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

◆ $first_item_description

string ilWebLinkXmlParser::$first_item_description
private

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

◆ $first_item_title

string ilWebLinkXmlParser::$first_item_title
private

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

◆ $is_list

bool ilWebLinkXmlParser::$is_list = false
private

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

◆ $list_description

string ilWebLinkXmlParser::$list_description
private

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

◆ $list_title

string ilWebLinkXmlParser::$list_title
private

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

◆ $mode

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

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

Referenced by getMode().

◆ $sorting_positions

array ilWebLinkXmlParser::$sorting_positions = []
private

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

◆ $web_link_repo

ilWebLinkRepository ilWebLinkXmlParser::$web_link_repo
private

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

◆ $webl

ilObjLinkResource ilWebLinkXmlParser::$webl
private

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

Referenced by getWebLink(), and setWebLink().

◆ MODE_CREATE

const int ilWebLinkXmlParser::MODE_CREATE = 2

◆ MODE_UNDEFINED

const int ilWebLinkXmlParser::MODE_UNDEFINED = 0
protected

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

◆ MODE_UPDATE

const int ilWebLinkXmlParser::MODE_UPDATE = 1

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