ILIAS  trunk Revision v12.0_alpha-1227-g7ff6d300864
class.ilDclDetailedViewGUI.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
25{
26 protected \ILIAS\UI\Factory $ui_factory;
27 protected \ILIAS\UI\Renderer $renderer;
29 protected ilDclTable $table;
30 protected int $tableview_id;
32 protected bool $is_enabled_paging = true;
33 protected ilLanguage $lng;
36
39 protected ?int $record_id;
42
43 public function __construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview_id)
44 {
45 global $DIC;
46
47 $tpl = $DIC->ui()->mainTemplate();
48 $this->ctrl = $DIC->ctrl();
49 $this->dcl_gui_object = $a_dcl_object;
50 $this->lng = $DIC->language();
51 $this->http = $DIC->http();
52 $this->refinery = $DIC->refinery();
53 $this->main_tpl = $DIC->ui()->mainTemplate();
54 $this->ui_factory = $DIC->ui()->factory();
55 $this->renderer = $DIC->ui()->renderer();
56
57 if (
58 !$this->http->wrapper()->query()->has('table_id') ||
59 !$this->http->wrapper()->query()->has('tableview_id')
60 ) {
61 $this->main_tpl->setOnScreenMessage($this->main_tpl::MESSAGE_TYPE_FAILURE, 'Table not found', true);
62 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "show");
63 }
64
65 $this->tableview_id = $this->http->wrapper()->query()->retrieve('tableview_id', $this->refinery->kindlyTo()->int());
66 $table_id = $this->http->wrapper()->query()->retrieve('table_id', $this->refinery->kindlyTo()->int());
67 $this->table = ilDclCache::getTableCache($table_id);
68 $this->loadSession();
69
70 $this->record_id = null;
71 if ($this->http->wrapper()->query()->has('record_id')) {
72 $this->record_id = $this->http->wrapper()->query()->retrieve(
73 'record_id',
74 $this->refinery->kindlyTo()->int()
75 );
76 } elseif ($this->http->wrapper()->query()->has('record_pos')) {
77 $record_ids = ilSession::get('dcl_record_ids');
78 $pos = $this->http->wrapper()->query()->retrieve('record_pos', $this->refinery->kindlyTo()->int());
79 if ($record_ids === [] || !array_key_exists($pos, $record_ids)) {
80 $this->ctrl->redirectToURL($this->http->request()->getServerParams()['HTTP_REFERER']);
81 }
82 $this->record_id = $record_ids[$pos];
83 }
84 if ($this->http->wrapper()->post()->has('record_id')) {
85 $this->record_id = $this->http->wrapper()->post()->retrieve(
86 'record_id',
87 $this->refinery->kindlyTo()->int()
88 );
89 }
90
91 if ($this->record_id) {
92 $this->record_obj = ilDclCache::getRecordCache($this->record_id);
93 if (!$this->record_obj->hasPermissionToView($this->dcl_gui_object->getRefId())) {
94 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('dcl_msg_no_perm_view'), true);
95 $this->ctrl->redirectByClass(ilDclRecordListGUI::class, "show");
96 }
97 }
98
99 // content style (using system defaults)
100 $tpl->setCurrentBlock("SyntaxStyle");
101 $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
102 $tpl->parseCurrentBlock();
103
104 $tpl->setCurrentBlock("ContentStyle");
105 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
106 $tpl->parseCurrentBlock();
107
108 // Comments
109 $repId = $this->dcl_gui_object->getDataCollectionObject()->getId();
111 $this->commentGUI = new ilCommentGUI($repId, $objId);
112 $this->commentGUI->enablePublicNotes();
113 $this->commentGUI->enablePublicNotesDeletion();
114 $this->ctrl->setParameterByClass(ilCommentGUI::class, "record_id", $this->record_id);
115 $this->ctrl->setParameterByClass(ilCommentGUI::class, "rep_id", $repId);
116
117 $this->tableview_id = $tableview_id;
118
119 if ($this->http->wrapper()->query()->has('disable_paging')
120 && $this->http->wrapper()->query()->retrieve('disable_paging', $this->refinery->kindlyTo()->bool())) {
121 $this->is_enabled_paging = false;
122 }
123 }
124
125 public function executeCommand(): void
126 {
127 $this->ctrl->setParameter($this, 'table_id', $this->table->getId());
128 $this->ctrl->setParameter($this, 'tableview_id', $this->tableview_id);
129
130 if (!$this->checkAccess()) {
131 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
132 return;
133 }
134
135 $cmd = $this->ctrl->getCmd('renderRecord');
136 $cmdClass = $this->ctrl->getCmdClass();
137 switch (strtolower($cmdClass)) {
138 case 'ilcommentgui':
139 $this->commentGUI->executeCommand();
140 break;
141 default:
142 $this->$cmd();
143 break;
144 }
145 }
146
147 public function jumpToRecord(): void
148 {
149 $this->ctrl->setParameterByClass(self::class, 'record_id', $this->record_id);
150 $this->ctrl->redirectByClass(self::class, 'renderRecord');
151 }
152
153 public function renderRecord(bool $editComments = false): void
154 {
155 global $DIC;
156 $x = $DIC->help();
157 $DIC->help()->setScreenId('dcl_record');
158 $ilTabs = $DIC->tabs();
159 $tpl = $DIC->ui()->mainTemplate();
160 $ilCtrl = $DIC->ctrl();
161
162 $rctpl = new ilDataCollectionGlobalTemplate("tpl.record_view.html", false, true, "components/ILIAS/DataCollection");
163
164 $ilTabs->setTabActive("id_content");
165
166 if (!$this->tableview_id) {
167 $ilCtrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
168 }
169
170 $pageObj = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
171 $pageObj->setOutputMode($pageObj::PRESENTATION);
172 $pageObj->setRecord($this->record_obj);
173 $html = $pageObj->showPage();
174 $rctpl->addCss("./assets/css/content.css");
175 $rctpl->fillCssFiles();
176 $rctpl->setVariable("CONTENT", $html);
177
178 //Permanent Link
179 $tpl->setPermanentLink(
180 'dcl',
181 filter_input(INPUT_GET, 'ref_id', FILTER_VALIDATE_INT),
182 $this->table->getId() . '_' . $this->tableview_id . '_' . $this->record_obj->getId()
183 );
184
185 // Buttons for previous/next records
186
187 if ($this->is_enabled_paging) {
188 $record_ids = ilSession::get('dcl_record_ids');
189 if ($record_ids !== [] && array_search($this->record_id, $record_ids) !== false) {
190 $DIC->toolbar()->addComponent(
191 $DIC->ui()->factory()->viewControl()->pagination()
192 ->withTargetURL($this->ctrl->getLinkTargetByClass(self::class, 'jumpToRecord'), 'record_pos')
193 ->withPageSize(1)
194 ->withDropdownAt(5)
195 ->withDropdownLabel($this->lng->txt('entry_of'))
196 ->withCurrentPage(array_search($this->record_id, $record_ids))
197 ->withTotalEntries(count($record_ids))
198 ->withMaxPaginationButtons(20)
199 );
200 }
201 }
202
203 if ($this->record_obj->hasPermissionToEdit($this->dcl_gui_object->getRefId())) {
204 $DIC->toolbar()->addSpacer('100%');
205 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'table_id', $this->table->getId());
206 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'tableview_id', $this->tableview_id);
207 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
208 $this->ctrl->saveParameterByClass(ilDclRecordEditGUI::class, 'record_id');
209 $DIC->toolbar()->addComponent($DIC->ui()->factory()->button()->standard(
210 $this->lng->txt('edit'),
211 $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'edit')
212 ));
213 }
214
215 // Comments
216 if ($this->table->getPublicCommentsEnabled()) {
217 $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
218 }
219
220 $tpl->setContent($rctpl->get());
221 }
222
223 public function doReplace(array $found): string
224 {
225 return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(), $this->setOptions($found[1]));
226 }
227
228 public function doExtReplace(array $found): ?string
229 {
230 $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
231 if (!is_array($ref_rec_ids)) {
232 $ref_rec_ids = [$ref_rec_ids];
233 }
234 if (!count($ref_rec_ids) || !$ref_rec_ids) {
235 return null;
236 }
237 $ref_recs = [];
238 foreach ($ref_rec_ids as $ref_rec_id) {
239 $ref_recs[] = ilDclCache::getRecordCache($ref_rec_id);
240 }
241 $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]);
242
243 $tpl = new ilTemplate("tpl.reference_list.html", true, true, "components/ILIAS/DataCollection");
244 $tpl->setCurrentBlock("reference_list");
245
246 if (!$field) {
247 if (ilObjDataCollectionAccess::hasWriteAccess($this->dcl_gui_object->getRefId())) {
248 $this->main_tpl->setOnScreenMessage(
249 'info',
250 "Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]",
251 true
252 );
253 }
254
255 return null;
256 }
257
258 foreach ($ref_recs as $ref_record) {
259 $tpl->setCurrentBlock("reference");
260 $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId()));
261 $tpl->parseCurrentBlock();
262 }
263 return $tpl->get();
264 }
265
266 protected function renderComments(bool $edit = false): string
267 {
268 if (!$edit) {
269 return $this->commentGUI->getListHTML();
270 } else {
271 return $this->commentGUI->addNoteForm();
272 }
273 }
274
275 private function setOptions(string $link_name): array
276 {
277 $options = [];
278 $options['link']['display'] = true;
279 $options['link']['name'] = $link_name;
280
281 return $options;
282 }
283
287 private function loadSession(): void
288 {
289 $list = new ilDclRecordListTableGUI(
290 new ilDclRecordListGUI($this->dcl_gui_object, $this->table->getId(), $this->tableview_id),
291 "listRecords",
292 $this->table,
293 $this->tableview_id
294 );
295 $list->initFilter();
296 $list->determineOffsetAndOrder();
297 $this->table->getPartialRecords(
298 (string) $this->table->getId(),
299 $list->getOrderField(),
300 $list->getOrderDirection(),
301 $list->getLimit(),
302 $list->getOffset(),
303 $list->getFilter()
304 );
305 }
306
307 protected function checkAccess(): bool
308 {
309 $page = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
310 $has_accass = ilObjDataCollectionAccess::hasAccessTo($this->dcl_gui_object->getRefId(), $this->table->getId(), $this->tableview_id);
311 $is_active = $page->getPageObject()->isActive();
312 return $has_accass && $is_active;
313 }
314}
renderer()
Builds data types.
Definition: Factory.php:36
Class Services.
Definition: Services.php:38
static getRecordCache(?int $record_id)
static getTableCache(?int $table_id=null)
@ilCtrl_Calls ilDclDetailedViewDefinitionGUI: ilPageEditorGUI, ilEditClipboardGUI,...
@ilCtrl_Calls ilDclDetailedViewGUI: ilDclDetailedViewDefinitionGUI, ilEditClipboardGUI,...
__construct(ilObjDataCollectionGUI $a_dcl_object, int $tableview_id)
ilObjDataCollectionGUI $dcl_gui_object
renderRecord(bool $editComments=false)
ilGlobalTemplateInterface $main_tpl
loadSession()
If we come from a goto Link we need to build up the session data.
ILIAS Refinery Factory $refinery
ilDclBaseRecordModel $record_obj
ilDclBaseFieldModel $currentField
language handling
static hasWriteAccess(int $ref, ?int $user_id=0)
@ilCtrl_Calls ilObjDataCollectionGUI: ilInfoScreenGUI, ilNoteGUI, ilCommonActionDispatcherGUI @ilCtrl...
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)
special template class to simplify handling of ITX/PEAR
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.
global $DIC
Definition: shib_login.php:26
$objId
Definition: xapitoken.php:55