ILIAS  release_8 Revision v8.24
class.ilWebResourceLinkTableGUI.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
26{
27 protected bool $editable = false;
28
29 protected int $link_sort_mode;
30 protected bool $link_sort_enabled = false;
31
34
38 public function __construct(
39 ?object $a_parent_obj,
40 string $a_parent_cmd,
41 bool $a_sorting = false
42 ) {
43 global $DIC;
44
45 parent::__construct($a_parent_obj, $a_parent_cmd);
46
47 $this->access = $DIC->access();
48 $this->web_link_repo = new ilWebLinkDatabaseRepository(
49 $this->getParentObject()->getObject()->getId()
50 );
51
52 // Initialize
53 if ($this->access->checkAccess(
54 'write',
55 '',
56 $this->getParentObject()->getObject()->getRefId()
57 )) {
58 $this->editable = true;
59 }
60
61 $this->enableLinkSorting($a_sorting);
62
63 $this->setTitle($this->lng->txt('web_resources'));
64
65 if ($this->isEditable()) {
66 if ($this->isLinkSortingEnabled()) {
67 $this->setLimit(9999);
68 $this->addColumn($this->lng->txt('position'), '', '10px');
69 $this->addColumn($this->lng->txt('title'), '', '90%');
70 $this->addColumn('', '', '10%');
71
72 $this->addMultiCommand(
73 'saveSorting',
74 $this->lng->txt('sorting_save')
75 );
76 } else {
77 $this->addColumn($this->lng->txt('title'), '', '90%');
78 $this->addColumn('', '', '10%');
79 }
80 } else {
81 $this->addColumn($this->lng->txt('title'), '', '100%');
82 }
83
84 $this->setEnableHeader(true);
85 $this->setFormAction(
86 $this->ctrl->getFormAction($this->getParentObject())
87 );
88 $this->setRowTemplate("tpl.webr_link_row.html", 'Modules/WebResource');
89 $this->setEnableTitle(true);
90 $this->setEnableNumInfo(false);
91 }
92
93 public function enableLinkSorting(bool $a_status): void
94 {
95 $this->link_sort_enabled = $a_status;
96 }
97
98 public function isLinkSortingEnabled(): bool
99 {
101 }
102
103 public function parse(): void
104 {
105 $rows = [];
106
107 $items = $this->web_link_repo->getAllItemsAsContainer(true)
108 ->sort()
109 ->getItems();
110
111 $counter = 1;
112 foreach ($items as $item) {
113 $tmp['position'] = ($counter++) * 10;
114 $tmp['title'] = $item->getTitle();
115 $tmp['description'] = $item->getDescription();
116 $tmp['target'] = $item->getTarget();
117 $tmp['link_id'] = $item->getLinkId();
118 $tmp['internal'] = $item->isInternal();
119
120 $rows[] = $tmp;
121 }
122 $this->setData($rows);
123 }
124
125 protected function fillRow(array $a_set): void
126 {
127 $this->ctrl->setParameterByClass(
128 get_class($this->getParentObject()),
129 'link_id',
130 $a_set['link_id']
131 );
132
133 $this->tpl->setVariable('TITLE', $a_set['title']);
134 if ($a_set['description']) {
135 $this->tpl->setVariable('DESCRIPTION', $a_set['description']);
136 }
137 // $this->tpl->setVariable('TARGET',$a_set['target']);
138 $this->tpl->setVariable(
139 'TARGET',
140 $this->ctrl->getLinkTarget($this->parent_obj, "callLink")
141 );
142
143 if (!$a_set['internal']) {
144 $this->tpl->setVariable('FRAME', ' target="_blank"');
145 $this->tpl->touchBlock('noopener');
146 }
147
148 if (!$this->isEditable()) {
149 return;
150 }
151
152 if ($this->isLinkSortingEnabled()) {
153 $this->tpl->setVariable('VAL_POS', $a_set['position']);
154 $this->tpl->setVariable('VAL_ITEM', $a_set['link_id']);
155 }
156
157 $actions = new ilAdvancedSelectionListGUI();
158 $actions->setSelectionHeaderClass("small");
159 $actions->setItemLinkClass("xsmall");
160
161 $actions->setListTitle($this->lng->txt('actions'));
162 $actions->setId((string) $a_set['link_id']);
163
164 $actions->addItem(
165 $this->lng->txt('edit'),
166 '',
167 $this->ctrl->getLinkTargetByClass(
168 get_class($this->getParentObject()),
169 'editLink'
170 )
171 );
172 $actions->addItem(
173 $this->lng->txt('webr_deactivate'),
174 '',
175 $this->ctrl->getLinkTargetByClass(
176 get_class($this->getParentObject()),
177 'deactivateLink'
178 )
179 );
180 $actions->addItem(
181 $this->lng->txt('delete'),
182 '',
183 $this->ctrl->getLinkTargetByClass(
184 get_class($this->getParentObject()),
185 'confirmDeleteLink'
186 )
187 );
188 $this->tpl->setVariable('ACTION_HTML', $actions->getHTML());
189 }
190
191 protected function isEditable(): bool
192 {
193 return $this->editable;
194 }
195}
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...
setLimit(int $a_limit=0, int $a_default_limit=0)
set max.
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableNumInfo(bool $a_val)
setEnableTitle(bool $a_enabletitle)
addMultiCommand(string $a_cmd, string $a_text)
setFormAction(string $a_form_action, bool $a_multipart=false)
addColumn(string $a_text, string $a_sort_field="", string $a_width="", bool $a_is_checkbox_action_column=false, string $a_class="", string $a_tooltip="", bool $a_tooltip_with_html=false)
setEnableHeader(bool $a_enableheader)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setData(array $a_data)
Set table data.
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...
__construct(?object $a_parent_obj, string $a_parent_cmd, bool $a_sorting=false)
TODO Move most of this stuff to an init method.
fillRow(array $a_set)
Standard Version of Fill Row.
global $DIC
Definition: feed.php:28
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...
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$rows
Definition: xhr_table.php:10