ILIAS  release_8 Revision v8.24
ilWebLinkDatabaseRepository Class Reference

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V. More...

+ Inheritance diagram for ilWebLinkDatabaseRepository:
+ Collaboration diagram for ilWebLinkDatabaseRepository:

Public Member Functions

 __construct (int $webr_id, bool $update_history=true)
 
 createItem (ilWebLinkDraftItem $item)
 Creates a new item, complete with parameters. More...
 
 createList (ilWebLinkDraftList $list)
 
 createAllItemsInDraftContainer (ilWebLinkDraftItemsContainer $container)
 
 getAllItemsAsContainer (bool $only_active=false)
 
 getItemByLinkId (int $link_id)
 
 doesOnlyOneItemExist (bool $only_active=false)
 
 getParameterinItemByParamId (ilWebLinkItem $item, int $param_id)
 
 getList ()
 
 doesListExist ()
 
 updateItem (ilWebLinkItem $item, ilWebLinkDraftItem $drafted_item)
 Updates an item. More...
 
 updateList (ilWebLinkList $list, ilWebLinkDraftList $drafted_list)
 
 deleteAllItems ()
 
 deleteItemByLinkID (int $link_id)
 
 deleteParameterByLinkIdAndParamId (int $link_id, int $param_id)
 
 deleteList ()
 
 getWebrId ()
 
 isUpdateHistory ()
 
 setUpdateHistory (bool $update_history)
 
 createItem (ilWebLinkDraftItem $item)
 Creates a new item, complete with parameters. More...
 
 createList (ilWebLinkDraftList $list)
 
 createAllItemsInDraftContainer (ilWebLinkDraftItemsContainer $container)
 
 getAllItemsAsContainer (bool $only_active=false)
 
 getItemByLinkId (int $link_id)
 
 doesOnlyOneItemExist (bool $only_active=false)
 
 getParameterinItemByParamId (ilWebLinkItem $item, int $param_id)
 
 getList ()
 
 doesListExist ()
 
 updateItem (ilWebLinkItem $item, ilWebLinkDraftItem $drafted_item)
 Updates an item. More...
 
 updateList (ilWebLinkList $list, ilWebLinkDraftList $drafted_list)
 
 deleteAllItems ()
 
 deleteItemByLinkID (int $link_id)
 
 deleteParameterByLinkIdAndParamId (int $link_id, int $param_id)
 
 deleteList ()
 

Data Fields

const ITEMS_TABLE = 'webr_items'
 
const LISTS_TABLE = 'webr_lists'
 
const PARAMS_TABLE = 'webr_params'
 

Protected Member Functions

 getParametersByLinkId (int $link_id)
 
 validateParameter (ilWebLinkBaseParameter $parameter)
 
 validateInternalItemTarget (ilWebLinkDraftItem $item)
 
 getCurrentTime ()
 
 getNewDateTimeImmutable ()
 

Protected Attributes

int $webr_id
 
ilDBInterface $db
 
ilObjUser $user
 
bool $update_history
 

Detailed Description

This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Learning e.V.

ILIAS is licensed with the GPL-3.0, see https://www.gnu.org/licenses/gpl-3.0.en.html You should have received a copy of said license along with the source code, too.

If this is not the case or you just want to try ILIAS, you'll find us at: https://www.ilias.de https://github.com/ILIAS-eLearning

Author
Tim Schmitz schmi.nosp@m.tz@l.nosp@m.eifos.nosp@m..de

Definition at line 24 of file class.ilWebLinkDatabaseRepository.php.

Constructor & Destructor Documentation

◆ __construct()

ilWebLinkDatabaseRepository::__construct ( int  $webr_id,
bool  $update_history = true 
)

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

36 {
37 global $DIC;
38
39 $this->db = $DIC->database();
40 $this->user = $DIC->user();
41 $this->webr_id = $webr_id;
42 $this->update_history = $update_history;
43 }
global $DIC
Definition: feed.php:28

References $DIC, $update_history, $webr_id, and ILIAS\Repository\user().

