ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilDclDetailedViewGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2009 ILIAS open source, Extended GPL, see docs/LICENSE */
4
15{
16
20 protected $dcl_gui_object;
24 protected $notes_gui;
28 protected $table;
32 protected $tableview_id;
36 protected $record_obj;
40 protected $next_record_id = 0;
44 protected $prev_record_id = 0;
52 protected $record_ids = array();
56 protected $is_enabled_paging = true;
60 protected $lng;
61
62
66 public function __construct(ilObjDataCollectionGUI $a_dcl_object)
67 {
68 global $DIC;
69 $tpl = $DIC['tpl'];
70 $ilCtrl = $DIC['ilCtrl'];
71 $lng = $DIC['lng'];
72 $this->dcl_gui_object = $a_dcl_object;
73 $this->lng = $lng;
74
75 $this->record_id = (int) $_REQUEST['record_id'];
76 $this->record_obj = ilDclCache::getRecordCache($this->record_id);
77
78 if (!$this->record_obj->hasPermissionToView((int) $_GET['ref_id'])) {
79 ilUtil::sendFailure('dcl_msg_no_perm_view', true);
80 $ilCtrl->redirectByClass('ildclrecordlistgui', 'listRecords');
81 }
82
83 // content style (using system defaults)
84 $tpl->setCurrentBlock("SyntaxStyle");
85 $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
86 $tpl->parseCurrentBlock();
87
88 $tpl->setCurrentBlock("ContentStyle");
89 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
90 $tpl->parseCurrentBlock();
91
92 $this->table = $this->record_obj->getTable();
93
94 // Comments
95 $repId = $this->dcl_gui_object->getDataCollectionObject()->getId();
96 $objId = (int) $this->record_id;
97 $this->notesGUI = new ilNoteGUI($repId, $objId);
98 $this->notesGUI->enablePublicNotes(true);
99 $this->notesGUI->enablePublicNotesDeletion(true);
100 $ilCtrl->setParameterByClass("ilnotegui", "record_id", $this->record_id);
101 $ilCtrl->setParameterByClass("ilnotegui", "rep_id", $repId);
102
103 if (isset($_GET['disable_paging']) && $_GET['disable_paging']) {
104 $this->is_enabled_paging = false;
105 }
106 // Find current, prev and next records for navigation
107 if ($this->is_enabled_paging) {
109 }
110 }
111
112
113 public function executeCommand()
114 {
115 global $DIC;
116 $ilCtrl = $DIC['ilCtrl'];
117 $this->tableview_id = $_GET['tableview_id'] ? $_GET['tableview_id'] : $this->table->getFirstTableViewId($_GET['ref_id']);
118 $ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
119 $ilCtrl->setParameter($this->dcl_gui_object, 'tableview_id', $_GET['back_tableview_id'] ? $_GET['back_tableview_id'] : $this->tableview_id);
120
121 if (!$this->checkAccess()) {
122 if ($this->table->getVisibleTableViews($_GET['ref_id'], true)) {
123 $this->offerAlternativeViews();
124 } else {
125 ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
126 }
127
128 return;
129 }
130
131 $cmd = $ilCtrl->getCmd();
132 $cmdClass = $ilCtrl->getCmdClass();
133 switch ($cmdClass) {
134 case 'ilnotegui':
135 $ilCtrl->forwardCommand($this->notesGUI);
136 break;
137 default:
138 $this->$cmd();
139 break;
140 }
141 }
142
143
144 protected function offerAlternativeViews()
145 {
146 global $DIC;
147 $tpl = $DIC['tpl'];
148 ilUtil::sendInfo($this->lng->txt('dcl_msg_info_alternatives'));
149 $table_gui = new ilDclTableViewTableGUI($this, 'renderRecord', $this->table);
150 $tpl->setContent($table_gui->getHTML());
151 }
152
153
157 public function renderRecord($editComments = false)
158 {
159 global $DIC;
160 $ilTabs = $DIC->tabs();
161 $tpl = $DIC->ui()->mainTemplate();
162 $ilCtrl = $DIC->ctrl();
163
164 $rctpl = new ilDataCollectionGlobalTemplate("tpl.record_view.html", false, true, "Modules/DataCollection");
165
166 $ilTabs->setTabActive("id_content");
167
168 if (!$this->tableview_id) {
169 $ilCtrl->redirectByClass("ildclrecordlistgui", "listRecords");
170 }
171
172 // see ilObjDataCollectionGUI->executeCommand about instantiation
173 $pageObj = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
174 $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl"));
175
176 $html = $pageObj->getHTML();
177 $rctpl->addCss("./Services/COPage/css/content.css");
178 $rctpl->fillCssFiles();
179 $table = ilDclCache::getTableCache($this->record_obj->getTableId());
180 foreach ($table->getRecordFields() as $field) {
181 //ILIAS_Ref_Links
182 $pattern = '/\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dcliln\]/';
183 if (preg_match($pattern, $html)) {
184 $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("$1")), $html);
185 }
186
187 //DataCollection Ref Links
188 $pattern = '/\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dclrefln\]/';
189 if (preg_match($pattern, $html)) {
190 $this->currentField = $field;
191 $html = preg_replace_callback($pattern, array($this, "doReplace"), $html);
192 }
193
194 $pattern = '/\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\]/';
195 if (preg_match($pattern, $html)) {
196 $this->currentField = $field;
197 $html = preg_replace_callback($pattern, array($this, "doExtReplace"), $html);
198 }
199
200 $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
201 }
202 foreach ($table->getStandardFields() as $field) {
203 $html = str_ireplace("[" . $field->getId() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
204 }
205 $rctpl->setVariable("CONTENT", $html);
206
207 //Permanent Link
208 $tpl->setPermanentLink(
209 'dcl',
210 filter_input(INPUT_GET, 'ref_id', FILTER_VALIDATE_INT),
211 '_' . $this->tableview_id . '_' . $this->record_obj->getId()
212 );
213
214 // Buttons for previous/next records
215
216 if ($this->is_enabled_paging) {
217 $prevNextLinks = $this->renderPrevNextLinks();
218 $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks);
219 $ilCtrl->clearParameters($this); // #14083
220 $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this));
221 $rctpl->setVariable('RECORD', $this->lng->txt('dcl_record'));
222 $rctpl->setVariable('RECORD_FROM_TOTAL', sprintf($this->lng->txt('dcl_record_from_total'), $this->current_record_position, count($this->record_ids)));
223 $rctpl->setVariable('TABLEVIEW_ID', $this->tableview_id);
224 $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions());
225 }
226
227 // Edit Button
228 if ($this->record_obj->hasPermissionToEdit((int) $_GET['ref_id'])) {
229 $button = ilLinkButton::getInstance();
230 $ilCtrl->setParameterByClass('ildclrecordeditgui', 'table_id', $this->table->getId());
231 $ilCtrl->setParameterByClass('ildclrecordeditgui', 'tableview_id', $this->tableview_id);
232 $ilCtrl->setParameterByClass('ildclrecordeditgui', 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
233 $ilCtrl->saveParameterByClass('ildclrecordeditgui', 'record_id');
234 $button->setUrl($ilCtrl->getLinkTargetByClass('ildclrecordeditgui', 'edit'));
235 $button->setCaption($this->lng->txt('dcl_edit_record'), false);
236 $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render());
237 }
238
239 // Comments
240 if ($this->table->getPublicCommentsEnabled()) {
241 $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
242 }
243
244 $tpl->setContent($rctpl->get());
245 }
246
247
253 public function doReplace($found)
254 {
255 return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(), $this->setOptions($found[1]));
256 }
257
258
264 public function doExtReplace($found)
265 {
266 $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
267 if (!is_array($ref_rec_ids)) {
268 $ref_rec_ids = array($ref_rec_ids);
269 }
270 if (!count($ref_rec_ids) || !$ref_rec_ids) {
271 return;
272 }
273 $ref_recs = array();
274 foreach ($ref_rec_ids as $ref_rec_id) {
275 $ref_recs[] = ilDclCache::getRecordCache($ref_rec_id);
276 }
277 $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]);
278
279 $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
280 $tpl->setCurrentBlock("reference_list");
281
282 if (!$field) {
283 if (ilObjDataCollectionAccess::hasWriteAccess($this->dcl_gui_object->ref_id)) {
284 ilUtil::sendInfo("Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]", true);
285 }
286
287 return;
288 }
289
290 foreach ($ref_recs as $ref_record) {
291 $tpl->setCurrentBlock("reference");
292 $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId()));
293 $tpl->parseCurrentBlock();
294 }
295
296 //$ref_rec->getRecordFieldHTML($field->getId())
297 if ($field) {
298 return $tpl->get();
299 }
300 }
301
302
303 protected function renderComments($edit = false)
304 {
305 global $DIC;
306 $this->notesGUI::initJavascript($DIC->ctrl()->getLinkTarget($this));
307 if (!$edit) {
308 return $this->notesGUI->getOnlyCommentsHtml();
309 } else {
310 return $this->notesGUI->editNoteForm();
311 }
312 }
313
314
318 protected function determineNextPrevRecords()
319 {
320 if (!isset($_SESSION['dcl_record_ids']) || $_SESSION['dcl_table_id'] != $this->table->getId()) {
321 $this->loadSession();
322 }
323
324 if (isset($_SESSION['dcl_record_ids']) && count($_SESSION['dcl_record_ids'])) {
325 $this->record_ids = $_SESSION['dcl_record_ids'];
326 foreach ($this->record_ids as $k => $recId) {
327 if ($recId == $this->record_id) {
328 if ($k != 0) {
329 $this->prev_record_id = $this->record_ids[$k - 1];
330 }
331 if (($k + 1) < count($this->record_ids)) {
332 $this->next_record_id = $this->record_ids[$k + 1];
333 }
334 $this->current_record_position = $k + 1;
335 break;
336 }
337 }
338 }
339 }
340
341
347 protected function renderPrevNextLinks()
348 {
349 global $DIC;
350 $ilCtrl = $DIC['ilCtrl'];
351 $ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
352 $prevStr = $this->lng->txt('dcl_prev_record');
353 $nextStr = $this->lng->txt('dcl_next_record');
354 $ilCtrl->setParameter($this, 'record_id', $this->prev_record_id);
355 $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
356 $out = ($this->prev_record_id) ? "<a href='{$url}'>{$prevStr}</a>" : "<span class='light'>{$prevStr}</span>";
357 $out .= " | ";
358 $ilCtrl->setParameter($this, 'record_id', $this->next_record_id);
359 $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
360 $out .= ($this->next_record_id) ? "<a href='{$url}'>{$nextStr}</a>" : "<span class='light'>{$nextStr}</span>";
361
362 return $out;
363 }
364
365
371 protected function renderSelectOptions()
372 {
373 $out = '';
374 foreach ($this->record_ids as $k => $recId) {
375 $selected = ($recId == $this->record_id) ? " selected" : "";
376 $out .= "<option value='{$recId}'{$selected}>" . ($k + 1) . "</option>";
377 }
378
379 return $out;
380 }
381
382
387 private function setOptions($link_name)
388 {
389 $options = array();
390 $options['link']['display'] = true;
391 $options['link']['name'] = $link_name;
392
393 return $options;
394 }
395
396
400 private function loadSession()
401 {
402 // We need the default sorting etc. to dertermine on which position we currently are, thus we instantiate the table gui.
403 $list = new ilDclRecordListTableGUI(new ilDclRecordListGUI($this->dcl_gui_object, $this->table->getId()), "listRecords", $this->table, $this->tableview_id);
404 //we then partially load the records. note that this also fills up session data.
405 $this->table->getPartialRecords($list->getOrderField(), $list->getOrderDirection(), $list->getLimit(), $list->getOffset(), $list->getFilter());
406 }
407
408
412 protected function checkAccess()
413 {
414 return ilObjDataCollectionAccess::hasAccessTo(filter_input(INPUT_GET, 'ref_id'), $this->table->getId(), $this->tableview_id)
415 && ilDclDetailedViewDefinition::isActive($this->tableview_id);
416 }
417}
$_GET["client_id"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
special template class to simplify handling of ITX/PEAR
static getTableCache($table_id=0)
static getRecordCache($record_id=0)
Class ilDclDetailedViewDefinitionGUI.
renderPrevNextLinks()
Determine and return the markup for the previous/next records.
determineNextPrevRecords()
Find the previous/next record from the current position.
renderSelectOptions()
Render select options.
renderRecord($editComments=false)
loadSession()
If we come from a goto Link we need to build up the session data.
__construct(ilObjDataCollectionGUI $a_dcl_object)
setOptions($link_name)
setOptions string $link_name
Class ilDclTableViewTableGUI.
static getInstance()
Factory.
Notes GUI class.
Class ilObjDataCollectionGUI.
static getSyntaxStylePath()
get syntax style path
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
static getContentStylePath($a_style_id, $add_random=true, $add_token=true)
get content style path
special template class to simplify handling of ITX/PEAR
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
global $DIC
Definition: goto.php:24
if($DIC->http() ->request() ->getMethod()=="GET" &&isset($DIC->http() ->request() ->getQueryParams()['tex'])) $tpl
Definition: latex.php:41
$url
$objId
Definition: xapitoken.php:39