ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 
5 require_once('./Modules/DataCollection/classes/Table/class.ilDclTable.php');
6 require_once('./Services/COPage/classes/class.ilPageObjectGUI.php');
7 require_once('./Modules/DataCollection/classes/Fields/Base/class.ilDclBaseRecordModel.php');
8 require_once('./Modules/DataCollection/classes/Fields/Base/class.ilDclBaseFieldModel.php');
9 require_once('class.ilDclDetailedViewDefinition.php');
10 require_once('./Services/UIComponent/Button/classes/class.ilLinkButton.php');
11 require_once('./Modules/DataCollection/classes/Content/class.ilDclRecordEditGUI.php');
12 require_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
13 require_once("./Modules/DataCollection/classes/Content/class.ilDclRecordListTableGUI.php");
14 require_once("./Modules/DataCollection/classes/Content/class.ilDclRecordListGUI.php");
15 require_once("./Modules/DataCollection/classes/TableView/class.ilDclTableViewTableGUI.php");
16 
27 
31  protected $dcl_gui_object;
35  protected $notes_gui;
39  protected $table;
43  protected $tableview_id;
47  protected $record_obj;
51  protected $next_record_id = 0;
55  protected $prev_record_id = 0;
59  protected $current_record_position = 0;
63  protected $record_ids = array();
67  protected $is_enabled_paging = true;
71  protected $lng;
72 
73 
77  public function __construct(ilObjDataCollectionGUI $a_dcl_object) {
78  global $DIC;
79  $tpl = $DIC['tpl'];
80  $ilCtrl = $DIC['ilCtrl'];
81  $lng = $DIC['lng'];
82  $this->dcl_gui_object = $a_dcl_object;
83  $this->lng = $lng;
84 
85  $this->record_id = (int)$_REQUEST['record_id'];
86  $this->record_obj = ilDclCache::getRecordCache($this->record_id);
87 
88  if (!$this->record_obj->hasPermissionToView((int)$_GET['ref_id'])) {
89  ilUtil::sendFailure('dcl_msg_no_perm_view', true);
90  $ilCtrl->redirectByClass('ildclrecordlistgui', 'listRecords');
91  }
92 
93  // content style (using system defaults)
94  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
95 
96  $tpl->setCurrentBlock("SyntaxStyle");
97  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET", ilObjStyleSheet::getSyntaxStylePath());
98  $tpl->parseCurrentBlock();
99 
100  $tpl->setCurrentBlock("ContentStyle");
101  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
102  $tpl->parseCurrentBlock();
103 
104  $this->table = $this->record_obj->getTable();
105 
106  // Comments
107  include_once("./Services/Notes/classes/class.ilNoteGUI.php");
108  $repId = $this->dcl_gui_object->getDataCollectionObject()->getId();
109  $objId = (int)$this->record_id;
110  $this->notesGUI = new ilNoteGUI($repId, $objId);
111  $this->notesGUI->enablePublicNotes(true);
112  $this->notesGUI->enablePublicNotesDeletion(true);
113  $ilCtrl->setParameterByClass("ilnotegui", "record_id", $this->record_id);
114  $ilCtrl->setParameterByClass("ilnotegui", "rep_id", $repId);
115 
116  if (isset($_GET['disable_paging']) && $_GET['disable_paging']) {
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  }
124 
125 
126  public function executeCommand() {
127  global $DIC;
128  $ilCtrl = $DIC['ilCtrl'];
129  $this->tableview_id = $_GET['tableview_id'] ? $_GET['tableview_id'] : $this->table->getFirstTableViewId($_GET['ref_id']);
130  $ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
131  $ilCtrl->setParameter($this->dcl_gui_object, 'tableview_id', $_GET['back_tableview_id'] ? $_GET['back_tableview_id'] : $this->tableview_id);
132 
133  if (!$this->checkAccess())
134  {
135  if ($this->table->getVisibleTableViews($_GET['ref_id'], true)) {
136  $this->offerAlternativeViews();
137  } else {
138  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
139  }
140  return;
141  }
142 
143  $cmd = $ilCtrl->getCmd();
144  $cmdClass = $ilCtrl->getCmdClass();
145  switch ($cmdClass) {
146  case 'ilnotegui':
147  switch ($cmd) {
148  case 'editNoteForm':
149  $this->renderRecord(true);
150  break;
151  case 'showNotes':
152  $this->renderRecord(false);
153  break;
154  case 'deleteNote':
155  $this->notesGUI->deleteNote();
156  $this->renderRecord();
157  break;
158  case 'cancelDelete':
159  $this->notesGUI->cancelDelete();
160  $this->renderRecord();
161  break;
162  default:
163  $this->notesGUI->$cmd();
164  break;
165  }
166  break;
167  default:
168  $this->$cmd();
169  break;
170  }
171  }
172 
173  protected function offerAlternativeViews() {
174  global $DIC;
175  $tpl = $DIC['tpl'];
176  ilUtil::sendInfo($this->lng->txt('dcl_msg_info_alternatives'));
177  $table_gui = new ilDclTableViewTableGUI($this, 'renderRecord', $this->table);
178  $tpl->setContent($table_gui->getHTML());
179  }
180 
184  public function renderRecord($editComments = false) {
185  global $DIC;
186  $ilTabs = $DIC['ilTabs'];
187  $tpl = $DIC['tpl'];
188  $ilCtrl = $DIC['ilCtrl'];
189 
190  $rctpl = new ilTemplate("tpl.record_view.html", false, true, "Modules/DataCollection");
191 
192  $ilTabs->setTabActive("id_content");
193 
194  if (!$this->tableview_id) {
195  $ilCtrl->redirectByClass("ildclrecordlistgui", "listRecords");
196  }
197 
198  // see ilObjDataCollectionGUI->executeCommand about instantiation
199  include_once("class.ilDclDetailedViewDefinitionGUI.php");
200  $pageObj = new ilDclDetailedViewDefinitionGUI($this->tableview_id);
201  include_once("./Services/Style/Content/classes/class.ilObjStyleSheet.php");
202  $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl"));
203 
204  $html = $pageObj->getHTML();
205  $rctpl->addCss("./Services/COPage/css/content.css");
206  $rctpl->fillCssFiles();
207  $table = ilDclCache::getTableCache($this->record_obj->getTableId());
208  foreach ($table->getRecordFields() as $field) {
209  //ILIAS_Ref_Links
210  $pattern = '/\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dcliln\]/';
211  if (preg_match($pattern, $html)) {
212  $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("$1")), $html);
213  }
214 
215  //DataCollection Ref Links
216  $pattern = '/\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dclrefln\]/';
217  if (preg_match($pattern, $html)) {
218  $this->currentField = $field;
219  $html = preg_replace_callback($pattern, array( $this, "doReplace" ), $html);
220  }
221 
222  $pattern = '/\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\]/';
223  if (preg_match($pattern, $html)) {
224  $this->currentField = $field;
225  $html = preg_replace_callback($pattern, array( $this, "doExtReplace" ), $html);
226  }
227 
228  $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
229  }
230  foreach ($table->getStandardFields() as $field) {
231  $html = str_ireplace("[" . $field->getId() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
232  }
233  $rctpl->setVariable("CONTENT", $html);
234 
235  //Permanent Link
236  $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_" . $this->tableview_id . "_" . $this->record_obj->getId());
237  $tpl->setVariable('PRMLINK', $perma_link->getHTML());
238 
239  // Buttons for previous/next records
240 
241  if ($this->is_enabled_paging) {
242  $prevNextLinks = $this->renderPrevNextLinks();
243  $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks);
244  $ilCtrl->clearParameters($this); // #14083
245  $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this));
246  $rctpl->setVariable('RECORD', $this->lng->txt('dcl_record'));
247  $rctpl->setVariable('RECORD_FROM_TOTAL', sprintf($this->lng->txt('dcl_record_from_total'), $this->current_record_position, count($this->record_ids)));
248  $rctpl->setVariable('TABLEVIEW_ID', $this->tableview_id);
249  $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions());
250  }
251 
252  // Edit Button
253  if ($this->record_obj->hasPermissionToEdit((int)$_GET['ref_id'])) {
254  $button = ilLinkButton::getInstance();
255  $ilCtrl->setParameterByClass('ildclrecordeditgui', 'table_id', $this->table->getId());
256  $ilCtrl->setParameterByClass('ildclrecordeditgui', 'tableview_id', $this->tableview_id);
257  $ilCtrl->setParameterByClass('ildclrecordeditgui', 'redirect', ilDclRecordEditGUI::REDIRECT_DETAIL);
258  $ilCtrl->saveParameterByClass('ildclrecordeditgui', 'record_id');
259  $button->setUrl($ilCtrl->getLinkTargetByClass('ildclrecordeditgui', 'edit'));
260  $button->setCaption($this->lng->txt('dcl_edit_record'), false);
261  $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render());
262  }
263 
264 
265  // Comments
266  if ($this->table->getPublicCommentsEnabled()) {
267  $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
268  }
269 
270  $tpl->setContent($rctpl->get());
271  }
272 
273 
279  public function doReplace($found) {
280  return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(), $this->setOptions($found[1]));
281  }
282 
283 
289  public function doExtReplace($found) {
290  $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
291  if (!is_array($ref_rec_ids)) {
292  $ref_rec_ids = array( $ref_rec_ids );
293  }
294  if (!count($ref_rec_ids) || !$ref_rec_ids) {
295  return;
296  }
297  $ref_recs = array();
298  foreach ($ref_rec_ids as $ref_rec_id) {
299  $ref_recs[] = ilDclCache::getRecordCache($ref_rec_id);
300  }
301  $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]);
302 
303  $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
304  $tpl->setCurrentBlock("reference_list");
305 
306  if (!$field) {
307  if (ilObjDataCollectionAccess::hasWriteAccess($this->dcl_gui_object->ref_id)) {
308  ilUtil::sendInfo("Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]", true);
309  }
310 
311  return;
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 
326 
327  protected function renderComments($edit = false) {
328 
329  if (!$edit) {
330  return $this->notesGUI->getOnlyCommentsHtml();
331  } else {
332  return $this->notesGUI->editNoteForm();
333  }
334  }
335 
336 
340  protected function determineNextPrevRecords() {
341  if(!isset($_SESSION['dcl_record_ids']) || $_SESSION['dcl_table_id'] != $this->table->getId()) {
342  $this->loadSession();
343  }
344 
345  if (isset($_SESSION['dcl_record_ids']) && count($_SESSION['dcl_record_ids'])) {
346  $this->record_ids = $_SESSION['dcl_record_ids'];
347  foreach ($this->record_ids as $k => $recId) {
348  if ($recId == $this->record_id) {
349  if ($k != 0) {
350  $this->prev_record_id = $this->record_ids[$k - 1];
351  }
352  if (($k + 1) < count($this->record_ids)) {
353  $this->next_record_id = $this->record_ids[$k + 1];
354  }
355  $this->current_record_position = $k + 1;
356  break;
357  }
358  }
359  }
360  }
361 
362 
368  protected function renderPrevNextLinks() {
369  global $DIC;
370  $ilCtrl = $DIC['ilCtrl'];
371  $ilCtrl->setParameter($this, 'tableview_id', $this->tableview_id);
372  $prevStr = $this->lng->txt('dcl_prev_record');
373  $nextStr = $this->lng->txt('dcl_next_record');
374  $ilCtrl->setParameter($this, 'record_id', $this->prev_record_id);
375  $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
376  $out = ($this->prev_record_id) ? "<a href='{$url}'>{$prevStr}</a>" : "<span class='light'>{$prevStr}</span>";
377  $out .= " | ";
378  $ilCtrl->setParameter($this, 'record_id', $this->next_record_id);
379  $url = $ilCtrl->getLinkTarget($this, 'renderRecord');
380  $out .= ($this->next_record_id) ? "<a href='{$url}'>{$nextStr}</a>" : "<span class='light'>{$nextStr}</span>";
381 
382  return $out;
383  }
384 
385 
391  protected function renderSelectOptions() {
392  $out = '';
393  foreach ($this->record_ids as $k => $recId) {
394  $selected = ($recId == $this->record_id) ? " selected" : "";
395  $out .= "<option value='{$recId}'{$selected}>" . ($k + 1) . "</option>";
396  }
397 
398  return $out;
399  }
400 
401 
406  private function setOptions($link_name) {
407  $options = array();
408  $options['link']['display'] = true;
409  $options['link']['name'] = $link_name;
410 
411  return $options;
412  }
413 
417  private function loadSession()
418  {
419  // We need the default sorting etc. to dertermine on which position we currently are, thus we instantiate the table gui.
420  $list = new ilDclRecordListTableGUI(new ilDclRecordListGUI($this->dcl_gui_object, $this->table->getId()), "listRecords", $this->table, $this->tableview_id);
421  //we then partially load the records. note that this also fills up session data.
422  $this->table->getPartialRecords($list->getOrderField(), $list->getOrderDirection(), $list->getLimit(), $list->getOffset(), $list->getFilter());
423  }
424 
428  protected function checkAccess()
429  {
430  return ilObjDataCollectionAccess::hasAccessTo(filter_input(INPUT_GET, 'ref_id'), $this->table->getId(), $this->tableview_id)
431  && ilDclDetailedViewDefinition::isActive($this->tableview_id);
432  }
433 }
434 
435 ?>
loadSession()
If we come from a goto Link we need to build up the session data.
Class for permanent links.
$_SESSION["AccountId"]
renderSelectOptions()
Render select options.
$_GET["client_id"]
$cmd
Definition: sahs_server.php:35
Class ilDclDetailedViewDefinitionGUI.
$url
Definition: shib_logout.php:72
static getTableCache($table_id=0)
Class ilDclTableViewTableGUI.
global $tpl
Definition: ilias.php:8
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.
if(!is_array($argv)) $options
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
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
__construct(ilObjDataCollectionGUI $a_dcl_object)
static getContentStylePath($a_style_id)
get content style path
global $DIC
determineNextPrevRecords()
Find the previous/next record from the current position.
$html
Definition: example_001.php:87