19declare(strict_types=1);
38 $this->db =
$DIC->database();
39 $this->
user = $DIC->user();
45 $next_link_id = $this->db->nextId(self::ITEMS_TABLE);
52 $next_param_id = $this->db->nextId(self::PARAMS_TABLE);
56 }
catch (Exception
$e) {
66 $parameter->getValue(),
73 'webr_id' => [
'integer', $new_parameter->getWebrId()],
74 'link_id' => [
'integer', $new_parameter->getLinkId()],
75 'param_id' => [
'integer', $new_parameter->getParamId()],
76 'name' => [
'text', $new_parameter->getName()],
77 'value' => [
'integer', $new_parameter->getValue()]
81 $new_parameters[] = $new_parameter;
86 $class = ilWebLinkItemInternal::class;
88 $class = ilWebLinkItemExternal::class;
91 $new_item =
new $class(
98 $this->getNewDateTimeImmutable(),
99 $this->getNewDateTimeImmutable(),
106 'internal' => [
'integer', (
int) $new_item->isInternal()],
107 'webr_id' => [
'integer', $new_item->getWebrId()],
108 'link_id' => [
'integer', $new_item->getLinkId()],
109 'title' => [
'text', $new_item->getTitle()],
110 'description' => [
'text', $new_item->getDescription() ??
''],
111 'target' => [
'text', $new_item->getTarget()],
112 'active' => [
'integer', (
int) $new_item->isActive()],
113 'create_date' => [
'integer', $new_item->getCreateDate()
115 'last_update' => [
'integer', $new_item->getLastUpdate()
129 $this->getNewDateTimeImmutable(),
130 $this->getNewDateTimeImmutable(),
136 'webr_id' => [
'integer', $new_list->getWebrId()],
137 'title' => [
'text', $new_list->getTitle()],
138 'description' => [
'text', $new_list->getDescription() ??
''],
139 'create_date' => [
'integer', $new_list->getCreateDate()
141 'last_update' => [
'integer', $new_list->getLastUpdate()
165 $query =
"SELECT * FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) .
" " .
166 "WHERE webr_id = " . $this->db->quote($this->
getWebrId(),
'integer');
169 $query .=
" AND active = " . $this->db->quote(1,
'integer');
172 $res = $this->db->query($query);
178 if ($row->internal) {
179 $class = ilWebLinkItemInternal::class;
181 $class = ilWebLinkItemExternal::class;
184 $items[] =
new $class(
187 (
string) $row->title,
188 ((
string) $row->description) !==
'' ? (
string) $row->description :
null,
189 (
string) $row->target,
191 $this->getNewDateTimeImmutable()->setTimestamp((
int) $row->create_date),
192 $this->getNewDateTimeImmutable()->setTimestamp((
int) $row->last_update),
205 $query =
"SELECT * FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) .
" " .
206 "WHERE webr_id = " . $this->db->quote($this->
getWebrId(),
'integer') .
" " .
207 "AND link_id = " . $this->db->quote($link_id,
'integer');
209 $res = $this->db->query($query);
214 if ($row->internal) {
215 $class = ilWebLinkItemInternal::class;
217 $class = ilWebLinkItemExternal::class;
223 (
string) $row->title,
224 ((
string) $row->description) !==
'' ? (
string) $row->description :
null,
225 (
string) $row->target,
227 $this->getNewDateTimeImmutable()->setTimestamp((
int) $row->create_date),
228 $this->getNewDateTimeImmutable()->setTimestamp((
int) $row->last_update),
234 'No item with the given link_id was found in this web link object.'
240 $query =
"SELECT COUNT(*) AS num FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) .
" " .
241 "WHERE webr_id = " . $this->db->quote($this->
getWebrId(),
'integer');
244 $query .=
" AND active = " . $this->db->quote(1,
'integer');
247 $row = $this->db->query($query)
250 return $row->num == 1;
257 $res = $this->db->query(
258 "SELECT * FROM " . $this->db->quoteIdentifier(self::
PARAMS_TABLE) .
" " .
259 "WHERE webr_id = " . $this->db->quote($this->
getWebrId(),
'integer') .
" " .
260 "AND link_id = " . $this->db->quote($item->getLinkId(),
'integer') .
" " .
261 "AND param_id = " . $this->db->quote($param_id,
'integer')
269 (
int) $row->param_id,
276 'In the given item of this web link object, no parameter with the given param_id was found.'
282 $res = $this->db->query(
283 "SELECT * FROM " . $this->db->quoteIdentifier(self::LISTS_TABLE) .
" " .
284 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer')
290 (
string) $row->title,
291 ((
string) $row->description) !==
'' ? (
string) $row->description :
null,
292 $this->getNewDateTimeImmutable()->setTimestamp((
int) $row->create_date),
293 $this->getNewDateTimeImmutable()->setTimestamp((
int) $row->last_update),
298 'No list exists in this web link object.'
304 $res = $this->db->query(
305 "SELECT COUNT(*) AS num FROM " . $this->db->quoteIdentifier(self::LISTS_TABLE) .
" " .
306 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer')
311 return ((
int) $row->num) > 0;
318 if ($item->getWebrId() !== $this->getWebrId()) {
320 'Cannot update an item from a different web link object.'
324 $this->validateInternalItemTarget($drafted_item);
329 'title' => [
'text', $drafted_item->getTitle()],
330 'description' => [
'text', $drafted_item->getDescription() ??
''],
331 'target' => [
'text', $drafted_item->getTarget()],
332 'active' => [
'integer', (
int) $drafted_item->isActive()],
333 'internal' => [
'integer', (
int) $drafted_item->isInternal()],
334 'last_update' => [
'integer', $this->getCurrentTime()]
337 'webr_id' => [
'integer', $item->
getWebrId()],
338 'link_id' => [
'integer', $item->
getLinkId()]
347 foreach ($drafted_item->getParameters() as $parameter) {
349 $param_ids[] = $parameter->getParamId();
354 $this->validateParameter($parameter);
355 }
catch (Exception
$e) {
359 if ($old_parameter = $parameter->getOldParameter()) {
361 $old_parameter->getLinkId() !== $item->
getLinkId() ||
362 $old_parameter->getWebrId() !== $item->
getWebrId()
365 'Cannot update a parameter from a different item.'
372 'name' => [
'text', $drafted_item->getTitle()],
373 'value' => [
'integer', $drafted_item->getTitle()]
376 'webr_id' => [
'integer', $item->
getWebrId()],
377 'link_id' => [
'integer', $item->
getLinkId()],
378 'param_id' => [
'integer', $parameter->getOldParameter()
385 $next_param_id = $this->db->nextId(self::PARAMS_TABLE);
389 'webr_id' => [
'integer', $this->getWebrId()],
390 'link_id' => [
'integer', $item->
getLinkId()],
391 'param_id' => [
'integer', $next_param_id],
392 'name' => [
'text', $parameter->getName()],
393 'value' => [
'integer', $parameter->getValue()]
403 if (!in_array($parameter->getParamId(), $param_ids)) {
404 $this->deleteParameterByLinkIdAndParamId(
406 $parameter->getParamId()
416 if ($list->getWebrId() !== $this->getWebrId()) {
418 'Cannot update a list from a different web link object.'
425 'title' => [
'text', $drafted_list->getTitle()],
426 'description' => [
'text', $drafted_list->getDescription() ??
''],
427 'last_update' => [
'integer', $this->getCurrentTime()]
430 'webr_id' => [
'integer', $list->getWebrId()]
437 $this->db->manipulate(
438 "DELETE FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) .
" " .
439 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer')
442 $this->db->manipulate(
443 "DELETE FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) .
" " .
444 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer')
450 $this->db->manipulate(
451 "DELETE FROM " . $this->db->quoteIdentifier(self::ITEMS_TABLE) .
" " .
452 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer') .
" " .
453 "AND link_id = " . $this->db->quote($link_id,
'integer')
456 $this->db->manipulate(
457 "DELETE FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) .
" " .
458 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer') .
" " .
459 "AND link_id = " . $this->db->quote($link_id,
'integer')
467 $this->db->manipulate(
468 "DELETE FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) .
" " .
469 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer') .
" " .
470 "AND link_id = " . $this->db->quote($link_id,
'integer') .
" " .
471 "AND param_id = " . $this->db->quote($param_id,
'integer')
477 $res = $this->db->manipulate(
478 "DELETE FROM " . $this->db->quoteIdentifier(self::LISTS_TABLE) .
" " .
479 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer')
488 $res = $this->db->query(
489 "SELECT * FROM " . $this->db->quoteIdentifier(self::PARAMS_TABLE) .
" " .
490 "WHERE webr_id = " . $this->db->quote($this->getWebrId(),
'integer') .
" " .
491 "AND link_id = " . $this->db->quote($link_id,
'integer')
500 (
int) $row->param_id,
505 $this->validateParameter($parameter);
506 }
catch (Exception
$e) {
509 $parameters[] = $parameter;
525 'The value of the parameter you are trying to create is invalid.'
537 !$this->isInternalLink($item->
getTarget())
540 'The target of this internal link item is not internal.'
552 return $this->webr_id;
562 return new DateTimeImmutable();
Base class for parameters attached to Web Link items.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
deleteParameterByLinkIdAndParamId(int $link_id, int $param_id)
validateInternalItemTarget(ilWebLinkDraftItem $item)
doesOnlyOneItemExist(bool $only_active=false)
validateParameter(ilWebLinkBaseParameter $parameter)
createAllItemsInDraftContainer(ilWebLinkDraftItemsContainer $container)
getParametersByLinkId(int $link_id)
getItemByLinkId(int $link_id)
__construct(int $webr_id)
createList(ilWebLinkDraftList $list)
updateItem(ilWebLinkItem $item, ilWebLinkDraftItem $drafted_item)
Updates an item.
const string PARAMS_TABLE
getNewDateTimeImmutable()
deleteItemByLinkID(int $link_id)
getAllItemsAsContainer(bool $only_active=false)
isInternalLink(string $value)
getParameterinItemByParamId(ilWebLinkItem $item, int $param_id)
updateList(ilWebLinkList $list, ilWebLinkDraftList $drafted_list)
createItem(ilWebLinkDraftItem $item)
Creates a new item, complete with parameters.
Draft class for creating and updating a Web Link item.
Container class for drafted Web Link items.
Draft class for creating or updating a Web Link list.
Immutable class for Web Link items.
Immutable container class for Web Link items.
Immutable class for Web Link lists.
Immutable class for parameters attached to Web Link items.
if(!file_exists('../ilias.ini.php'))