ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
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, 'tableview_id', $this->tableview_id);
128
129 if (!$this->checkAccess()) {
130 $this->main_tpl->setOnScreenMessage('failure', $this->lng->txt('permission_denied'), true);
131 return;
132 }
133
134 $cmd = $this->ctrl->getCmd('renderRecord');
135 $cmdClass = $this->ctrl->getCmdClass();
136 switch (strtolower($cmdClass)) {
137 case 'ilcommentgui':
138 $this->commentGUI->executeCommand();
139 break;
140 default:
141 $this->$cmd();
142 break;
143 }
144 }
145
146 public function jumpToRecord(): void
147 {
148 $this->ctrl->setParameterByClass(self::class, 'record_id', $this->record_id);
149 $this->ctrl->redirectByClass(self::class, 'renderRecord');
150 }
151
152 public function renderRecord(bool $editComments = false): void
153 {
154 global $DIC;
155 $x = $DIC->help();
156 $DIC->help()->setScreenId('dcl_record');
157 $ilTabs = $DIC->tabs();
158 $tpl = $DIC->ui()->mainTemplate();
159 $ilCtrl = $DIC->ctrl();
160
161 $rctpl = new ilDataCollectionGlobalTemplate("tpl.record_view.html", false, true, "components/ILIAS/DataCollection");
162
163 $ilTabs->setTabActive("id_content");
164
165 if (!$this->tableview_id) {
166 $ilCtrl->redirectByClass(ilDclRecordListGUI::class, "listRecords");
167 }
168
169 $pageObj = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
170 $pageObj->setOutputMode($pageObj::PRESENTATION);
171 $pageObj->setRecord($this->record_obj);
172 $html = $pageObj->showPage();
173 $rctpl->addCss("./assets/css/content.css");
174 $rctpl->fillCssFiles();
175 $rctpl->setVariable("CONTENT", $html);
176
177 //Permanent Link
178 $tpl->setPermanentLink(
179 'dcl',
180 filter_input(INPUT_GET, 'ref_id', FILTER_VALIDATE_INT),
181 $this->table->getId() . '_' . $this->tableview_id . '_' . $this->record_obj->getId()
182 );
183
184 // Buttons for previous/next records
185
186 if ($this->is_enabled_paging) {
187 $record_ids = ilSession::get('dcl_record_ids');
188 if ($record_ids !== [] && array_search($this->record_id, $record_ids) !== false) {
189 $DIC->toolbar()->addComponent(
190 $DIC->ui()->factory()->viewControl()->pagination()
191 ->withTargetURL($this->ctrl->getLinkTargetByClass(self::class, 'jumpToRecord'), 'record_pos')
192 ->withPageSize(1)
193 ->withDropdownAt(5)
194 ->withDropdownLabel($this->lng->txt('entry_of'))
195 ->withCurrentPage(array_search($this->record_id, $record_ids))
196 ->withTotalEntries(count($record_ids))
197 ->withMaxPaginationButtons(20)
198 );
199 }
200 }
201
202 if ($this->record_obj->hasPermissionToEdit($this->dcl_gui_object->getRefId())) {
203 $DIC->toolbar()->addSpacer('100%');
204 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'table_id', $this->table->getId());
205 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'tableview_id', $this->tableview_id);
206 $this->ctrl->setParameterByClass(ilDclRecordEditGUI::class, 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
207 $this->ctrl->saveParameterByClass(ilDclRecordEditGUI::class, 'record_id');
208 $DIC->toolbar()->addComponent($DIC->ui()->factory()->button()->standard(
209 $this->lng->txt('edit'),
210 $this->ctrl->getLinkTargetByClass(ilDclRecordEditGUI::class, 'edit')
211 ));
212 }
213
214 // Comments
215 if ($this->table->getPublicCommentsEnabled()) {
216 $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
217 }
218
219 $tpl->setContent($rctpl->get());
220 }
221
222 public function doReplace(array $found): string
223 {
224 return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(), $this->setOptions($found[1]));
225 }
226
227 public function doExtReplace(array $found): ?string
228 {
229 $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
230 if (!is_array($ref_rec_ids)) {
231 $ref_rec_ids = [$ref_rec_ids];
232 }
233 if (!count($ref_rec_ids) || !$ref_rec_ids) {
234 return null;
235 }
236 $ref_recs = [];
237 foreach ($ref_rec_ids as $ref_rec_id) {
238 $ref_recs[] = ilDclCache::getRecordCache($ref_rec_id);
239 }
240 $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]);
241
242 $tpl = new ilTemplate("tpl.reference_list.html", true, true, "components/ILIAS/DataCollection");
243 $tpl->setCurrentBlock("reference_list");
244
245 if (!$field) {
246 if (ilObjDataCollectionAccess::hasWriteAccess($this->dcl_gui_object->getRefId())) {
247 $this->main_tpl->setOnScreenMessage(
248 'info',
249 "Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]",
250 true
251 );
252 }
253
254 return null;
255 }
256
257 foreach ($ref_recs as $ref_record) {
258 $tpl->setCurrentBlock("reference");
259 $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId()));
260 $tpl->parseCurrentBlock();
261 }
262 return $tpl->get();
263 }
264
265 protected function renderComments(bool $edit = false): string
266 {
267 if (!$edit) {
268 return $this->commentGUI->getListHTML();
269 } else {
270 return $this->commentGUI->addNoteForm();
271 }
272 }
273
274 private function setOptions(string $link_name): array
275 {
276 $options = [];
277 $options['link']['display'] = true;
278 $options['link']['name'] = $link_name;
279
280 return $options;
281 }
282
286 private function loadSession(): void
287 {
288 $list = new ilDclRecordListTableGUI(
289 new ilDclRecordListGUI($this->dcl_gui_object, $this->table->getId(), $this->tableview_id),
290 "listRecords",
291 $this->table,
292 $this->tableview_id
293 );
294 $list->initFilter();
295 $list->determineOffsetAndOrder();
296 $this->table->getPartialRecords(
297 (string) $this->table->getId(),
298 $list->getOrderField(),
299 $list->getOrderDirection(),
300 $list->getLimit(),
301 $list->getOffset(),
302 $list->getFilter()
303 );
304 }
305
306 protected function checkAccess(): bool
307 {
308 $page = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
309 $has_accass = ilObjDataCollectionAccess::hasAccessTo($this->dcl_gui_object->getRefId(), $this->table->getId(), $this->tableview_id);
310 $is_active = $page->getPageObject()->isActive();
311 return $has_accass && $is_active;
312 }
313}
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:57