+ Here is the call graph for this function:

Member Function Documentation

◆ createAllItemsInDraftContainer()

ilWebLinkDatabaseRepository::createAllItemsInDraftContainer ( ilWebLinkDraftItemsContainer  $container)

Implements ilWebLinkRepository.

Definition at line 167 of file class.ilWebLinkDatabaseRepository.php.

168 {
169 $new_items = [];
170
171 foreach ($container->getItems() as $item) {
172 $new_items[] = $this->createItem($item);
173 }
174
175 return new ilWebLinkItemsContainer(
176 $this->getWebrId(),
177 $new_items
178 );
179 }
createItem(ilWebLinkDraftItem $item)
Creates a new item, complete with parameters.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$container
@noRector
Definition: wac.php:14

References $container, createItem(), and getWebrId().

+ Here is the call graph for this function:

◆ createItem()

ilWebLinkDatabaseRepository::createItem ( ilWebLinkDraftItem  $item)

Creates a new item, complete with parameters.

New parameters cannot be created on their own, but only by adding them as drafts to a drafted item, and then updating or creating with it.

Implements ilWebLinkRepository.

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

46 {
47 $next_link_id = $this->db->nextId(self::ITEMS_TABLE);
48
49 $this->validateInternalItemTarget($item);
50
51 //create the parameters
52 $new_parameters = [];
53 foreach ($item->getParameters() as $parameter) {
54 $next_param_id = $this->db->nextId(self::PARAMS_TABLE);
55
56 try {
57 $this->validateParameter($parameter);
58 } catch (Exception $e) {
59 continue;
60 }
61
62
63 $new_parameter = new ilWebLinkParameter(
64 $this->user,
65 $this->getWebrId(),
66 $next_link_id,
67 $next_param_id,
68 $parameter->getValue(),
69 $parameter->getName()
70 );
71
72 $this->db->insert(
73 self::PARAMS_TABLE,
74 [
75 'webr_id' => ['integer', $new_parameter->getWebrId()],
76 'link_id' => ['integer', $new_parameter->getLinkId()],
77 'param_id' => ['integer', $new_parameter->getParamId()],
78 'name' => ['text', $new_parameter->getName()],
79 'value' => ['integer', $new_parameter->getValue()]
80 ]
81 );
82
83 $new_parameters[] = $new_parameter;
84 }
85
86 //create the item with the new parameters
87 if ($item->isInternal()) {
88 $class = ilWebLinkItemInternal::class;
89 } else {
90 $class = ilWebLinkItemExternal::class;
91 }
92
93 $new_item = new $class(
94 $this->getWebrId(),
95 $next_link_id,
96 $item->getTitle(),
97 $item->getDescription(),
98 $item->getTarget(),
99 $item->isActive(),
100 $this->getNewDateTimeImmutable(),
101 $this->getNewDateTimeImmutable(),
102 $new_parameters
103 );
104
105 $this->db->insert(
106 self::ITEMS_TABLE,
107 [
108 'internal' => ['integer', (int) $new_item->isInternal()],
109 'webr_id' => ['integer', $new_item->getWebrId()],
110 'link_id' => ['integer', $new_item->getLinkId()],
111 'title' => ['text', $new_item->getTitle()],
112 'description' => ['text', $new_item->getDescription() ?? ''],
113 'target' => ['text', $new_item->getTarget()],
114 'active' => ['integer', (int) $new_item->isActive()],
115 'create_date' => ['integer', $new_item->getCreateDate()
116 ->getTimestamp()],
117 'last_update' => ['integer', $new_item->getLastUpdate()
118 ->getTimestamp()]
119 ]
120 );
121
122 if ($this->isUpdateHistory()) {
124 $this->getWebrId(),
125 "add",
126 [$new_item->getTitle()]
127 );
128 }
129
130 return $new_item;
131 }
static _createEntry(int $a_obj_id, string $a_action, array $a_info_params=[], string $a_obj_type="", string $a_user_comment="", bool $a_update_last=false)
Creates a new history entry for an object.
validateInternalItemTarget(ilWebLinkDraftItem $item)
validateParameter(ilWebLinkBaseParameter $parameter)
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 Vendor\Package\$e, ilHistory\_createEntry(), ilWebLinkBaseItem\getDescription(), ilWebLinkBaseItem\getParameters(), ilWebLinkBaseItem\getTarget(), ilWebLinkBaseItem\getTitle(), getWebrId(), ilWebLinkBaseItem\isActive(), ilWebLinkDraftItem\isInternal(), isUpdateHistory(), ILIAS\Repository\user(), validateInternalItemTarget(), and validateParameter().

