ILIAS  release_8 Revision v8.24
class.ilDclDetailedViewGUI.php
Go to the documentation of this file.
1<?php
2
23{
27 protected ilDclTable $table;
28 protected int $tableview_id;
30 protected int $next_record_id = 0;
31 protected int $prev_record_id = 0;
32 protected int $current_record_position = 0;
33 protected array $record_ids = [];
34 protected bool $is_enabled_paging = true;
35 protected ilLanguage $lng;
38
41
44 protected int $record_id;
47
48 private function init(
50 ): void {
51 $this->dclUi = $adapter->getDataCollectionUi();
52 $this->dclAccess = $adapter->getDataCollectionAccess();
53 $this->dclEndPoint = $adapter->getDataCollectionEndpoint();
54 }
55
59 public function __construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview_id)
60 {
61 global $DIC;
63
64 $tpl = $DIC->ui()->mainTemplate();
65 $this->ctrl = $DIC->ctrl();
66 $this->dcl_gui_object = $a_dcl_object;
67 $this->lng = $DIC->language();
68 $this->http = $DIC->http();
69 $this->refinery = $DIC->refinery();
70 $this->main_tpl = $DIC->ui()->mainTemplate();
71
72 if ($this->http->wrapper()->query()->has('record_id')) {
73 $this->record_id = $this->http->wrapper()->query()->retrieve(
74 'record_id',
75 $this->refinery->kindlyTo()->int()
76 );
77 }
78 if ($this->http->wrapper()->post()->has('record_id')) {
79 $this->record_id = $this->http->wrapper()->post()->retrieve(
80 'record_id',
81 $this->refinery->kindlyTo()->int()
82 );
83 }
84 $this->record_obj = ilDclCache::getRecordCache($this->record_id);
85
86 $ref_id = $this->dcl_gui_object->getRefId();
87 if (!$this->record_obj->hasPermissionToView($ref_id)) {
88 $this->dclUi->displayFailureMessage($this->lng->txt('dcl_msg_no_perm_view'));
89
90 $this->dclEndPoint->redirect($this->dclEndPoint->getListRecordsLink());
91 }
92
93 // content style (using system defaults)
94 $tpl->setCurrentBlock("SyntaxStyle");
95 $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
96 $tpl->parseCurrentBlock();
97
98 $tpl->setCurrentBlock("ContentStyle");
99 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
100 $tpl->parseCurrentBlock();
101
102 $this->table = $this->record_obj->getTable();
103
104 // Comments
105 $repId = $this->dcl_gui_object->getDataCollectionObject()->getId();
106 $objId = $this->record_id;
107 $this->notesGUI = new ilNoteGUI($repId, $objId);
108 $this->notesGUI->enablePublicNotes(true);
109 $this->notesGUI->enablePublicNotesDeletion(true);
110 $this->ctrl->setParameterByClass("ilnotegui", "record_id", $this->record_id);
111 $this->ctrl->setParameterByClass("ilnotegui", "rep_id", $repId);
112
113 $this->tableview_id = $tableview_id;
114
115 if ($this->http->wrapper()->query()->has('disable_paging')
116 && $this->http->wrapper()->query()->retrieve('disable_paging', $this->refinery->kindlyTo()->bool())) {
117 $this->is_enabled_paging = false;
118 }
119 // Find current, prev and next records for navigation
120 if ($this->is_enabled_paging) {
121 $this->determineNextPrevRecords();
122 }
123 $this->content_style_domain = $DIC->contentStyle()
124 ->domain()
125 ->styleForRefId(
126 $this->dcl_gui_object->getDataCollectionObject()->getRefId()
127 );
128 }
129
130 public function executeCommand(): void
131 {
132 $this->ctrl->setParameter($this, 'tableview_id', $this->tableview_id);
133
134 if (!$this->checkAccess()) {
135 $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
136 if ($this->table->getVisibleTableViews($ref_id, true)) {
137 $this->offerAlternativeViews();
138 } else {
139 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
140 }
141
142 return;
143 }
144
145 $cmd = $this->ctrl->getCmd();
146 $cmdClass = $this->ctrl->getCmdClass();
147 switch (strtolower($cmdClass)) {
148 case 'ilnotegui':
149 $this->notesGUI->executeCommand();
150 break;
151 default:
152 $this->$cmd();
153 break;
154 }
155 }
156
157 protected function offerAlternativeViews(): void
158 {
159 global $DIC;
160 $tpl = $DIC['tpl'];
161 $this->main_tpl->setOnScreenMessage('info', $this->lng->txt('dcl_msg_info_alternatives'));
162 $table_gui = new ilDclTableViewTableGUI($this, 'renderRecord', $this->table, $this->dcl_gui_object->getRefId());
163 $tpl->setContent($table_gui->getHTML());
164 }
165
166 public function renderRecord(bool $editComments = false): void
167 {
168 global $DIC;
169 $ilTabs = $DIC->tabs();
170 $tpl = $DIC->ui()->mainTemplate();
171 $ilCtrl = $DIC->ctrl();
172
173 $rctpl = new ilDataCollectionGlobalTemplate("tpl.record_view.html", false, true, "Modules/DataCollection");
174
175 $ilTabs->setTabActive("id_content");
176
177 if (!$this->tableview_id) {
178 $ilCtrl->redirectByClass("ildclrecordlistgui", "listRecords");
179 }
180
181 // see ilObjDataCollectionGUI->executeCommand about instantiation
182 $pageObj = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
183 $pageObj->setStyleId(
184 $this->content_style_domain->getEffectiveStyleId()
185 );
186
187 $html = $pageObj->getHTML();
188 $rctpl->addCss("./Services/COPage/css/content.css");
189 $rctpl->fillCssFiles();
190 $table = ilDclCache::getTableCache($this->record_obj->getTableId());
191 foreach ($table->getRecordFields() as $field) {
192 //ILIAS_Ref_Links
193 $pattern = '/\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dcliln\]/';
194 if (preg_match($pattern, $html)) {
195 $html = preg_replace(
196 $pattern,
197 $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("$1")),
198 $html
199 );
200 }
201
202 //DataCollection Ref Links
203 $pattern = '/\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dclrefln\]/';
204 if (preg_match($pattern, $html)) {
205 $this->currentField = $field;
206 $html = preg_replace_callback($pattern, [$this, "doReplace"], $html);
207 }
208
209 $pattern = '/\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\]/';
210 if (preg_match($pattern, $html)) {
211 $this->currentField = $field;
212 $html = preg_replace_callback($pattern, [$this, "doExtReplace"], $html);
213 }
214
215 $html = str_ireplace(
216 "[" . $field->getTitle() . "]",
217 $this->record_obj->getRecordFieldSingleHTML($field->getId(), ['tableview_id' => $this->tableview_id]),
218 $html
219 );
220 }
221 foreach ($table->getStandardFields() as $field) {
222 $html = str_ireplace(
223 "[" . $field->getId() . "]",
224 $this->record_obj->getRecordFieldSingleHTML($field->getId(), ['tableview_id' => $this->tableview_id]),
225 $html
226 );
227 }
228 $rctpl->setVariable("CONTENT", $html);
229
230 //Permanent Link
231 $tpl->setPermanentLink(
232 'dcl',
233 filter_input(INPUT_GET, 'ref_id', FILTER_VALIDATE_INT),
234 '_' . $this->tableview_id . '_' . $this->record_obj->getId()
235 );
236
237 // Buttons for previous/next records
238
239 if ($this->is_enabled_paging) {
240 $prevNextLinks = $this->renderPrevNextLinks();
241 $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks);
242 $ilCtrl->clearParameters($this); // #14083
243 $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this));
244 $rctpl->setVariable('RECORD', $this->lng->txt('dcl_record'));
245 $rctpl->setVariable(
246 'RECORD_FROM_TOTAL',
247 sprintf(
248 $this->lng->txt('dcl_record_from_total'),
249 $this->current_record_position,
250 count($this->record_ids)
251 )
252 );
253 $rctpl->setVariable('TABLEVIEW_ID', $this->tableview_id);
254 $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions());
255 }
256
257 // Edit Button
258 $ref_id = $this->http->wrapper()->query()->retrieve('ref_id', $this->refinery->kindlyTo()->int());
259
260 if ($this->record_obj->hasPermissionToEdit($ref_id)) {
261 $button = ilLinkButton::getInstance();
262 $ilCtrl->setParameterByClass('ildclrecordeditgui', 'table_id', $this->table->getId());
263 $ilCtrl->setParameterByClass('ildclrecordeditgui', 'tableview_id', $this->tableview_id);
264 $ilCtrl->setParameterByClass('ildclrecordeditgui', 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
265 $ilCtrl->saveParameterByClass('ildclrecordeditgui', 'record_id');
266 $button->setUrl($ilCtrl->getLinkTargetByClass('ildclrecordeditgui', 'edit'));
267 $button->setCaption($this->lng->txt('dcl_edit_record'), false);
268 $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render());
269 }
270
271 // Comments
272 if ($this->table->getPublicCommentsEnabled()) {
273 $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
274 }
275
276 $tpl->setContent($rctpl->get());
277 }
278
279 public function doReplace(array $found): string
280 {
281 return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(), $this->setOptions($found[1]));
282 }
283
284 public function doExtReplace(array $found): ?string
285 {
286 $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
287 if (!is_array($ref_rec_ids)) {
288 $ref_rec_ids = [$ref_rec_ids];
289 }
290 if (!count($ref_rec_ids) || !$ref_rec_ids) {
291 return null;
292 }
293 $ref_recs = [];
294 foreach ($ref_rec_ids as $ref_rec_id) {
295 $ref_recs[] = ilDclCache::getRecordCache($ref_rec_id);
296 }
297 $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]);
298
299 $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
300 $tpl->setCurrentBlock("reference_list");
301
302 if (!$field) {
303 if (ilObjDataCollectionAccess::hasWriteAccess($this->dcl_gui_object->getRefId())) {
304 $this->main_tpl->setOnScreenMessage(
305 'info',
306 "Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]",
307 true
308 );
309 }
310
311 return null;
312 }
313
314 foreach ($ref_recs as $ref_record) {
315 $tpl->setCurrentBlock("reference");
316 $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId()));
317 $tpl->parseCurrentBlock();
318 }
319
320 //$ref_rec->getRecordFieldHTML($field->getId())
321 if ($field) {
322 return $tpl->get();
323 }
324
325 return null;
326 }
327
328 protected function renderComments(bool $edit = false): string
329 {
330 if (!$edit) {
331 return $this->notesGUI->getCommentsHTML();
332 } else {
333 return $this->notesGUI->editNoteForm();
334 }
335 }
336
340 protected function determineNextPrevRecords(): void
341 {
342 if (!ilSession::has("dcl_record_ids") || ilSession::get('dcl_record_ids') != $this->table->getId()) {
343 $this->loadSession();
344 }
345
346 if (ilSession::has("dcl_record_ids") && count(ilSession::get("dcl_record_ids"))) {
347 $this->record_ids = ilSession::get("dcl_record_ids");
348 foreach ($this->record_ids as $k => $recId) {
349 if ($recId == $this->record_id) {
350 if ($k != 0) {
351 $this->prev_record_id = $this->record_ids[$k - 1];
352 }
353 if (($k + 1) < count($this->record_ids)) {
354 $this->next_record_id = $this->record_ids[$k + 1];
355 }
356 $this->current_record_position = $k + 1;
357 break;
358 }
359 }
360 }
361 }
362
366 protected function renderPrevNextLinks(): string
367 {
368 global $DIC;
369 $ilCtrl = $DIC['ilCtrl'];
370 $ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
371 $prevStr = $this->lng->txt('dcl_prev_record');
372 $nextStr = $this->lng->txt('dcl_next_record');
373 $ilCtrl->setParameter($this, 'record_id', $this->prev_record_id);
374 $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
375 $out = ($this->prev_record_id) ? "<a href='{$url}'>{$prevStr}</a>" : "<span class='light'>{$prevStr}</span>";
376 $out .= " | ";
377 $ilCtrl->setParameter($this, 'record_id', $this->next_record_id);
378 $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
379 $out .= ($this->next_record_id) ? "<a href='{$url}'>{$nextStr}</a>" : "<span class='light'>{$nextStr}</span>";
380
381 return $out;
382 }
383
387 protected function renderSelectOptions(): string
388 {
389 $out = '';
390 foreach ($this->record_ids as $k => $recId) {
391 $selected = ($recId == $this->record_id) ? " selected" : "";
392 $out .= "<option value='{$recId}'{$selected}>" . ($k + 1) . "</option>";
393 }
394
395 return $out;
396 }
397
402 private function setOptions(string $link_name): array
403 {
404 $options = [];
405 $options['link']['display'] = true;
406 $options['link']['name'] = $link_name;
407
408 return $options;
409 }
410
414 private function loadSession(): void
415 {
416 $list = new ilDclRecordListTableGUI(
417 new ilDclRecordListGUI($this->dcl_gui_object, $this->table->getId(), $this->tableview_id),
418 "listRecords",
419 $this->table,
420 $this->tableview_id
421 );
422 $list->initFilter();
423 $list->determineOffsetAndOrder();
424 $this->table->getPartialRecords(
425 $this->table->getId(),
426 $list->getOrderField(),
427 $list->getOrderDirection(),
428 $list->getLimit(),
429 $list->getOffset(),
430 $list->getFilter()
431 );
432 }
433
437 protected function checkAccess(): bool
438 {
439 $ref_id = $this->dcl_gui_object->getRefId();
440 $has_accass = ilObjDataCollectionAccess::hasAccessTo($ref_id, $this->table->getId(), $this->tableview_id);
441 $is_active = ilDclDetailedViewDefinition::isActive($this->tableview_id);
442 return $has_accass && $is_active;
443 }
444}
$out
Definition: buildRTE.php:24
Builds data types.
Definition: Factory.php:21
Class Services.
Definition: Services.php:38
External facade for object content styles.
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getRecordCache(?int $record_id)
static getTableCache(int $table_id=null)
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...
init(ilDataCollectionOutboundsAdapter $adapter)
__construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview_id)
ilObjDataCollectionGUI $dcl_gui_object
renderPrevNextLinks()
Determine and return the markup for the previous/next records.
ILIAS Style Content Object ObjectFacade $content_style_domain
renderRecord(bool $editComments=false)
determineNextPrevRecords()
Find the previous/next record from the current position.
renderSelectOptions()
Render select options.
ilGlobalTemplateInterface $main_tpl
setOptions(string $link_name)
setOptions string $link_name
loadSession()
If we come from a goto Link we need to build up the session data.
ilDataCollectionUiPort $dclUi
ILIAS Refinery Factory $refinery
ilDclBaseRecordModel $record_obj
ilDclBaseFieldModel $currentField
ilDataCollectionEndpointPort $dclEndPoint
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...
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...
getRecordFields()
Returns all fields of this table which are NOT standard fields.
language handling
Notes GUI class.
static hasWriteAccess(int $ref, ?int $user_id=0)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
static getContentStylePath(int $a_style_id, bool $add_random=true, bool $add_token=true)
get content style path static (to avoid full reading)
static get(string $a_var)
static has($a_var)
special template class to simplify handling of ITX/PEAR
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...
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...
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$ref_id
Definition: ltiauth.php:67
static http()
Fetches the global http state from ILIAS.
$url
$objId
Definition: xapitoken.php:57