Framework  3.9
DateTimeFieldRenderer Class Reference

Field renderer for date data fields. More...

+ Inheritance diagram for DateTimeFieldRenderer:
+ Collaboration diagram for DateTimeFieldRenderer:

Public Member Functions

 DateTimeFieldRenderer (&$parent)
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. More...
 
 renderScript ($field)
 FieldRenderers can override this method to provide any Javascript that their control requires for an edit form. More...
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderSearchScript ($field, $mode)
 FieldRenderers can override this method to provide any Javascript that the control requires when being used in a search form. More...
 
 renderSearchField ($field, $mode)
 FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form. More...
 
 renderReadOnly ($field)
 
 preProcess ($field="")
 FieldRenderers can override this method to provide behavior that occurs prior to the saving of the parent form's target object to the database. More...
 
 format ($field)
 
- Public Member Functions inherited from FieldRenderer
 FieldRenderer ($parent)
 Constructor. More...
 
 _printLabel ($field, $colspan=1, $styles="", $annotation="")
 Internal method to generate the HTML for the field label. More...
 
 _getLabel ($field, $addSuffix=true)
 
 _startField ($field, $styles="")
 Internal method to generate the starting HTML for the field (including the label) More...
 
 _endField ($field)
 Internal method to generate the closing HTML for the field. More...
 
 addSearchValidatorsToForm ($field, $mode, $required=false)
 For SearchForm, the validator field needs to match the name tag in the form which is in the format field:mode. More...
 
 formatName ($item, $name)
 Formats the given DataItem based on the supplied format string. More...
 
 renderOnSubmitHandler ($field)
 FieldRenderers can override this method to provide any Javascript that must be executed when the form is submitted on the client. More...
 
 postProcess ($field="")
 FieldRenderers can override this method to provide behavior that occurs after the parent form's target object has been saved to the database. More...
 

Public Attributes

 $validator
 
 $requireTime = true
 
 $template = ""
 
- Public Attributes inherited from FieldRenderer
 $parent = null
 
 $labelSuffix = ""
 
 $colspan = 1
 
 $annotateBefore = false
 
 $annotateNextLine = true
 
 $hideLabel = false
 
 $onPreProcess = null
 callback hook for processing prior to saving the form's data object - individual renderers may override with custom processing More...
 
 $onPostProcess = null
 callback hook for processing after saving the form's data object - individual renderers may override with custom processing More...
 

Detailed Description

Field renderer for date data fields.

Renders with date format validation and a date picking popup widget.

@template - field formatting format for readonly is standard "F d, Y", accepts "long", "daylong", and "short" and any format string used by php date function

Definition at line 48 of file datetime_field_renderer.inc.

Member Function Documentation

◆ addValidatorsToForm()

DateTimeFieldRenderer::addValidatorsToForm (   $field,
  $required = false 
)

This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer.

Fields that need custom validation or a custom required validator should override this function.

Parameters
string$fieldthe field name
boolean$required- whether the field is required

Reimplemented from FieldRenderer.

Definition at line 59 of file datetime_field_renderer.inc.

60  {
61  $label = isset($this->label) ? $this->label : $this->parent->prettifyFieldName($field);
62 
63  $this->parent->validator->add(new DateValidator($field, $label));
64  $this->parent->validator->add(new TimeValidator($field, $label));
65 
66  if($required)
67  {
68  $this->parent->validator->add(new RequiredValidator($field, $label));
69  if($this->requireTime)
70  $this->parent->validator->add(new RequiredTimeValidator($field, $label . " Time"));
71  }
72  }
Date Validator.
Definition: validation.inc:338
RequiredTimeValidator.
Definition: validation.inc:702
RequiredField Validator.
Definition: validation.inc:76
TimeValidator.
Definition: validation.inc:658

◆ DateTimeFieldRenderer()

DateTimeFieldRenderer::DateTimeFieldRenderer ( $parent)

Definition at line 54 of file datetime_field_renderer.inc.

55  {
56  $this->FieldRenderer($parent);
57  }
FieldRenderer($parent)
Constructor.

◆ format()

DateTimeFieldRenderer::format (   $field)

Definition at line 224 of file datetime_field_renderer.inc.

225  {
226  return DateTimeTypeRenderer::format($this->parent->data->get($field), $this->template);
227  }
static format($datetime, $template="")

