ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilWebResourceEditableLinkTableGUI.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
23 
30 {
31  protected Refinery $refinery;
32  protected HTTPService $http;
33  protected ilSetting $settings;
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  'Modules/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) {
300  continue;
301  }
302  $options[] = ilWebLinkBaseParameter::VALUES_TEXT[$identifier];
303  }
304  $this->tpl->setVariable(
305  'SEL_DYN_VAL',
307  $a_set['value'] ?? 0,
308  'links[' . $a_set['id'] . '][val]',
309  /*
310  array_map(function ($s) {
311  return $this->lng->txt($s);
312  }, ilWebLinkBaseParameter::VALUES_TEXT),
313  */
314  $options,
315  false,
316  true
317  )
318  );
319  $this->tpl->parseCurrentBlock();
320  }
321 
322  if (in_array($a_set['id'], $this->getInvalidLinks())) {
323  $this->tpl->setVariable('CSS_ROW', 'warn');
324  }
325 
326  // Check
327  $this->tpl->setVariable('VAL_ID', $a_set['id']);
328  $this->tpl->setVariable(
329  'VAL_CHECKBOX',
331  false,
332  'link_ids[]',
333  (string) $a_set['id']
334  )
335  );
336 
337  // Column title
338  $this->tpl->setVariable('TXT_TITLE', $this->lng->txt('title'));
339  $this->tpl->setVariable(
340  'VAL_TITLE',
342  $a_set['title']
343  )
344  );
345  $this->tpl->setVariable('TXT_DESC', $this->lng->txt('description'));
346  $this->tpl->setVariable(
347  'VAL_DESC',
349  $a_set['description'] ?? ''
350  )
351  );
352 
353  // Column Target
354  $this->tpl->setVariable('TXT_TARGET', $this->lng->txt('target'));
355  }
356 }
setData(array $a_data)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setFormAction(string $a_form_action, bool $a_multipart=false)
setEnableTitle(bool $a_enabletitle)
if($clientAssertionType !='urn:ietf:params:oauth:client-assertion-type:jwt-bearer'|| $grantType !='client_credentials') $parts
Definition: ltitoken.php:64
addCommandButton(string $a_cmd, string $a_text, string $a_onclick='', string $a_id="", string $a_class="")
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
setSelectAllCheckbox(string $a_select_all_checkbox, bool $a_select_all_on_top=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)
static prepareFormOutput($a_str, bool $a_strip=false)
__construct(?object $a_parent_obj, string $a_parent_cmd)
TODO Move most of this stuff to an init method.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static http()
Fetches the global http state from ILIAS.
setRowTemplate(string $a_template, string $a_template_dir="")
Set row template.
$param
Definition: xapitoken.php:46
static formCheckbox(bool $checked, string $varname, string $value, bool $disabled=false)
setTitle(string $a_title, string $a_icon="", string $a_icon_alt="")
$rows
Definition: xhr_table.php:10
setEnableNumInfo(bool $a_val)
__construct(Container $dic, ilPlugin $plugin)
const VALUES
TODO Once the GUI is updated, undefined can be dropped.
const VALUES_TEXT
Keys of the language variables to the possible values, e.g.
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)
addMultiCommand(string $a_cmd, string $a_text)
setEnableHeader(bool $a_enableheader)