Referenced by createAllItemsInDraftContainer().

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

◆ createList()

ilWebLinkDatabaseRepository::createList ( ilWebLinkDraftList  $list)

Implements ilWebLinkRepository.

Definition at line 133 of file class.ilWebLinkDatabaseRepository.php.

134 {
135 $new_list = new ilWebLinkList(
136 $this->getWebrId(),
137 $list->getTitle(),
138 $list->getDescription(),
139 $this->getNewDateTimeImmutable(),
140 $this->getNewDateTimeImmutable(),
141 );
142
143 $this->db->insert(
144 self::LISTS_TABLE,
145 [
146 'webr_id' => ['integer', $new_list->getWebrId()],
147 'title' => ['text', $new_list->getTitle()],
148 'description' => ['text', $new_list->getDescription() ?? ''],
149 'create_date' => ['integer', $new_list->getCreateDate()
150 ->getTimestamp()],
151 'last_update' => ['integer', $new_list->getLastUpdate()
152 ->getTimestamp()],
153 ]
154 );
155
156 if ($this->isUpdateHistory()) {
158 $this->getWebrId(),
159 "add",
160 [$new_list->getTitle()]
161 );
162 }
163
164 return $new_list;
165 }

References ilHistory\_createEntry(), ilWebLinkBaseList\getDescription(), ilWebLinkBaseList\getTitle(), getWebrId(), and isUpdateHistory().

+ Here is the call graph for this function:

◆ deleteAllItems()

ilWebLinkDatabaseRepository::deleteAllItems ( )

Implements ilWebLinkRepository.

Definition at line 469 of file class.ilWebLinkDatabaseRepository.php.

469 : void
470 {
471 $this->db->manipulate(
472 "DELETE FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) . " " .
473 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer')
474 );
475
476 $this->db->manipulate(
477 "DELETE FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) . " " .
478 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer')
479 );
480 }

◆ deleteItemByLinkID()

ilWebLinkDatabaseRepository::deleteItemByLinkID ( int  $link_id)

Implements ilWebLinkRepository.

Definition at line 482 of file class.ilWebLinkDatabaseRepository.php.

482 : void
483 {
484 if ($this->isUpdateHistory()) {
485 $title = $this->getItemByLinkId($link_id)->getTitle();
486 }
487
488 $this->db->manipulate(
489 "DELETE FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) . " " .
490 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer') . " " .
491 "AND link_id = " . $this->db->quote($link_id, 'integer')
492 );
493
494 $this->db->manipulate(
495 "DELETE FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) . " " .
496 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer') . " " .
497 "AND link_id = " . $this->db->quote($link_id, 'integer')
498 );
499
500 if (isset($title)) {
502 $this->getWebrId(),
503 "delete",
504 [$title]
505 );
506 }
507 }

References ilHistory\_createEntry().

+ Here is the call graph for this function:

◆ deleteList()

ilWebLinkDatabaseRepository::deleteList ( )

Implements ilWebLinkRepository.

Definition at line 521 of file class.ilWebLinkDatabaseRepository.php.

521 : void
522 {
523 if ($this->isUpdateHistory()) {
524 $title = $this->getList()->getTitle();
525 }
526
527 $res = $this->db->manipulate(
528 "DELETE FROM " . $this->db->quoteIdentifier(self::LISTS_TABLE) . " " .
529 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer')
530 );
531
532 if (isset($title)) {
534 $this->getWebrId(),
535 "delete",
536 [$title]
537 );
538 }
539 }
$res
Definition: ltiservices.php:69

