ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
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;
48  protected $current_record_position = 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  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
85 
86  $tpl->setCurrentBlock("SyntaxStyle");
87  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
88  $tpl->parseCurrentBlock();
89 
90  $tpl->setCurrentBlock("ContentStyle");
91  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
92  $tpl->parseCurrentBlock();
93 
94  $this->table = $this->record_obj->getTable();
95 
96  // Comments
97  include_once("./Services/Notes/classes/class.ilNoteGUI.php");
98  $repId = $this->dcl_gui_object->getDataCollectionObject()->getId();
99  $objId = (int) $this->record_id;
100  $this->notesGUI = new ilNoteGUI($repId, $objId);
101  $this->notesGUI->enablePublicNotes(true);
102  $this->notesGUI->enablePublicNotesDeletion(true);
103  $ilCtrl->setParameterByClass("ilnotegui", "record_id", $this->record_id);
104  $ilCtrl->setParameterByClass("ilnotegui", "rep_id", $repId);
105 
106  if (isset($_GET['disable_paging']) && $_GET['disable_paging']) {
107  $this->is_enabled_paging = false;
108  }
109  // Find current, prev and next records for navigation
110  if ($this->is_enabled_paging) {
111  $this->determineNextPrevRecords();
112  }
113  }
114 
115 
116  public function executeCommand()
117  {
118  global $DIC;
119  $ilCtrl = $DIC['ilCtrl'];
120  $this->tableview_id = $_GET['tableview_id'] ? $_GET['tableview_id'] : $this->table->getFirstTableViewId($_GET['ref_id']);
121  $ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
122  $ilCtrl->setParameter($this->dcl_gui_object, 'tableview_id', $_GET['back_tableview_id'] ? $_GET['back_tableview_id'] : $this->tableview_id);
123 
124  if (!$this->checkAccess()) {
125  if ($this->table->getVisibleTableViews($_GET['ref_id'], true)) {
126  $this->offerAlternativeViews();
127  } else {
128  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
129  }
130 
131  return;
132  }
133 
134  $cmd = $ilCtrl->getCmd();
135  $cmdClass = $ilCtrl->getCmdClass();
136  switch ($cmdClass) {
137  case 'ilnotegui':
138  switch ($cmd) {
139  case 'editNoteForm':
140  $this->renderRecord(true);
141  break;
142  case 'showNotes':
143  $this->renderRecord(false);
144  break;
145  case 'deleteNote':
146  $this->notesGUI->deleteNote();
147  $this->renderRecord();
148  break;
149  case 'cancelDelete':
150  $this->notesGUI->cancelDelete();
151  $this->renderRecord();
152  break;
153  default:
154  $this->notesGUI->$cmd();
155  break;
156  }
157  break;
158  default:
159  $this->$cmd();
160  break;
161  }
162  }
163 
164 
165  protected function offerAlternativeViews()
166  {
167  global $DIC;
168  $tpl = $DIC['tpl'];
169  ilUtil::sendInfo($this->lng->txt('dcl_msg_info_alternatives'));
170  $table_gui = new ilDclTableViewTableGUI($this, 'renderRecord', $this->table);
171  $tpl->setContent($table_gui->getHTML());
172  }
173 
174 
178  public function renderRecord($editComments = false)
179  {
180  global $DIC;
181  $ilTabs = $DIC['ilTabs'];
182  $tpl = $DIC['tpl'];
183  $ilCtrl = $DIC['ilCtrl'];
184 
185  $rctpl = new ilTemplate("tpl.record_view.html", false, true, "Modules/DataCollection");
186 
187  $ilTabs->setTabActive("id_content");
188 
189  if (!$this->tableview_id) {
190  $ilCtrl->redirectByClass("ildclrecordlistgui", "listRecords");
191  }
192 
193  // see ilObjDataCollectionGUI->executeCommand about instantiation
194  include_once("class.ilDclDetailedViewDefinitionGUI.php");
195  $pageObj = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
196  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
197  $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl"));
198 
199  $html = $pageObj->getHTML();
200  $rctpl->addCss("./Services/COPage/css/content.css");
201  $rctpl->fillCssFiles();
202  $table = ilDclCache::getTableCache($this->record_obj->getTableId());
203  foreach ($table->getRecordFields() as $field) {
204  //ILIAS_Ref_Links
205  $pattern = '/\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dcliln\]/';
206  if (preg_match($pattern, $html)) {
207  $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("$1")), $html);
208  }
209 
210  //DataCollection Ref Links
211  $pattern = '/\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dclrefln\]/';
212  if (preg_match($pattern, $html)) {
213  $this->currentField = $field;
214  $html = preg_replace_callback($pattern, array($this, "doReplace"), $html);
215  }
216 
217  $pattern = '/\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\]/';
218  if (preg_match($pattern, $html)) {
219  $this->currentField = $field;
220  $html = preg_replace_callback($pattern, array($this, "doExtReplace"), $html);
221  }
222 
223  $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
224  }
225  foreach ($table->getStandardFields() as $field) {
226  $html = str_ireplace("[" . $field->getId() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
227  }
228  $rctpl->setVariable("CONTENT", $html);
229 
230  //Permanent Link
231  $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_" . $this->tableview_id . "_" . $this->record_obj->getId());
232  $tpl->setVariable('PRMLINK', $perma_link->getHTML());
233 
234  // Buttons for previous/next records
235 
236  if ($this->is_enabled_paging) {
237  $prevNextLinks = $this->renderPrevNextLinks();
238  $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks);
239  $ilCtrl->clearParameters($this); // #14083
240  $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this));
241  $rctpl->setVariable('RECORD', $this->lng->txt('dcl_record'));
242  $rctpl->setVariable('RECORD_FROM_TOTAL', sprintf($this->lng->txt('dcl_record_from_total'), $this->current_record_position, count($this->record_ids)));
243  $rctpl->setVariable('TABLEVIEW_ID', $this->tableview_id);
244  $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions());
245  }
246 
247  // Edit Button
248  if ($this->record_obj->hasPermissionToEdit((int) $_GET['ref_id'])) {
249  $button = ilLinkButton::getInstance();
250  $ilCtrl->setParameterByClass('ildclrecordeditgui', 'table_id', $this->table->getId());
251  $ilCtrl->setParameterByClass('ildclrecordeditgui', 'tableview_id', $this->tableview_id);
252  $ilCtrl->setParameterByClass('ildclrecordeditgui', 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
253  $ilCtrl->saveParameterByClass('ildclrecordeditgui', 'record_id');
254  $button->setUrl($ilCtrl->getLinkTargetByClass('ildclrecordeditgui', 'edit'));
255  $button->setCaption($this->lng->txt('dcl_edit_record'), false);
256  $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render());
257  }
258 
259  // Comments
260  if ($this->table->getPublicCommentsEnabled()) {
261  $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
262  }
263 
264  $tpl->setContent($rctpl->get());
265  }
266 
267 
273  public function doReplace($found)
274  {
275  return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(), $this->setOptions($found[1]));
276  }
277 
278 
284  public function doExtReplace($found)
285  {
286  $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
287  if (!is_array($ref_rec_ids)) {
288  $ref_rec_ids = array($ref_rec_ids);
289  }
290  if (!count($ref_rec_ids) || !$ref_rec_ids) {
291  return;
292  }
293  $ref_recs = array();
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->ref_id)) {
304  ilUtil::sendInfo("Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]", true);
305  }
306 
307  return;
308  }
309 
310  foreach ($ref_recs as $ref_record) {
311  $tpl->setCurrentBlock("reference");
312  $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId()));
313  $tpl->parseCurrentBlock();
314  }
315 
316  //$ref_rec->getRecordFieldHTML($field->getId())
317  if ($field) {
318  return $tpl->get();
319  }
320  }
321 
322 
323  protected function renderComments($edit = false)
324  {
325  if (!$edit) {
326  return $this->notesGUI->getOnlyCommentsHtml();
327  } else {
328  return $this->notesGUI->editNoteForm();
329  }
330  }
331 
332 
336  protected function determineNextPrevRecords()
337  {
338  if (!isset($_SESSION['dcl_record_ids']) || $_SESSION['dcl_table_id'] != $this->table->getId()) {
339  $this->loadSession();
340  }
341 
342  if (isset($_SESSION['dcl_record_ids']) && count($_SESSION['dcl_record_ids'])) {
343  $this->record_ids = $_SESSION['dcl_record_ids'];
344  foreach ($this->record_ids as $k => $recId) {
345  if ($recId == $this->record_id) {
346  if ($k != 0) {
347  $this->prev_record_id = $this->record_ids[$k - 1];
348  }
349  if (($k + 1) < count($this->record_ids)) {
350  $this->next_record_id = $this->record_ids[$k + 1];
351  }
352  $this->current_record_position = $k + 1;
353  break;
354  }
355  }
356  }
357  }
358 
359 
365  protected function renderPrevNextLinks()
366  {
367  global $DIC;
368  $ilCtrl = $DIC['ilCtrl'];
369  $ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
370  $prevStr = $this->lng->txt('dcl_prev_record');
371  $nextStr = $this->lng->txt('dcl_next_record');
372  $ilCtrl->setParameter($this, 'record_id', $this->prev_record_id);
373  $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
374  $out = ($this->prev_record_id) ? "<a href='{$url}'>{$prevStr}</a>" : "<span class='light'>{$prevStr}</span>";
375  $out .= " | ";
376  $ilCtrl->setParameter($this, 'record_id', $this->next_record_id);
377  $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
378  $out .= ($this->next_record_id) ? "<a href='{$url}'>{$nextStr}</a>" : "<span class='light'>{$nextStr}</span>";
379 
380  return $out;
381  }
382 
383 
389  protected function renderSelectOptions()
390  {
391  $out = '';
392  foreach ($this->record_ids as $k => $recId) {
393  $selected = ($recId == $this->record_id) ? " selected" : "";
394  $out .= "<option value='{$recId}'{$selected}>" . ($k + 1) . "</option>";
395  }
396 
397  return $out;
398  }
399 
400 
405  private function setOptions($link_name)
406  {
407  $options = array();
408  $options['link']['display'] = true;
409  $options['link']['name'] = $link_name;
410 
411  return $options;
412  }
413 
414 
418  private function loadSession()
419  {
420  // We need the default sorting etc. to dertermine on which position we currently are, thus we instantiate the table gui.
421  $list = new ilDclRecordListTableGUI(new ilDclRecordListGUI($this->dcl_gui_object, $this->table->getId()), "listRecords", $this->table, $this->tableview_id);
422  //we then partially load the records. note that this also fills up session data.
423  $this->table->getPartialRecords($list->getOrderField(), $list->getOrderDirection(), $list->getLimit(), $list->getOffset(), $list->getFilter());
424  }
425 
426 
430  protected function checkAccess()
431  {
432  return ilObjDataCollectionAccess::hasAccessTo(filter_input(INPUT_GET, 'ref_id'), $this->table->getId(), $this->tableview_id)
433  && ilDclDetailedViewDefinition::isActive($this->tableview_id);
434  }
435 }
loadSession()
If we come from a goto Link we need to build up the session data.
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41
Class for permanent links.
$_SESSION["AccountId"]
global $DIC
Definition: saml.php:7
renderSelectOptions()
Render select options.
$_GET["client_id"]
$tpl
Definition: ilias.php:10
Class ilDclDetailedViewDefinitionGUI.
static getTableCache($table_id=0)
Class ilDclTableViewTableGUI.
Notes GUI class.
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Class ilObjDataCollectionGUI.
setOptions($link_name)
setOptions string $link_name
renderPrevNextLinks()
Determine and return the markup for the previous/next records.
special template class to simplify handling of ITX/PEAR
static getEffectiveContentStyleId($a_style_id, $a_type="")
Get effective Style Id.
static getRecordCache($record_id=0)
renderRecord($editComments=false)
static getSyntaxStylePath()
get syntax style path
static getContentStylePath($a_style_id, $add_random=true)
get content style path
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct(ilObjDataCollectionGUI $a_dcl_object)
$url
determineNextPrevRecords()
Find the previous/next record from the current position.
$html
Definition: example_001.php:87