ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.arDisplayGUI.php
Go to the documentation of this file.
1 <?php
2 require_once('./Services/Form/classes/class.ilPropertyFormGUI.php');
3 require_once('./Services/ActiveRecord/Views/Display/class.arDisplayField.php');
4 require_once('./Services/ActiveRecord/Views/Display/class.arDisplayFields.php');
5 
14 {
15 
19  protected $record;
23  protected $parent_gui;
27  protected $ctrl;
31  protected $tpl;
35  protected $title = "";
39  protected $fields = array();
43  protected $data = array();
47  protected $back_button_name = "";
51  protected $back_button_target = "";
55  protected $template;
56 
57 
62  public function __construct(arGUI $parent_gui, ActiveRecord $ar)
63  {
64  global $DIC;
65  $ilCtrl = $DIC['ilCtrl'];
66  $tpl = $DIC['tpl'];
71  $this->ctrl = $ilCtrl;
72  $this->tpl = $tpl;
73  $this->ar = $ar;
74  $this->parent_gui = $parent_gui;
75 
76  $this->ctrl->saveParameter($parent_gui, 'ar_id');
77 
78  $this->init();
79  }
80 
81 
82  protected function init()
83  {
84  $this->initTitle();
85  $this->initFields();
86  $this->initBackButton();
87  $this->initTemplate();
88  }
89 
90 
91  protected function initTitle()
92  {
93  $this->setTitle(strtolower(str_replace("Record", "", get_class($this->ar))));
94  }
95 
96 
97  protected function initFields()
98  {
99  $this->fields = new arDisplayFields($this->ar);
100  $this->customizeFields();
101  $this->fields->sortFields();
102  }
103 
104 
105  protected function customizeFields()
106  {
107  }
108 
109 
110  protected function initBackButton()
111  {
112  $this->setBackButtonName($this->txt("back", false));
113  $this->setBackButtonTarget($this->ctrl->getLinkTarget($this->parent_gui, "index"));
114  }
115 
116 
117  protected function initTemplate()
118  {
119  $this->setTemplate(new ilTemplate("tpl.display.html", true, true, "Services/ActiveRecord"));
120  }
121 
122 
126  public function getHtml()
127  {
128  $this->getTemplate()->setVariable("TITLE", $this->title);
129  $this->setArFieldsData();
130  $this->getTemplate()->setVariable("BACK_BUTTON_NAME", $this->getBackButtonName());
131  $this->getTemplate()->setVariable("BACK_BUTTON_TARGET", $this->getBackButtonTarget());
132 
133  return $this->getTemplate()->get();
134  }
135 
136 
137  protected function setArFieldsData()
138  {
139  foreach ($this->fields->getFields() as $field) {
143  if ($field->getVisible()) {
144  $get_function = $field->getGetFunctionName();
145  $value = $this->ar->$get_function();
146  $this->getTemplate()->setCurrentBlock("entry");
147  $this->getTemplate()->setVariable("ITEM", $this->txt($field->getTxt()));
148  $this->getTemplate()->setVariable("VALUE", $this->setArFieldData($field, $value));
149  $this->getTemplate()->parseCurrentBlock();
150  }
151  }
152  }
153 
154 
161  protected function setArFieldData(arDisplayField $field, $value)
162  {
163  if ($field->getCustomField()) {
164  return $this->setCustomFieldData($field);
165  } else {
166  if ($value == null) {
167  return $this->setEmptyFieldData($field);
168  } else {
169  if ($field->getIsCreatedByField()) {
170  return $this->setCreatedByData($field, $value);
171  } else {
172  if ($field->getIsModifiedByField()) {
173  return $this->setModifiedByData($field, $value);
174  } else {
175  switch ($field->getFieldType()) {
176  case 'integer':
177  case 'float':
178  return $this->setNumericData($field, $value);
179  case 'text':
180  return $this->setTextData($field, $value);
181  case 'date':
182  case 'time':
183  case 'timestamp':
184  return $this->setDateTimeData($field, $value);
185  case 'clob':
186  return $this->setClobData($field, $value);
187  }
188  }
189  }
190  }
191  }
192  }
193 
194 
200  protected function setEmptyFieldData(arDisplayField $field)
201  {
202  return $this->txt("", false);
203  }
204 
205 
211  protected function setCustomFieldData(arDisplayField $field)
212  {
213  return "CUSTOM-OVERRIDE: setCustomFieldData";
214  }
215 
216 
223  protected function setModifiedByData(arDisplayField $field, $value)
224  {
225  $user = new ilObjUser($value);
226 
227  return $user->getPublicName();
228  }
229 
230 
237  protected function setCreatedByData(arDisplayField $field, $value)
238  {
239  $user = new ilObjUser($value);
240 
241  return $user->getPublicName();
242  }
243 
244 
251  protected function setNumericData(arDisplayField $field, $value)
252  {
253  return $value;
254  }
255 
256 
263  protected function setTextData(arDisplayField $field, $value)
264  {
265  return $value;
266  }
267 
268 
275  protected function setDateTimeData(arDisplayField $field, $value)
276  {
277  $datetime = new ilDateTime($value, IL_CAL_DATETIME);
278 
280  }
281 
282 
289  protected function setClobData(arDisplayField $field, $value)
290  {
291  return $value;
292  }
293 
294 
299  {
300  $this->back_button_name = $back_button_name;
301  }
302 
303 
307  public function getBackButtonName()
308  {
310  }
311 
312 
317  {
318  $this->back_button_target = $back_button_target;
319  }
320 
321 
325  public function getBackButtonTarget()
326  {
328  }
329 
330 
335  {
336  $this->fields = $fields;
337  }
338 
339 
343  public function getFields()
344  {
345  return $this->fields;
346  }
347 
348 
352  public function getFieldsAsArray()
353  {
354  return $this->getFields()->getFields();
355  }
356 
357 
363  public function getField($field_name)
364  {
365  return $this->getFields()->getField($field_name);
366  }
367 
368 
372  public function addField(arDisplayField $field)
373  {
374  $this->getFields()->addField($field);
375  }
376 
377 
381  public function setTitle($title)
382  {
383  $this->title = $title;
384  }
385 
386 
390  public function getTitle()
391  {
392  return $this->title;
393  }
394 
395 
399  public function setTemplate($template)
400  {
401  $this->template = $template;
402  }
403 
404 
408  public function getTemplate()
409  {
410  return $this->template;
411  }
412 
413 
420  protected function txt($txt, $plugin_txt = true)
421  {
422  return $this->parent_gui->txt($txt, $plugin_txt);
423  }
424 }
const IL_CAL_DATETIME
addField(arDisplayField $field)
Class ActiveRecord.
global $DIC
Definition: saml.php:7
setBackButtonTarget($back_button_target)
txt($txt, $plugin_txt=true)
setDateTimeData(arDisplayField $field, $value)
setTemplate($template)
static formatDate(ilDateTime $date, $a_skip_day=false, $a_include_wd=false, $include_seconds=false)
Format a date public.
setBackButtonName($back_button_name)
global $ilCtrl
Definition: ilias.php:18
$errors fields
Definition: imgupload.php:51
setEmptyFieldData(arDisplayField $field)
setNumericData(arDisplayField $field, $value)
special template class to simplify handling of ITX/PEAR
setTextData(arDisplayField $field, $value)
GUI-Class arDisplayFields.
Date and time handling
setArFieldData(arDisplayField $field, $value)
getField($field_name)
$txt
Definition: error.php:11
$user
Definition: migrateto20.php:57
setModifiedByData(arDisplayField $field, $value)
setCustomFieldData(arDisplayField $field)
setClobData(arDisplayField $field, $value)
setFields(arDisplayFields $fields)
GUI-Class arDisplayField.
setCreatedByData(arDisplayField $field, $value)
GUI-Class arDisplayGUI.