References $res, and ilHistory\_createEntry().

+ Here is the call graph for this function:

◆ deleteParameterByLinkIdAndParamId()

ilWebLinkDatabaseRepository::deleteParameterByLinkIdAndParamId ( int  $link_id,
int  $param_id 
)

Implements ilWebLinkRepository.

Definition at line 509 of file class.ilWebLinkDatabaseRepository.php.

512 : void {
513 $this->db->manipulate(
514 "DELETE FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) . " " .
515 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer') . " " .
516 "AND link_id = " . $this->db->quote($link_id, 'integer') . " " .
517 "AND param_id = " . $this->db->quote($param_id, 'integer')
518 );
519 }

◆ doesListExist()

ilWebLinkDatabaseRepository::doesListExist ( )

Implements ilWebLinkRepository.

Definition at line 320 of file class.ilWebLinkDatabaseRepository.php.

320 : bool
321 {
322 $res = $this->db->query(
323 "SELECT COUNT(*) AS num FROM " . $this->db->quoteIdentifier(self::LISTS_TABLE) . " " .
324 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer')
325 );
326
327 $row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT);
328
329 return ((int) $row->num) > 0;
330 }

References $res, and ilDBConstants\FETCHMODE_OBJECT.

◆ doesOnlyOneItemExist()

ilWebLinkDatabaseRepository::doesOnlyOneItemExist ( bool  $only_active = false)

Implements ilWebLinkRepository.

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

256 : bool
257 {
258 $query = "SELECT COUNT(*) AS num FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) . " " .
259 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer');
260
261 if ($only_active) {
262 $query .= " AND active = " . $this->db->quote(1, 'integer');
263 }
264
265 $row = $this->db->query($query)
267
268 return $row->num == 1;
269 }
$query

References $query, ilDBConstants\FETCHMODE_OBJECT, and getWebrId().

+ Here is the call graph for this function:

◆ getAllItemsAsContainer()

ilWebLinkDatabaseRepository::getAllItemsAsContainer ( bool  $only_active = false)

Implements ilWebLinkRepository.

Definition at line 181 of file class.ilWebLinkDatabaseRepository.php.

182 {
183 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) . " " .
184 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer');
185
186 if ($only_active) {
187 $query .= " AND active = " . $this->db->quote(1, 'integer');
188 }
189
190 $res = $this->db->query($query);
191 $items = [];
192
193 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
194 $parameters = $this->getParametersByLinkId((int) $row->link_id);
195
196 if ($row->internal) {
197 $class = ilWebLinkItemInternal::class;
198 } else {
199 $class = ilWebLinkItemExternal::class;
200 }
201
202 $items[] = new $class(
203 (int) $row->webr_id,
204 (int) $row->link_id,
205 (string) $row->title,
206 ((string) $row->description) !== '' ? (string) $row->description : null,
207 (string) $row->target,
208 (bool) $row->active,
209 $this->getNewDateTimeImmutable()->setTimestamp((int) $row->create_date),
210 $this->getNewDateTimeImmutable()->setTimestamp((int) $row->last_update),
211 $parameters
212 );
213 }
214
215 return new ilWebLinkItemsContainer(
216 $this->getWebrId(),
217 $items
218 );
219 }

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, getParametersByLinkId(), and getWebrId().

+ Here is the call graph for this function:

◆ getCurrentTime()

ilWebLinkDatabaseRepository::getCurrentTime ( )
protected

Definition at line 612 of file class.ilWebLinkDatabaseRepository.php.

612 : int
613 {
614 return time();
615 }

◆ getItemByLinkId()

ilWebLinkDatabaseRepository::getItemByLinkId ( int  $link_id)

Implements ilWebLinkRepository.

Definition at line 221 of file class.ilWebLinkDatabaseRepository.php.

