CMS  Version 3.9
native_date_field_renderer.inc
Go to the documentation of this file.
1 <?php
7 Fakoli::usingFeature("field_renderers");
8 
9 class NativeDateFieldRenderer extends DateFieldRenderer
10 {
12  {
13  trace("Instantiating NativeDateFieldRenderer for $field", 3);
14  $this->DateFieldRenderer($parent, $field);
15  }
16 
17  function renderScript($field)
18  {
19  }
20 
21  function addValidatorsToForm($field, $required = false)
22  {
23  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
24 
25  if($required)
26  {
27  $this->parent->validator->add(new RequiredValidator($field, $label));
28  }
29 
30  }
31 
32  function renderField($field)
33  {
34  $obj = $this->parent->data;
35  $value = $obj->get($field);
36 
37  // JDG 10/1/2010 check for empty saved string
38  $date = "";
39 
40  if ($value AND $value != '0000-00-00')
41  {
42  $date = DateTypeRenderer::format($obj->reformatFromSQLDate($value), "Y-m-d");
43  }
44 
45  $this->_startField($field);
46  echo "<input id='{$this->parent->id}_{$field}' type='date' name='{$field}' value='$date'/>";
47  $this->_endField($field);
48  }
49 
51  {
52  }
53 
55  {
56  if ($mode == "range")
57  {
58  $date_from = $this->parent->params->get($field, "from");
59  $date_to = $this->parent->params->get($field, "to");
60 
61  $this->_startField($field);
62 
63  echo "<input type='date' name='$field:from' value='$date_from'/>";
64  echo " to <input type='date' name='$field:to' value='$date_to'/>\n";
65 
66  $this->_endField($field);
67  }
68  else
69  {
70  $date = $this->parent->params->get($field, $mode);
71 
72  $this->_startField($field);
73  echo "<input type='date' name='$field:$mode' value='$date'/>";
74  $this->_endField($field);
75  }
76  }
77 
79  {
80 
81  $obj = $this->parent->data;
82 
83  $this->_startField($field);
84  echo $this->format($obj->get($field));
85 
86  // AJG - if the field is read-only but the form is not, add a hidden field to
87  // retain the field value upon submission.
88 
89  if (!$this->parent->readOnlyForm)
90  {
91  $value = $obj->get($field);
92  echo "<input type='hidden' name='$field' value='{$value}'/>";
93  }
94 
95  $this->_endField();
96  }
97 
98  function preProcess($field = "")
99  {
100  //TODO
101  }
102 }?>
$parent
Definition: templates.inc:42
static usingFeature()
Uses the specified framework feature(s).
Definition: core.inc:388
addValidatorsToForm($field, $required=false)
$date
Definition: event_list.inc:51
$mode