ILIAS  release_4-3 Revision
 All Data Structures Namespaces Files Functions Variables Groups Pages
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 
11 
12 
24 {
28  protected $dcl_gui_object;
29 
30  public function __construct($a_dcl_object)
31  {
32  global $tpl;
33 
34  $this->dcl_gui_object = $a_dcl_object;
35 
36  $this->record_id = $_GET['record_id'];
37  $this->record_obj = ilDataCollectionCache::getRecordCache($this->record_id);
38 
39  // content style (using system defaults)
40  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
41 
42  $tpl->setCurrentBlock("SyntaxStyle");
43  $tpl->setVariable("LOCATION_SYNTAX_STYLESHEET",
45  $tpl->parseCurrentBlock();
46 
47  $tpl->setCurrentBlock("ContentStyle");
48  $tpl->setVariable("LOCATION_CONTENT_STYLESHEET",
50  $tpl->parseCurrentBlock();
51  }
52 
56  public function &executeCommand()
57  {
58  global $ilCtrl;
59 
60  $cmd = $ilCtrl->getCmd();
61 
62  switch($cmd)
63  {
64  default:
65  $this->$cmd();
66  break;
67  }
68  }
69 
74  public static function _getViewDefinitionId($record_obj)
75  {
76  return ilDataCollectionRecordViewViewdefinition::getIdByTableId($record_obj->getTableId());
77  }
78 
83  public function renderRecord()
84  {
85  global $ilTabs, $tpl, $ilCtrl, $lng;
86 
87  $rctpl = new ilTemplate("tpl.record_view.html", true, true, "Modules/DataCollection");
88 
89  $ilTabs->setTabActive("id_content");
90 
91  $view_id = self::_getViewDefinitionId($this->record_obj);
92 
93  if(!$view_id){
94  $ilCtrl->redirectByClass("ildatacollectionrecordlistgui", "listRecords");
95  }
96 
97  // see ilObjDataCollectionGUI->executeCommand about instantiation
98  include_once("./Modules/DataCollection/classes/class.ilDataCollectionRecordViewViewdefinitionGUI.php");
99  $pageObj = new ilDataCollectionRecordViewViewdefinitionGUI($this->record_obj->getTableId(), $view_id);
100  include_once("./Services/Style/classes/class.ilObjStyleSheet.php");
101  $pageObj->setStyleId(ilObjStyleSheet::getEffectiveContentStyleId(0, "dcl"));
102 
103 
104  $html = $pageObj->getHTML();
105  $rctpl->addCss("./Services/COPage/css/content.css");
106  $rctpl->fillCssFiles();
107  $table = ilDataCollectionCache::getTableCache($this->record_obj->getTableId());
108  foreach($table->getFields() as $field)
109  {
110  //ILIAS_Ref_Links
111  $pattern = '/\[dcliln field="'.preg_quote($field->getTitle(), "/").'"\](.*?)\[\/dcliln\]/';
112  if (preg_match($pattern,$html)) {
113  $html = preg_replace($pattern, $this->record_obj->getRecordFieldSingleHTML($field->getId(),$this->setOptions("$1")), $html);
114  }
115 
116  //DataCollection Ref Links
117  $pattern = '/\[dclrefln field="'.preg_quote($field->getTitle(), "/").'"\](.*?)\[\/dclrefln\]/';
118  if (preg_match($pattern ,$html)) {
119  $this->currentField = $field;
120  $html = preg_replace_callback($pattern, array($this, "doReplace"), $html);
121  }
122 
123  $pattern = '/\[ext tableOf="'.preg_quote($field->getTitle(), "/").'" field="(.*?)"\]/';
124  if (preg_match($pattern ,$html)) {
125  $this->currentField = $field;
126  $html = preg_replace_callback($pattern, array($this, "doExtReplace"), $html);
127  }
128 
129  $html = str_ireplace("[".$field->getTitle()."]", $this->record_obj->getRecordFieldHTML($field->getId()), $html);
130 
131  }
132  $rctpl->setVariable("CONTENT",$html);
133 
134  //Permanent Link
135  include_once("./Services/PermanentLink/classes/class.ilPermanentLinkGUI.php");
136  $perma_link = new ilPermanentLinkGUI("dcl", $_GET["ref_id"], "_".$_GET['record_id']);
137  $rctpl->setVariable("PERMA_LINK", $perma_link->getHTML());
138 
139 
140  $tpl->setContent($rctpl->get());
141  }
142 
143  public function doReplace($found){
144  return $this->record_obj->getRecordFieldSingleHTML($this->currentField->getId(),$this->setOptions($found[1]));
145  }
146 
147  public function doExtReplace($found){
148  $ref_rec_ids = $this->record_obj->getRecordFieldValue($this->currentField->getId());
149  if(!is_array($ref_rec_ids))
150  $ref_rec_ids = array($ref_rec_ids);
151  if(!count($ref_rec_ids) || !$ref_rec_ids)
152  return;
153  $ref_recs = array();
154  foreach($ref_rec_ids as $ref_rec_id)
155  $ref_recs[] = ilDataCollectionCache::getRecordCache($ref_rec_id);
156  $field = $ref_recs[0]->getTable()->getFieldByTitle($found[1]);
157 
158  $tpl = new ilTemplate("tpl.reference_list.html", true, true, "Modules/DataCollection");
159  $tpl->setCurrentBlock("reference_list");
160 
161  if(!$field){
162 // if(ilObjDataCollection::_hasWriteAccess($this->dcl_gui_object->ref_id))
163 // ilUtil::sendInfo("Bad Viewdefinition at [ext tableOf=\"".$field->getTitle()."\" ...]", true);
164  return;
165  }
166 
167  foreach($ref_recs as $ref_record){
168  $tpl->setCurrentBlock("reference");
169  $tpl->setVariable("CONTENT", $ref_record->getRecordFieldHTML($field->getId()));
170  $tpl->parseCurrentBlock();
171  }
172 
173  //$ref_rec->getRecordFieldHTML($field->getId())
174  if($field)
175  return $tpl->get();
176  }
177 
182  private function setOptions($link_name)
183  {
184  $options = array();
185  $options['link']['display'] = true;
186  $options['link']['name'] = $link_name;
187  return $options;
188  }
189 }
190 
191 ?>