ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.arDisplayGUI.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
3 require_once('./Customizing/global/plugins/Libraries/ActiveRecord/Views/Display/class.arDisplayField.php');
4 require_once('./Customizing/global/plugins/Libraries/ActiveRecord/Views/Display/class.arDisplayFields.php');
5 
13 class arDisplayGUI {
14 
18  protected $record;
22  protected $parent_gui;
26  protected $ctrl;
30  protected $tpl;
34  protected $title = "";
38  protected $fields = array();
42  protected $data = array();
46  protected $back_button_name = "";
50  protected $back_button_target = "";
54  protected $template;
55 
56 
61  public function __construct(arGUI $parent_gui, ActiveRecord $ar) {
62  global $ilCtrl, $tpl;
67  $this->ctrl = $ilCtrl;
68  $this->tpl = $tpl;
69  $this->ar = $ar;
70  $this->parent_gui = $parent_gui;
71 
72  $this->ctrl->saveParameter($parent_gui, 'ar_id');
73 
74  $this->init();
75  }
76 
77 
78  protected function init() {
79  $this->initTitle();
80  $this->initFields();
81  $this->initBackButton();
82  $this->initTemplate();
83  }
84 
85 
86  protected function initTitle() {
87  $this->setTitle(strtolower(str_replace("Record", "", get_class($this->ar))));
88  }
89 
90 
91  protected function initFields() {
92  $this->fields = new arDisplayFields($this->ar);
93  $this->customizeFields();
94  $this->fields->sortFields();
95  }
96 
97 
98  protected function customizeFields() {
99  }
100 
101 
102  protected function initBackButton() {
103  $this->setBackButtonName($this->txt("back", false));
104  $this->setBackButtonTarget($this->ctrl->getLinkTarget($this->parent_gui, "index"));
105  }
106 
107 
108  protected function initTemplate() {
109  $this->setTemplate(new ilTemplate("tpl.display.html", true, true, "Customizing/global/plugins/Libraries/ActiveRecord"));
110  }
111 
112 
116  public function getHtml() {
117 
118  $this->getTemplate()->setVariable("TITLE", $this->title);
119  $this->setArFieldsData();
120  $this->getTemplate()->setVariable("BACK_BUTTON_NAME", $this->getBackButtonName());
121  $this->getTemplate()->setVariable("BACK_BUTTON_TARGET", $this->getBackButtonTarget());
122 
123  return $this->getTemplate()->get();
124  }
125 
126 
127  protected function setArFieldsData() {
128  foreach ($this->fields->getFields() as $field) {
132  if ($field->getVisible()) {
133  $get_function = $field->getGetFunctionName();
134  $value = $this->ar->$get_function();
135  $this->getTemplate()->setCurrentBlock("entry");
136  $this->getTemplate()->setVariable("ITEM", $this->txt($field->getTxt()));
137  $this->getTemplate()->setVariable("VALUE", $this->setArFieldData($field, $value));
138  $this->getTemplate()->parseCurrentBlock();
139  }
140  }
141  }
142 
143 
150  protected function setArFieldData(arDisplayField $field, $value) {
151  if ($field->getCustomField()) {
152  return $this->setCustomFieldData($field);
153  } else {
154  if ($value == NULL) {
155  return $this->setEmptyFieldData($field);
156  } else {
157  if ($field->getIsCreatedByField()) {
158  return $this->setCreatedByData($field, $value);
159  } else {
160  if ($field->getIsModifiedByField()) {
161  return $this->setModifiedByData($field, $value);
162  } else {
163  switch ($field->getFieldType()) {
164  case 'integer':
165  case 'float':
166  return $this->setNumericData($field, $value);
167  case 'text':
168  return $this->setTextData($field, $value);
169  case 'date':
170  case 'time':
171  case 'timestamp':
172  return $this->setDateTimeData($field, $value);
173  case 'clob':
174  return $this->setClobData($field, $value);
175  }
176  }
177  }
178  }
179  }
180  }
181 
182 
188  protected function setEmptyFieldData(arDisplayField $field) {
189  return $this->txt("", false);
190  }
191 
192 
198  protected function setCustomFieldData(arDisplayField $field) {
199  return "CUSTOM-OVERRIDE: setCustomFieldData";
200  }
201 
202 
209  protected function setModifiedByData(arDisplayField $field, $value) {
210  $user = new ilObjUser($value);
211 
212  return $user->getPublicName();
213  }
214 
215 
222  protected function setCreatedByData(arDisplayField $field, $value) {
223  $user = new ilObjUser($value);
224 
225  return $user->getPublicName();
226  }
227 
228 
235  protected function setNumericData(arDisplayField $field, $value) {
236  return $value;
237  }
238 
239 
246  protected function setTextData(arDisplayField $field, $value) {
247  return $value;
248  }
249 
250 
257  protected function setDateTimeData(arDisplayField $field, $value) {
258  $datetime = new ilDateTime($value, IL_CAL_DATETIME);
259 
261  }
262 
263 
270  protected function setClobData(arDisplayField $field, $value) {
271  return $value;
272  }
273 
274 
279  $this->back_button_name = $back_button_name;
280  }
281 
282 
286  public function getBackButtonName() {
288  }
289 
290 
295  $this->back_button_target = $back_button_target;
296  }
297 
298 
302  public function getBackButtonTarget() {
304  }
305 
306 
311  $this->fields = $fields;
312  }
313 
314 
318  public function getFields() {
319  return $this->fields;
320  }
321 
322 
326  public function getFieldsAsArray() {
327  return $this->getFields()->getFields();
328  }
329 
330 
336  public function getField($field_name) {
337  return $this->getFields()->getField($field_name);
338  }
339 
340 
344  public function addField(arDisplayField $field) {
345  $this->getFields()->addField($field);
346  }
347 
348 
352  public function setTitle($title) {
353  $this->title = $title;
354  }
355 
356 
360  public function getTitle() {
361  return $this->title;
362  }
363 
364 
368  public function setTemplate($template) {
369  $this->template = $template;
370  }
371 
372 
376  public function getTemplate() {
377  return $this->template;
378  }
379 
380 
387  protected function txt($txt, $plugin_txt = true) {
388  return $this->parent_gui->txt($txt, $plugin_txt);
389  }
390 }