◆ preProcess()

DateTimeFieldRenderer::preProcess (   $field = "")

FieldRenderers can override this method to provide behavior that occurs prior to the saving of the parent form's target object to the database.

For example, the FileUploadFieldRenderer overrides this method to process the uploading of the file and then store the location in the associated field in the target object.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 198 of file datetime_field_renderer.inc.

199  {
200  $hh = checkNumeric($_POST["{$field}_hh"]);
201  if(intval($hh) == 0) $hh = "00";
202  $mm = checkNumeric($_POST["{$field}_mm"]);
203  if(intval($mm) == 0) $mm = "00";
204  $aa = $_POST["{$field}_aa"];
205  $dd = $_POST["{$field}"];
206 
207  if (!$dd)
208  {
209  $this->parent->data->set($field, $this->parent->data->reformatToSQLDate("00/00/0000 00:00:00"));
210  return;
211  }
212  if($hh == "00" && $mm == "00")
213  {
214  $this->parent->data->set($field, $this->parent->data->reformatToSQLDate("$dd"));
215  return;
216  }
217 
218  if ($aa != "AM" && $aa != "PM") throw new FakoliException("Invalid meridiem");
219  if ($aa == "PM" && $hh != "12") $hh += 12;
220  if ($aa == "AM" && $hh == "12") $hh = "00";
221  $this->parent->data->set($field, $this->parent->data->reformatToSQLDate("$dd $hh:$mm:00"));
222  }
checkNumeric($p)
Security helper function.
Definition: functions.inc:630

◆ renderField()

DateTimeFieldRenderer::renderField (   $field)

FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 91 of file datetime_field_renderer.inc.

92  {
93  $obj = $this->parent->data;
94  $value = $obj->get($field);
95 
96  // JDG 10/1/2010 check for empty saved string
97  $date = "";
98  if($value AND $value != '0000-00-00 00:00:00')
99  $date = DateTimeTypeRenderer::format($obj->reformatFromSQLDate($value), "m/d/Y");
100 
101  $this->_startField($field);
102  echo "<input id='{$this->parent->id}_{$field}' type='text' name='$field' value='$date' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar.toggle(this)'>\n";
103 
104  // If no time component, show as blank, not 12:00 AM
105  if ($value AND !preg_match("/00:00:00$/", $value))
106  {
107  $text = date("h/i/A", strtotime($value));
108  list($hh, $mm, $aa) = explode("/", $text);
109  }
110 
111  echo "<div id='{$this->parent->id}_{$field}_block' style='display: inline'>\n";
112  echo "&nbsp;&nbsp;<input type='text' value='$hh' name='{$field}_hh' size='2' maxlength='2' onkeydown='return maskInput(event);'>
113  &nbsp;:&nbsp;<input type='text' value='$mm' name='{$field}_mm' size='2' maxlength='2' onkeydown='return maskInput(event);'>";
114  echo "&nbsp;<select name='{$field}_aa'><option";
115  if ($aa == 'AM') echo " selected";
116  echo ">AM</option><option";
117  if ($aa == 'PM') echo " selected";
118  echo ">PM</option></select>";
119  echo "</div>\n";
120 
121  $this->_endField($field);
122  }
_startField($field, $styles="")
Internal method to generate the starting HTML for the field (including the label)
_endField($field)
Internal method to generate the closing HTML for the field.

◆ renderReadOnly()

DateTimeFieldRenderer::renderReadOnly (   $field)

Definition at line 180 of file datetime_field_renderer.inc.

181  {
182  $this->_startField($field);
183 
184  echo $this->format($field);
185 
186  // AJG - if the field is read-only but the form is not, add a hidden field to
187  // retain the field value upon submission.
188  if (!$this->parent->readOnlyForm)
189  {
190  $obj = $this->parent->data;
191  $value = $obj->get($field);
192  echo "<input type='hidden' name='$field' value='{$value}'/>";
193  }
194 
195  $this->_endField($field);
196  }

◆ renderScript()

DateTimeFieldRenderer::renderScript (   $field)

FieldRenderers can override this method to provide any Javascript that their control requires for an edit form.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 74 of file datetime_field_renderer.inc.

