ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebResourceEditableLinkTableGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use ILIAS\Refinery\Factory as Refinery;
22use ILIAS\HTTP\Services as HTTPService;
23
30{
31 protected Refinery $refinery;
32 protected HTTPService $http;
34
36 protected array $invalid = [];
37
41 public function __construct(?object $a_parent_obj, string $a_parent_cmd)
42 {
43 global $DIC;
44
45 parent::__construct($a_parent_obj, $a_parent_cmd);
46
47 $this->http = $DIC->http();
48 $this->refinery = $DIC->refinery();
49 $this->settings = $DIC->settings();
50 $this->web_link_repo = new ilWebLinkDatabaseRepository(
51 $this->getParentObject()->getObject()->getId()
52 );
53
54 $this->setTitle($this->lng->txt('webr_edit_links'));
55 $this->addColumn('', '', '1px');
56 $this->addColumn($this->lng->txt('title'), 'title', '25%');
57 $this->addColumn($this->lng->txt('target'), 'target', '25%');
58 $this->addColumn($this->lng->txt('webr_active'), 'active');
59
60 $this->setEnableHeader(true);
61 $this->setFormAction(
62 $this->ctrl->getFormAction($this->getParentObject())
63 );
64 $this->setRowTemplate(
65 "tpl.webr_editable_link_row.html",
66 'components/ILIAS/WebResource'
67 );
68 $this->setEnableTitle(true);
69 $this->setEnableNumInfo(true);
70 $this->setSelectAllCheckbox('link_ids');
71
72 $this->addMultiCommand('confirmDeleteLink', $this->lng->txt('delete'));
73 $this->addCommandButton('updateLinks', $this->lng->txt('save'));
74 }
75
76 public function setInvalidLinks(array $a_links): void
77 {
78 $this->invalid = $a_links;
79 }
80
81 public function getInvalidLinks(): array
82 {
83 return $this->invalid;
84 }
85
89 public function parseSelectedLinks(array $a_link_ids): void
90 {
91 $rows = [];
92
93 $items = $this->web_link_repo->getAllItemsAsContainer()
94 ->sort()
95 ->getItems();
96
97 foreach ($items as $item) {
98 if (!in_array($item->getLinkId(), $a_link_ids)) {
99 continue;
100 }
101
102 $tmp['id'] = $item->getLinkId();
103 $tmp['title'] = $item->getTitle();
104 $tmp['description'] = $item->getDescription();
105 $tmp['target'] = $item->getTarget();
106 $tmp['active'] = $item->isActive();
107 $tmp['params'] = [];
108
109 $rows[] = $tmp;
110 }
111 $this->setData($rows);
112 }
113
114 public function updateFromPost(): void
115 {
116 $request_link_info = (array) (
117 $this->http->request()
118 ->getParsedBody()['links'] ?? []
119 );
120
121 $rows = [];
122 foreach ($this->getData() as $link) {
123 $link_id = $link['id'];
124 $tmp = $link;
125 $tmp['title'] = $request_link_info[$link_id]['title'] ?? null;
126 $tmp['description'] = $request_link_info[$link_id]['desc'] ?? null;
127 $tmp['target'] = $request_link_info[$link_id]['tar'] ?? null;
128 $tmp['active'] = $request_link_info[$link_id]['act'] ?? null;
129 $tmp['value'] = $request_link_info[$link_id]['val'] ?? null;
130 $tmp['name'] = $request_link_info[$link_id]['nam'] ?? null;
131 $tmp['params'] = [];
132 $rows[] = $tmp;
133 }
134 $this->setData($rows);
135 }
136
137 public function parse(): void
138 {
139 $rows = [];
140
141 $items = $this->web_link_repo->getAllItemsAsContainer()
142 ->sort()
143 ->getItems();
144
145 foreach ($items as $item) {
146 $tmp['id'] = $item->getLinkId();
147 $tmp['title'] = $item->getTitle();
148 $tmp['description'] = $item->getDescription();
149 $tmp['target'] = $item->getTarget();
150 $tmp['active'] = $item->isActive();
151 $tmp['internal'] = $item->isInternal();
152
157 $tmp['params'] = array_map(
158 function ($p) {
159 return [
160 'info' => $p->getInfo(),
161 'param_id' => $p->getParamId()
162 ];
163 },
164 $item->getParameters()
165 );
166
167 $rows[] = $tmp;
168 }
169 $this->setData($rows);
170 }
171
172 protected function fillRow(array $a_set): void
173 {
174 if (!$a_set['internal']) {
175 $this->tpl->setCurrentBlock('external');
176 $this->tpl->setVariable('VAL_ID', $a_set['id']);
177 $this->tpl->setVariable(
178 'VAL_TARGET',
180 $a_set['target']
181 )
182 );
183 } else {
184 $this->ctrl->setParameterByClass(
185 'ilinternallinkgui',
186 'postvar',
187 'tar_' . $a_set['id']
188 );
189 $trigger_link = [
190 get_class($this->parent_obj),
191 'ilinternallinkgui'
192 ];
193 $trigger_link = $this->ctrl->getLinkTargetByClass(
194 $trigger_link,
195 '',
196 '',
197 true,
198 false
199 );
200 $this->ctrl->setParameterByClass(
201 'ilinternallinkgui',
202 'postvar',
203 ''
204 );
205
206 $this->tpl->setCurrentBlock('internal');
207 $this->tpl->setVariable('VAL_ID', $a_set['id']);
208 $this->tpl->setVariable('VAL_TRIGGER_INTERNAL', $trigger_link);
209 $this->tpl->setVariable(
210 'TXT_TRIGGER_INTERNAL',
211 $this->lng->txt('edit')
212 );
213
214 // info about current link
215 if ($a_set['target']) {
216 $parts = explode('|', $a_set['target']);
217
218 $this->tpl->setVariable('VAL_INTERNAL_TYPE', $parts[0]);
219 $this->tpl->setVariable('VAL_INTERNAL_ID', $parts[1]);
220
221 $parts = ilLinkInputGUI::getTranslatedValue($a_set['target']);
222 if ($parts !== []) {
223 $this->tpl->setVariable(
224 'TXT_TRIGGER_INFO',
225 $parts['type'] . ' "' . $parts['name'] . '"'
226 );
227 }
228 }
229 }
230
231 $this->tpl->parseCurrentBlock();
232
233 // Active
234 $this->tpl->setVariable(
235 'VAL_ACTIVE',
237 $a_set['active'],
238 'links[' . $a_set['id'] . '][act]',
239 '1'
240 )
241 );
242
243 // Dynamic parameters
244 foreach ($a_set['params'] as $param) {
245 $this->tpl->setCurrentBlock('dyn_del_row');
246 $this->tpl->setVariable('TXT_DYN_DEL', $this->lng->txt('delete'));
247 $this->ctrl->setParameterByClass(
248 get_class($this->getParentObject()),
249 'param_id',
250 $param['param_id']
251 );
252 $this->ctrl->setParameterByClass(
253 get_class($this->getParentObject()),
254 'link_id',
255 $a_set['id']
256 );
257 $this->tpl->setVariable(
258 'DYN_DEL_LINK',
259 $this->ctrl->getLinkTarget(
260 $this->getParentObject(),
261 'deleteParameter'
262 )
263 );
264 $this->tpl->setVariable(
265 'VAL_DYN',
266 $param['info']
267 );
268 $this->tpl->parseCurrentBlock();
269 }
270 if ($a_set['params']) {
271 $this->tpl->setCurrentBlock('dyn_del_rows');
272 $this->tpl->setVariable(
273 'TXT_EXISTING',
274 $this->lng->txt('links_existing_params')
275 );
276 $this->tpl->parseCurrentBlock();
277 }
278
279 if ($this->settings->get('links_dynamic')) {
280 $this->tpl->setCurrentBlock('dyn_add');
281 $this->tpl->setVariable(
282 'TXT_DYN_ADD',
283 $this->lng->txt('links_add_param')
284 );
285
286 $this->tpl->setVariable(
287 'TXT_DYN_NAME',
288 $this->lng->txt('links_name')
289 );
290 $this->tpl->setVariable(
291 'TXT_DYN_VALUE',
292 $this->lng->txt('links_value')
293 );
294 $this->tpl->setVariable('VAL_DYN_NAME', $a_set['name'] ?? '');
295 $this->tpl->setVariable('DYN_ID', $a_set['id']);
296
297 $options = [];
298 foreach (ilWebLinkBaseParameter::VALUES as $name => $identifier) {
299 $options[$identifier] = $this->lng->txt(ilWebLinkBaseParameter::VALUES_TEXT[$identifier]);
300 }
301 $this->tpl->setVariable(
302 'SEL_DYN_VAL',
304 $a_set['value'] ?? 0,
305 'links[' . $a_set['id'] . '][val]',
306 $options,
307 false,
308 true
309 )
310 );
311 $this->tpl->parseCurrentBlock();
312 }
313
314 if (in_array($a_set['id'], $this->getInvalidLinks())) {
315 $this->tpl->setVariable('CSS_ROW', 'warn');
316 }
317
318 // Check
319 $this->tpl->setVariable('VAL_ID', $a_set['id']);
320 $this->tpl->setVariable(
321 'VAL_CHECKBOX',
323 false,
324 'link_ids[]',
325 (string) $a_set['id']
326 )
327 );
328
329 // Column title
330 $this->tpl->setVariable('TXT_TITLE', $this->lng->txt('title'));
331 $this->tpl->setVariable(
332 'VAL_TITLE',
334 $a_set['title']
335 )
336 );
337 $this->tpl->setVariable('TXT_DESC', $this->lng->txt('description'));
338 $this->tpl->setVariable(
339 'VAL_DESC',
341 $a_set['description'] ?? ''
342 )
343 );
344
345 // Column Target
346 $this->tpl->setVariable('TXT_TARGET', $this->lng->txt('target'));
347 }
348}
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
static prepareFormOutput($a_str, bool $a_strip=false)
static formSelect( $selected, string $varname, array $options, bool $multiple=false, bool $direct_text=false, int $size=0, string $style_class="", array $attribs=[], bool $disabled=false)
Builds a select form field with options and shows the selected option first.
static getTranslatedValue(string $a_value)
ILIAS Setting Class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
setEnableNumInfo(bool $a_val)
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
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)
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=false)
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
setData(array $a_data)
Set table data.
const array VALUES_TEXT
Keys of the language variables to the possible values, e.g.
const array VALUES
TODO Once the GUI is updated, undefined can be dropped.
fillRow(array $a_set)
Standard Version of Fill Row.
__construct(?object $a_parent_obj, string $a_parent_cmd)
TODO Move most of this stuff to an init method.
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:61
static http()
Fetches the global http state from ILIAS.
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
global $DIC
Definition: shib_login.php:26
$param
Definition: xapitoken.php:46