ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
class.ilDataCollectionRecordViewGUI.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/class.ilDataCollectionTable.php');
6 require_once('./Services/COPage/classes/class.ilPageObjectGUI.php');
7 require_once('./Modules/DataCollection/classes/class.ilDataCollectionRecord.php');
8 require_once('./Modules/DataCollection/classes/class.ilDataCollectionField.php');
9 require_once('./Modules/DataCollection/classes/class.ilDataCollectionRecordViewViewdefinition.php');
10 require_once('./Services/UIComponent/Button/classes/class.ilLinkButton.php');
11 require_once('class.ilDataCollectionRecordEditGUI.php');
12 require_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
13 require_once("Modules/DataCollection/classes/class.ilDataCollectionRecordListTableGUI.php");
14 require_once("Modules/DataCollection/classes/class.ilDataCollectionRecordListGUI.php");
15 
27 
31  protected $dcl_gui_object;
35  protected $notes_gui;
39  protected $table;
43  protected $record_obj;
47  protected $next_record_id = 0;
51  protected $prev_record_id = 0;
55  protected $current_record_position = 0;
59  protected $record_ids = array();
63  protected $is_enabled_paging = true;
64 
65 
69  public function __construct(ilObjDataCollectionGUI $a_dcl_object) {
70  global $tpl, $ilCtrl;
71  $this->dcl_gui_object = $a_dcl_object;
72 
73  $this->record_id = (int)$_REQUEST['record_id'];
74  $this->record_obj = ilDataCollectionCache::getRecordCache($this->record_id);
75 
76  if (!$this->record_obj->hasPermissionToView((int)$_GET['ref_id'])) {
77  ilUtil::sendFailure('dcl_msg_no_perm_view', true);
78  $ilCtrl->redirectByClass('ildatacollectionrecordlistgui', 'listRecords');
79  }
80 
81  // content style (using system defaults)
82  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
83 
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  include_once("./Services/Notes/classes/class.ilNoteGUI.php");
96  $repId = $this->dcl_gui_object->getDataCollectionObject()->getId();
97  $objId = (int)$this->record_id;
98  $this->notesGUI = new ilNoteGUI($repId, $objId);
99  $this->notesGUI->enablePublicNotes(true);
100  $this->notesGUI->enablePublicNotesDeletion(true);
101  $ilCtrl->setParameterByClass("ilnotegui", "record_id", $this->record_id);
102  $ilCtrl->setParameterByClass("ilnotegui", "rep_id", $repId);
103 
104  if (isset($_GET['disable_paging']) && $_GET['disable_paging']) {
105  $this->is_enabled_paging = false;
106  }
107  // Find current, prev and next records for navigation
108  if ($this->is_enabled_paging) {
109  $this->determineNextPrevRecords();
110  }
111  }
112 
113 
114  public function executeCommand() {
115  global $ilCtrl;
116 
117  $cmd = $ilCtrl->getCmd();
118  $cmdClass = $ilCtrl->getCmdClass();
119  switch ($cmdClass) {
120  case 'ilnotegui':
121  switch ($cmd) {
122  case 'editNoteForm':
123  $this->renderRecord(true);
124  break;
125  case 'showNotes':
126  $this->renderRecord(false);
127  break;
128  case 'deleteNote':
129  $this->notesGUI->deleteNote();
130  $this->renderRecord();
131  break;
132  case 'cancelDelete':
133  $this->notesGUI->cancelDelete();
134  $this->renderRecord();
135  break;
136  default:
137  $this->notesGUI->$cmd();
138  break;
139  }
140  break;
141  default:
142  $this->$cmd();
143  break;
144  }
145  }
146 
147 
157  }
158 
159 
168 
169  return $view->getActive() AND $view->getId() !== NULL;
170  }
171 
172 
180 
181  return $view->getActive() AND $view->getId() !== NULL;
182  }
183 
184 
188  public function renderRecord($editComments = false) {
189  global $ilTabs, $tpl, $ilCtrl, $lng;
190 
191  $rctpl = new ilTemplate("tpl.record_view.html", false, true, "Modules/DataCollection");
192 
193  $ilTabs->setTabActive("id_content");
194 
195  $view_id = self::_getViewDefinitionId($this->record_obj);
196 
197  if (!$view_id) {
198  $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
199  }
200 
201  // see ilObjDataCollectionGUI->executeCommand about instantiation
202  include_once("./Modules/DataCollection/classes/class.ilDataCollectionRecordViewViewdefinitionGUI.php");
203  $pageObj = new ilDataCollectionRecordViewViewdefinitionGUI($this->record_obj->getTableId(), $view_id);
204  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
205  $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl"));
206 
207  $html = $pageObj->getHTML();
208  $rctpl->addCss("./Services/COPage/css/content.css");
209  $rctpl->fillCssFiles();
210  $table = ilDataCollectionCache::getTableCache($this->record_obj->getTableId());
211  foreach ($table->getRecordFields() as $field) {
212  //ILIAS_Ref_Links
213  $pattern = '/\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dcliln\]/';
214  if (preg_match($pattern, $html)) {
215  $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("$1")), $html);
216  }
217 
218  //DataCollection Ref Links
219  $pattern = '/\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\](.*?)\[\/dclrefln\]/';
220  if (preg_match($pattern, $html)) {
221  $this->currentField = $field;
222  $html = preg_replace_callback($pattern, array( $this, "doReplace" ), $html);
223  }
224 
225  $pattern = '/\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\]/';
226  if (preg_match($pattern, $html)) {
227  $this->currentField = $field;
228  $html = preg_replace_callback($pattern, array( $this, "doExtReplace" ), $html);
229  }
230 
231  $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
232  }
233  foreach ($table->getStandardFields() as $field) {
234  $html = str_ireplace("[" . $field->getId() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html);
235  }
236  $rctpl->setVariable("CONTENT", $html);
237 
238  //Permanent Link
239  $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_" . $this->record_obj->getId());
240  $tpl->setVariable('PRMLINK', $perma_link->getHTML());
241 
242  // Buttons for previous/next records
243 
244  if ($this->is_enabled_paging) {
245  $prevNextLinks = $this->renderPrevNextLinks();
246  $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks);
247  $ilCtrl->clearParameters($this); // #14083
248  $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this));
249  $rctpl->setVariable('RECORD', $lng->txt('dcl_record'));
250  $rctpl->setVariable('RECORD_FROM_TOTAL', sprintf($lng->txt('dcl_record_from_total'), $this->current_record_position, count($this->record_ids)));
251  $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions());
252  }
253 
254  // Edit Button
255  if ($this->record_obj->hasPermissionToEdit((int)$_GET['ref_id'])) {
256  $button = ilLinkButton::getInstance();
257  $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'table_id', $this->table->getId());
258  $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'redirect', ilDataCollectionRecordEditGUI::REDIRECT_DETAIL);
259  $ilCtrl->saveParameterByClass('ildatacollectionrecordeditgui', 'record_id');
260  $button->setUrl($ilCtrl->getLinkTargetByClass('ildatacollectionrecordeditgui', 'edit'));
261  $button->setCaption($lng->txt('dcl_edit_record'), false);
262  $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render());
263  }
264 
265 // var_dump($_SESSION['dcl_record_ids']);
266 
267  // Comments
268  if ($this->table->getPublicCommentsEnabled()) {
269  $rctpl->setVariable('COMMENTS', $this->renderComments($editComments));
270  }
271 
272  $tpl->setContent($rctpl->get());
273  }
274 
275 
281  public function doReplace($found) {
282  return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(), $this->setOptions($found[1]));
283  }
284 
285 
291  public function doExtReplace($found) {
292  $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
293  if (!is_array($ref_rec_ids)) {
294  $ref_rec_ids = array( $ref_rec_ids );
295  }
296  if (!count($ref_rec_ids) || !$ref_rec_ids) {
297  return;
298  }
299  $ref_recs = array();
300  foreach ($ref_rec_ids as $ref_rec_id) {
301  $ref_recs[] = ilDataCollectionCache::getRecordCache($ref_rec_id);
302  }
303  $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]);
304 
305  $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
306  $tpl->setCurrentBlock("reference_list");
307 
308  if (!$field) {
309  if (ilObjDataCollectionAccess::hasWriteAccess($this->dcl_gui_object->ref_id)) {
310  ilUtil::sendInfo("Bad Viewdefinition at [ext tableOf=\"" . $found[1] . "\" ...]", true);
311  }
312 
313  return;
314  }
315 
316  foreach ($ref_recs as $ref_record) {
317  $tpl->setCurrentBlock("reference");
318  $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId()));
319  $tpl->parseCurrentBlock();
320  }
321 
322  //$ref_rec->getRecordFieldHTML($field->getId())
323  if ($field) {
324  return $tpl->get();
325  }
326  }
327 
328 
329  protected function renderComments($edit = false) {
330 
331  if (!$edit) {
332  return $this->notesGUI->getOnlyCommentsHtml();
333  } else {
334  return $this->notesGUI->editNoteForm();
335  }
336  }
337 
338 
342  protected function determineNextPrevRecords() {
343  if(!isset($_SESSION['dcl_record_ids']) || $_SESSION['dcl_table_id'] != $this->table->getId()) {
344  $this->loadSession();
345  }
346 
347  if (isset($_SESSION['dcl_record_ids']) && count($_SESSION['dcl_record_ids'])) {
348  $this->record_ids = $_SESSION['dcl_record_ids'];
349  foreach ($this->record_ids as $k => $recId) {
350  if ($recId == $this->record_id) {
351  if ($k != 0) {
352  $this->prev_record_id = $this->record_ids[$k - 1];
353  }
354  if (($k + 1) < count($this->record_ids)) {
355  $this->next_record_id = $this->record_ids[$k + 1];
356  }
357  $this->current_record_position = $k + 1;
358  break;
359  }
360  }
361  }
362  }
363 
364 
370  protected function renderPrevNextLinks() {
371  global $ilCtrl, $lng;
372  $prevStr = $lng->txt('dcl_prev_record');
373  $nextStr = $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 ilDataCollectionRecordListTableGUI(new ilDataCollectionRecordListGUI($this->dcl_gui_object, $this->table->getId()), "listRecords", $this->table);
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 }
425 
426 ?>
static getRecordCache($record_id=0)
Class ilDataCollectionField.
Class ilDataCollectionRecordListGUI.
static getIdByTableId($a_table_id)
Get view definition id by table id.
Class for permanent links.
$_SESSION["AccountId"]
static hasTableValidViewDefinition(ilDataCollectionTable $table)
$_GET["client_id"]
renderPrevNextLinks()
Determine and return the markup for the previous/next records.
__construct(ilObjDataCollectionGUI $a_dcl_object)
$cmd
Definition: sahs_server.php:35
setOptions($link_name)
setOptions string $link_name
$url
Definition: shib_logout.php:72
Class ilDataCollectionRecordViewGUI.
getSyntaxStylePath()
get syntax style path
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 ilDataCollectionRecord.
Class ilObjDataCollectionGUI.
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 hasValidViewDefinition(ilDataCollectionRecord $record_obj)
static _getViewDefinitionId(ilDataCollectionRecord $record_obj)
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
getContentStylePath($a_style_id)
get content style path
global $lng
Definition: privfeed.php:40
loadSession()
If we come from a goto Link we need to build up the session data.
if($_REQUEST['ilias_path']) define('ILIAS_HTTP_PATH' $_REQUEST['ilias_path']
Definition: index.php:7
$html
Definition: example_001.php:87
determineNextPrevRecords()
Find the previous/next record from the current position.