75  {
76  $script = "";
77 
78  if (!$this->_includedDateScript)
79  {
80  echo "<script src='{$this->parent->componentPath}/calendar/sonjara_calendar.js' type='text/javascript'></script>\n";
81  echo "<link href='{$this->parent->componentPath}/calendar/sonjara_calendar.css' type='text/css' rel='stylesheet'>\n";
82  $this->_includedDateScript = true;
83  }
84 
85  $calendar = "{$field}_calendar";
86  echo "<script type='text/javascript'>\n";
87  echo "var $calendar = new Calendar('$calendar', '', '{$this->parent->id}_{$field}');\n";
88  echo "</script>\n";
89  }

◆ renderSearchField()

DateTimeFieldRenderer::renderSearchField (   $field,
  $mode 
)

FieldRenderers must override this method to provide the HTML implementation of the control displayed for the field in a search form.

Parameters
string$fieldthe field name

Reimplemented from FieldRenderer.

Definition at line 154 of file datetime_field_renderer.inc.

155  {
156  if ($mode == "range")
157  {
158  $date_from = $this->parent->params->get($field, "from");
159  $date_to = $this->parent->params->get($field, "to");
160  echo "<tr>\n";
161  $this->_printLabel($field);
162  echo "<td>";
163  echo "<input type='text' name='$field:from' value='$date_from' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar_from.toggle(this)'>";
164  echo " to <input type='text' name='$field:to' value='$date_to' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar_to.toggle(this)'></td>\n";
165  echo "</td>\n";
166  echo "</tr>\n";
167  }
168  else
169  {
170  $date = $this->parent->params->get($field, $mode);
171  echo "<tr>\n";
172  $this->_printLabel($field);
173  echo "<td>";
174  echo "<input type='text' name='$field:$mode' value='$date' size='12'>&nbsp;<img src='{$this->parent->componentPath}/calendar/calendar.gif' alt='Popup Calendar' align='absmiddle' border='0' onclick='{$field}_calendar_{$mode}.toggle(this)'></td>\n";
175  echo "</td>\n";
176  echo "</tr>\n";
177  }
178  }
_printLabel($field, $colspan=1, $styles="", $annotation="")
Internal method to generate the HTML for the field label.

◆ renderSearchScript()

DateTimeFieldRenderer::renderSearchScript (   $field,
  $mode 
)

FieldRenderers can override this method to provide any Javascript that the control requires when being used in a search form.

Parameters
string$fieldthe field name
string$modethe search mode for the specific field ('equal', 'like', 'from', 'to', 'range')

Reimplemented from FieldRenderer.

Definition at line 124 of file datetime_field_renderer.inc.

125  {
126  $script = "";
127 
128  if (!$this->_includedDateScript)
129  {
130  echo "<script src='{$this->parent->componentPath}/calendar/sonjara_calendar.js' type='text/javascript'></script>\n";
131  echo "<link href='{$this->parent->componentPath}/calendar/sonjara_calendar.css' type='text/css' rel='stylesheet'>\n";
132  $this->_includedDateScript = true;
133  }
134 
135  if ($mode == "range")
136  {
137  $calendar_from = "{$field}_calendar_from";
138  $calendar_to = "{$field}_calendar_to";
139 
140  echo "<script type='text/javascript'>\n";
141  echo "var $calendar_from = new Calendar('$calendar_from', '{$this->parent->id}', '$field:from');\n";
142  echo "var $calendar_to = new Calendar('$calendar_to', '{$this->parent->id}', '$field:to');\n";
143  echo "</script>\n";
144  }
145  else
146  {
147  $calendar = "{$field}_calendar_{$mode}";
148  echo "<script type='text/javascript'>\n";
149  echo "var $calendar = new Calendar('$calendar', '{$this->parent->id}', '$field:$mode');\n";
150  echo "</script>\n";
151  }
152  }

Member Data Documentation

◆ $requireTime

DateTimeFieldRenderer::$requireTime = true

Definition at line 51 of file datetime_field_renderer.inc.

◆ $template

DateTimeFieldRenderer::$template = ""

Definition at line 52 of file datetime_field_renderer.inc.

◆ $validator

DateTimeFieldRenderer::$validator

Definition at line 50 of file datetime_field_renderer.inc.


The documentation for this class was generated from the following file: