/** * Substitute field values in placehoders like [[Field Title]] from current record * * @param string $placeholder * * @throws ilException * @return string */ protected function substituteFieldValue($placeholder) { if (isset(self::$cache_fields[$placeholder])) { $field = self::$cache_fields[$placeholder]; } else { $table = ilDataCollectionCache::getTableCache($this->record->getTableId()); // TODO May need caching per table in future $field_title = preg_replace('#^\\[\\[(.*)\\]\\]#', "\$1", $placeholder); $field = $table->getFieldByTitle($field_title); if ($field === NULL) { // Workaround for standardfields - title my be ID $field = $table->getField($field_title); if ($field === NULL) { global $lng; /** * @var $lng ilLanguage */ $lng->loadLanguageModule('dcl'); // throw new ilException("Field with title '$field_title' not found"); throw new ilException(sprintf($lng->txt('dcl_err_formula_field_not_found'), $field_title)); } } self::$cache_fields[$placeholder] = $field; } return $this->record->getRecordFieldHTML($field->getId()); }
/** * @param bool $editComments */ public function renderRecord($editComments = false) { global $ilTabs, $tpl, $ilCtrl, $lng; $rctpl = new ilTemplate("tpl.record_view.html", false, true, "Modules/DataCollection"); $ilTabs->setTabActive("id_content"); $view_id = self::_getViewDefinitionId($this->record_obj); if (!$view_id) { $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords"); } // see ilObjDataCollectionGUI->executeCommand about instantiation include_once "./Modules/DataCollection/classes/class.ilDataCollectionRecordViewViewdefinitionGUI.php"; $pageObj = new ilDataCollectionRecordViewViewdefinitionGUI($this->record_obj->getTableId(), $view_id); include_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl")); $html = $pageObj->getHTML(); $rctpl->addCss("./Services/COPage/css/content.css"); $rctpl->fillCssFiles(); $table = ilDataCollectionCache::getTableCache($this->record_obj->getTableId()); foreach ($table->getRecordFields() as $field) { //ILIAS_Ref_Links $pattern = '/\\[dcliln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dcliln\\]/'; if (preg_match($pattern, $html)) { $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(), $this->setOptions("\$1")), $html); } //DataCollection Ref Links $pattern = '/\\[dclrefln field="' . preg_quote($field->getTitle(), "/") . '"\\](.*?)\\[\\/dclrefln\\]/'; if (preg_match($pattern, $html)) { $this->currentField = $field; $html = preg_replace_callback($pattern, array($this, "doReplace"), $html); } $pattern = '/\\[ext tableOf="' . preg_quote($field->getTitle(), "/") . '" field="(.*?)"\\]/'; if (preg_match($pattern, $html)) { $this->currentField = $field; $html = preg_replace_callback($pattern, array($this, "doExtReplace"), $html); } $html = str_ireplace("[" . $field->getTitle() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html); } foreach ($table->getStandardFields() as $field) { $html = str_ireplace("[" . $field->getId() . "]", $this->record_obj->getRecordFieldSingleHTML($field->getId()), $html); } $rctpl->setVariable("CONTENT", $html); //Permanent Link $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_" . $_GET['record_id']); $tpl->setVariable('PRMLINK', $perma_link->getHTML()); // Buttons for previous/next records if ($this->is_enabled_paging) { $prevNextLinks = $this->renderPrevNextLinks(); $rctpl->setVariable('PREV_NEXT_RECORD_LINKS', $prevNextLinks); $ilCtrl->clearParameters($this); // #14083 $rctpl->setVariable('FORM_ACTION', $ilCtrl->getFormAction($this)); $rctpl->setVariable('RECORD', $lng->txt('dcl_record')); $rctpl->setVariable('RECORD_FROM_TOTAL', sprintf($lng->txt('dcl_record_from_total'), $this->current_record_position, count($this->record_ids))); $rctpl->setVariable('SELECT_OPTIONS', $this->renderSelectOptions()); } // Edit Button if ($this->record_obj->hasPermissionToEdit((int) $_GET['ref_id'])) { $button = ilLinkButton::getInstance(); $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'table_id', $this->table->getId()); $ilCtrl->setParameterByClass('ildatacollectionrecordeditgui', 'redirect', ilDataCollectionRecordEditGUI::REDIRECT_DETAIL); $ilCtrl->saveParameterByClass('ildatacollectionrecordeditgui', 'record_id'); $button->setUrl($ilCtrl->getLinkTargetByClass('ildatacollectionrecordeditgui', 'edit')); $button->setCaption($lng->txt('dcl_edit_record'), false); $rctpl->setVariable('EDIT_RECORD_BUTTON', $button->render()); } // Comments if ($this->table->getPublicCommentsEnabled()) { $rctpl->setVariable('COMMENTS', $this->renderComments($editComments)); } $tpl->setContent($rctpl->get()); }