222 {
223 $query = "SELECT * FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) . " " .
224 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer') . " " .
225 "AND link_id = " . $this->db->quote($link_id, 'integer');
226
227 $res = $this->db->query($query);
228
229 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
230 $parameters = $this->getParametersByLinkId((int) $row->link_id);
231
232 if ($row->internal) {
233 $class = ilWebLinkItemInternal::class;
234 } else {
235 $class = ilWebLinkItemExternal::class;
236 }
237
238 return new $class(
239 (int) $row->webr_id,
240 (int) $row->link_id,
241 (string) $row->title,
242 ((string) $row->description) !== '' ? (string) $row->description : null,
243 (string) $row->target,
244 (bool) $row->active,
245 $this->getNewDateTimeImmutable()->setTimestamp((int) $row->create_date),
246 $this->getNewDateTimeImmutable()->setTimestamp((int) $row->last_update),
247 $parameters
248 );
249 }
250
252 'No item with the given link_id was found in this web link object.'
253 );
254 }
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...

References $query, $res, ilDBConstants\FETCHMODE_OBJECT, getParametersByLinkId(), and getWebrId().

+ Here is the call graph for this function:

◆ getList()

ilWebLinkDatabaseRepository::getList ( )

Implements ilWebLinkRepository.

Definition at line 298 of file class.ilWebLinkDatabaseRepository.php.

299 {
300 $res = $this->db->query(
301 "SELECT * FROM " . $this->db->quoteIdentifier(self::LISTS_TABLE) . " " .
302 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer')
303 );
304
305 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
306 return new ilWebLinkList(
307 (int) $row->webr_id,
308 (string) $row->title,
309 ((string) $row->description) !== '' ? (string) $row->description : null,
310 $this->getNewDateTimeImmutable()->setTimestamp((int) $row->create_date),
311 $this->getNewDateTimeImmutable()->setTimestamp((int) $row->last_update),
312 );
313 }
314
316 'No list exists in this web link object.'
317 );
318 }

References $res, and ilDBConstants\FETCHMODE_OBJECT.

◆ getNewDateTimeImmutable()

ilWebLinkDatabaseRepository::getNewDateTimeImmutable ( )
protected

Definition at line 617 of file class.ilWebLinkDatabaseRepository.php.

617 : DateTimeImmutable
618 {
619 return new DateTimeImmutable();
620 }

◆ getParameterinItemByParamId()

ilWebLinkDatabaseRepository::getParameterinItemByParamId ( ilWebLinkItem  $item,
int  $param_id 
)

Implements ilWebLinkRepository.

Definition at line 271 of file class.ilWebLinkDatabaseRepository.php.

275 $res = $this->db->query(
276 "SELECT * FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) . " " .
277 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer') . " " .
278 "AND link_id = " . $this->db->quote($item->getLinkId(), 'integer') . " " .
279 "AND param_id = " . $this->db->quote($param_id, 'integer')
280 );
281
282 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
283 return new ilWebLinkParameter(
284 $this->user,
285 (int) $row->webr_id,
286 (int) $row->link_id,
287 (int) $row->param_id,
288 (int) $row->value,
289 (string) $row->name
290 );
291 }
292
294 'In the given item of this web link object, no parameter with the given param_id was found.'
295 );
296 }

References ILIAS\Repository\user().

+ Here is the call graph for this function:

◆ getParametersByLinkId()

ilWebLinkDatabaseRepository::getParametersByLinkId ( int  $link_id)
protected
Returns
ilWebLinkParameter[]

Definition at line 544 of file class.ilWebLinkDatabaseRepository.php.

544 : array
545 {
546 $res = $this->db->query(
547 "SELECT * FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) . " " .
548 "WHERE webr_id = " . $this->db->quote($this->getWebrId(), 'integer') . " " .
549 "AND link_id = " . $this->db->quote($link_id, 'integer')
550 );
551 $parameters = [];
552
553 while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) {
554 $parameters[] = new ilWebLinkParameter(
555 $this->user,
556 (int) $row->webr_id,
557 (int) $row->link_id,
558 (int) $row->param_id,
559 (int) $row->value,
560 (string) $row->name
561 );
562 }
563
564 return $parameters;
565 }

References $res, ilDBConstants\FETCHMODE_OBJECT, and ILIAS\Repository\user().

Referenced by getAllItemsAsContainer(), and getItemByLinkId().

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

◆ getWebrId()

ilWebLinkDatabaseRepository::getWebrId ( )

Definition at line 597 of file class.ilWebLinkDatabaseRepository.php.

597 : int
598 {
599 return $this->webr_id;
600 }

Referenced by createAllItemsInDraftContainer(), createItem(), createList(), doesOnlyOneItemExist(), getAllItemsAsContainer(), and getItemByLinkId().

+ Here is the caller graph for this function:

◆ isUpdateHistory()

ilWebLinkDatabaseRepository::isUpdateHistory ( )

Definition at line 602 of file class.ilWebLinkDatabaseRepository.php.

602 : bool
603 {
605 }

Referenced by createItem(), and createList().

+ Here is the caller graph for this function:

◆ setUpdateHistory()

ilWebLinkDatabaseRepository::setUpdateHistory ( bool  $update_history)

Definition at line 607 of file class.ilWebLinkDatabaseRepository.php.

607 : void
608 {
609 $this->update_history = $update_history;
610 }

◆ updateItem()

ilWebLinkDatabaseRepository::updateItem ( ilWebLinkItem  $item,
ilWebLinkDraftItem  $drafted_item 
)

Updates an item.

New parameters added as drafts update the parameter they replace, or else are created fresh. Current parameters of the item not added to the draft are deleted.

Implements ilWebLinkRepository.

Definition at line 332 of file class.ilWebLinkDatabaseRepository.php.

335 : void {
336 if ($item->getWebrId() !== $this->getWebrId()) {
338 'Cannot update an item from a different web link object.'
339 );
340 }
341
342 $this->validateInternalItemTarget($drafted_item);
343
344 $this->db->update(
345 self::ITEMS_TABLE,
346 [
347 'title' => ['text', $drafted_item->getTitle()],
348 'description' => ['text', $drafted_item->getDescription() ?? ''],
349 'target' => ['text', $drafted_item->getTarget()],
350 'active' => ['integer', (int) $drafted_item->isActive()],
351 'internal' => ['integer', (int) $drafted_item->isInternal()],
352 'last_update' => ['integer', $this->getCurrentTime()]
353 ],
354 [
355 'webr_id' => ['integer', $item->getWebrId()],
356 'link_id' => ['integer', $item->getLinkId()]
357 ]
358 );
359
360 /*
361 * drafted parameters of the drafted item are either created or
362 * update an existing parameter
363 */
364 $param_ids = [];
365 foreach ($drafted_item->getParameters() as $parameter) {
366 if ($parameter instanceof ilWebLinkParameter) {
367 $param_ids[] = $parameter->getParamId();
368 continue;
369 }
370
371 try {
372 $this->validateParameter($parameter);
373 } catch (Exception $e) {
374 continue;
375 }
376
377 if ($old_parameter = $parameter->getOldParameter()) {
378 if (
379 $old_parameter->getLinkId() !== $item->getLinkId() ||
380 $old_parameter->getWebrId() !== $item->getWebrId()
381 ) {
383 'Cannot update a parameter from a different item.'
384 );
385 }
386
387 $this->db->update(
388 self::PARAMS_TABLE,
389 [
390 'name' => ['text', $drafted_item->getTitle()],
391 'value' => ['integer', $drafted_item->getTitle()]
392 ],
393 [
394 'webr_id' => ['integer', $item->getWebrId()],
395 'link_id' => ['integer', $item->getLinkId()],
396 'param_id' => ['integer', $parameter->getOldParameter()
397 ->getParamId()],
398 ]
399 );
400 continue;
401 }
402
403 $next_param_id = $this->db->nextId(self::PARAMS_TABLE);
404 $this->db->insert(
405 self::PARAMS_TABLE,
406 [
407 'webr_id' => ['integer', $this->getWebrId()],
408 'link_id' => ['integer', $item->getLinkId()],
409 'param_id' => ['integer', $next_param_id],
410 'name' => ['text', $parameter->getName()],
411 'value' => ['integer', $parameter->getValue()]
412 ]
413 );
414 }
415
416 /*
417 * parameters attached to the original item but not the drafted item
418 * are deleted
419 */
420 foreach ($item->getParameters() as $parameter) {
421 if (!in_array($parameter->getParamId(), $param_ids)) {
423 $item->getLinkId(),
424 $parameter->getParamId()
425 );
426 }
427 }
428
429 if ($this->isUpdateHistory()) {
431 $this->getWebrId(),
432 "update",
433 [$item->getTitle()]
434 );
435 }
436 }
deleteParameterByLinkIdAndParamId(int $link_id, int $param_id)

◆ updateList()

ilWebLinkDatabaseRepository::updateList ( ilWebLinkList  $list,
ilWebLinkDraftList  $drafted_list 
)

Implements ilWebLinkRepository.

Definition at line 438 of file class.ilWebLinkDatabaseRepository.php.

441 : void {
442 if ($list->getWebrId() !== $this->getWebrId()) {
444 'Cannot update a list from a different web link object.'
445 );
446 }
447
448 $this->db->update(
449 self::LISTS_TABLE,
450 [
451 'title' => ['text', $drafted_list->getTitle()],
452 'description' => ['text', $drafted_list->getDescription() ?? ''],
453 'last_update' => ['integer', $this->getCurrentTime()]
454 ],
455 [
456 'webr_id' => ['integer', $list->getWebrId()]
457 ]
458 );
459
460 if ($this->isUpdateHistory()) {
462 $this->getWebrId(),
463 "update",
464 [$list->getTitle()]
465 );
466 }
467 }

◆ validateInternalItemTarget()

ilWebLinkDatabaseRepository::validateInternalItemTarget ( ilWebLinkDraftItem  $item)
protected
Exceptions
ilWebLinkDatabaseRepositoryException

Definition at line 585 of file class.ilWebLinkDatabaseRepository.php.

585 : void
586 {
587 if (
588 $item->isInternal() &&
590 ) {
592 'The target of this internal link item is not internal.'
593 );
594 }
595 }
static isInternalLink(string $a_value)

References ilWebLinkBaseItem\getTarget(), ilWebLinkDraftItem\isInternal(), and ilLinkInputGUI\isInternalLink().

Referenced by createItem().

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

◆ validateParameter()

ilWebLinkDatabaseRepository::validateParameter ( ilWebLinkBaseParameter  $parameter)
protected
Exceptions
ilWebLinkDatabaseRepositoryException

Definition at line 570 of file class.ilWebLinkDatabaseRepository.php.

570 : void
571 {
572 if (!in_array(
573 $parameter->getValue(),
575 )) {
577 'The value of the parameter you are trying to create is invalid.'
578 );
579 }
580 }
const VALUES
TODO Once the GUI is updated, undefined can be dropped.

References ilWebLinkBaseParameter\getValue(), and ilWebLinkBaseParameter\VALUES.

Referenced by createItem().

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

Field Documentation

◆ $db

ilDBInterface ilWebLinkDatabaseRepository::$db
protected

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

◆ $update_history

bool ilWebLinkDatabaseRepository::$update_history
protected

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

Referenced by __construct().

◆ $user

ilObjUser ilWebLinkDatabaseRepository::$user
protected

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

◆ $webr_id

int ilWebLinkDatabaseRepository::$webr_id
protected

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

Referenced by __construct().

◆ ITEMS_TABLE

◆ LISTS_TABLE

const ilWebLinkDatabaseRepository::LISTS_TABLE = 'webr_lists'

◆ PARAMS_TABLE


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