Framework  3.9
CheckListFieldRenderer Class Reference

CheckListFieldRenderer: Renders the specified list of options as a list of checkboxes from which multiple values can be selected. More...

+ Inheritance diagram for CheckListFieldRenderer:
+ Collaboration diagram for CheckListFieldRenderer:

Public Member Functions

 CheckListFieldRenderer (&$form, $field, $label, $options, $grouped=false)
 
 allowAddEntry ($text="or add new", $size=40)
 
 setSize ($width, $height, $scrollAfter=0)
 
 addFixedOption ($value)
 
 addDefaultOption ($value)
 
 getOptionCount ()
 
 renderField ($field)
 FieldRenderers must override this method to provide the HTML implementation of the control used to edit the field. More...
 
 renderScript ($field)
 FieldRenderers can override this method to provide any Javascript that their control requires for an edit form. More...
 
 renderReadOnly ($field)
 
 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...
 
 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...
 
- 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...
 
 addValidatorsToForm ($field, $required=false)
 This method is called by the AutoForm to add any default input validators that are required by the FieldRenderer. 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

 $options
 
 $addEntry
 
 $addEntryText
 
 $grouped
 
 $addEntrySize = 20
 
 $width
 
 $height
 
 $resizable = false
 
 $nobr = false
 
 $dropdown
 
 $dropdownMaxWidth = "340px"
 
 $dropdownMessage = "Click to Select Terms"
 
 $showSelectAll = false
 
 $separator = ", "
 The separator between values in read only list. More...
 
 $fixedOptions = array()
 
 $defaultOptions = array()
 
- 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

CheckListFieldRenderer: Renders the specified list of options as a list of checkboxes from which multiple values can be selected.

The results are stored in the associated field as a comma-separated list of values.

Parameters
obj$formthe AutoForm object, passed by reference
string$fieldthe name of the field defined in the dataitem class object in the datamodel folder whose values can be changed by the checkbox list This field name should match the field name in the database.
string$labelpresented on the form to the user to describe the list
array$optionsdefines the list of options available, as follows: $options = array ( 1 => "Option 1", 2 => "Option 2", 3 => "Option 3" ) For grouped lists, the structure would be:
 $options = 
      array("Group 1" =>
           array(
                1 => "Option 1",
                2 => "Option 2"),
             "Group 2"    =>
           array(
                3 => "Option 3"));
boolean$groupedspecifies whether the array defines a grouping structure for the checkbox list. The default is false.

Definition at line 73 of file checklist_field_renderer.inc.

Member Function Documentation

◆ addDefaultOption()

CheckListFieldRenderer::addDefaultOption (   $value)

Definition at line 134 of file checklist_field_renderer.inc.

135  {
136  $this->defaultOptions[$value] = $value;
137 
138  return $this;
139  }

◆ addFixedOption()

CheckListFieldRenderer::addFixedOption (   $value)

Definition at line 127 of file checklist_field_renderer.inc.

128  {
129  $this->fixedOptions[$value] = $value;
130 
131  return $this;
132  }

◆ allowAddEntry()

CheckListFieldRenderer::allowAddEntry (   $text = "or add new",
  $size = 40 
)

Definition at line 109 of file checklist_field_renderer.inc.

110  {
111  $this->addEntry = true;
112  $this->addEntryText = $text;
113  $this->addEntrySize = $size;
114 
115  return $this;
116  }

◆ CheckListFieldRenderer()

CheckListFieldRenderer::CheckListFieldRenderer ( $form,
  $field,
  $label,
  $options,
  $grouped = false 
)

Definition at line 93 of file checklist_field_renderer.inc.

94  {
95  $this->options = $options;
96  $this->grouped = $grouped;
97  $this->FieldRenderer($form);
98  if ($form->data->hasField($field))
99  {
100  $form->override($field, $label, $this);
101  }
102  else
103  {
104  $form->add($this, $field);
105  if ($label) $form->alias($field, $label);
106  }
107  }
FieldRenderer($parent)
Constructor.

◆ getOptionCount()

CheckListFieldRenderer::getOptionCount ( )

Definition at line 141 of file checklist_field_renderer.inc.

142  {
143  if (!$this->grouped) return count($this->options);
144 
145  $count = 0;
146 
147  foreach($this->options as $groupName => $group);
148  {
149  $count += count($group) + 1;
150  }
151 
152  return $count;
153  }

◆ preProcess()

CheckListFieldRenderer::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 452 of file checklist_field_renderer.inc.

453  {
454  $value = ($this->parent->method == "POST") ? $_POST[$field] : $_GET[$field];
455  $addEntry = ($this->parent->method == "POST") ? $_POST["{$field}_addEntry"] : $_GET["{$field}_addEntry"];
456 
457  if (is_array($value))
458  {
459  $this->parent->data->set($field, implode(",", array_values($value)));
460  }
461  else if (!$value)
462  {
463  $this->parent->data->set($field, "");
464  }
465  else
466  {
467  $this->parent->data->set($field, $value);
468  }
469 
470  trace("addEntry($field): $addEntry", 3);
471 
472  if ($addEntry)
473  {
474  if($this->parent->data->get($field))
475  {
476  $this->parent->data->set($field, $this->parent->data->get($field) . ",");
477  }
478 
479  $this->parent->data->set($field, $this->parent->data->get($field) . $addEntry);
480  }
481  }
trace($msg, $lvl=3, $callStack=null)
Send output to the trace log.
Definition: functions.inc:1010

◆ renderField()

CheckListFieldRenderer::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 155 of file checklist_field_renderer.inc.

156  {
157  $this->_startField($field);
158 
159  $rawValue = $this->parent->data->get($field);
160  if (is_array($rawValue))
161  {
162  $this->preProcess($field);
163  $rawValue = $this->parent->data->get($field);
164  }
165 
166  $values = explode(",", $rawValue);
167 
168  $divider = $this->horizontal ? " " : "";
169  $layout = $this->horizontal ? " style='display: inline'" : "";
170 
171  if ($this->showSelectAll)
172  {
173  echo "<a class='select_toggle' href='#' onclick='return {$this->parent->id}_{$field}_toggleSelectAll(this);'>Select All</a><br/>";
174  }
175 
176  if ($this->width && $this->height && $this->getOptionCount() > $this->scrollAfter)
177  {
178  $width = is_numeric($this->width) ? "{$this->width}px" : $this->width;
179  $height = is_numeric($this->height) ? "{$this->height}px" : $this->height;
180  $padding = ($width == "auto") ? "padding-right: 20px; " : "";
181 
182  $resizable = ($this->resizable && !$this->dropdown) ? " resizable": "";
183  $dropdown = $this->dropdown ? " multi_select_dropdown_list" : "";
184  echo "<div id='{$this->parent->id}_{$field}_container' class='selectbox scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height}; $padding overflow: auto'>\n";
185  }
186  else
187  {
188  echo "<div class='selectbox'>";
189  }
190 
191  $idx = 0;
192 
193  if ($this->grouped)
194  {
195  echo "<dl>\n";
196  foreach($this->options as $groupName => $group)
197  {
198  echo "<dt>$groupName</dt>\n<dd>\n";
199  foreach($group as $value => $text)
200  {
201  $checked = (array_search($value, $values) !== FALSE) ? " checked" : "";
202 
203  if ($this->nobr) { $text = str_replace(" ", "&nbsp;", $text); }
204 
205  echo "<label for='{$this->parent->id}_{$field}[$idx]'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}[$idx]' name='{$field}[$idx]' value='$value'$checked/>$text</label>$divider";
206  $idx++;
207  }
208 
209  echo "</dd>";
210  }
211  echo "</dl>";
212  }
213  else
214  {
215  if(count($this->options) > 0)
216  {
217  foreach($this->options as $value => $text)
218  {
219  $disabled = "";
220 
221  if ($this->fixedOptions[$value])
222  {
223  $disabled = " disabled";
224  $checked = " checked";
225  }
226  else if ($this->defaultOptions[$value])
227  {
228  $checked = "checked";
229  }
230  else
231  {
232  $checked = (array_search($value, $values) !== FALSE) ? " checked" : "";
233  }
234  if ($this->nobr) { $text = str_replace(" ", "&nbsp;", $text); }
235  echo "<label for='{$this->parent->id}_{$field}[$idx]'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}[$idx]' name='{$field}[$idx]' value='$value'$checked$disabled/>$text</label>$divider";
236  $idx++;
237  }
238 
239  if($this->addEntry)
240  {
241  foreach($values as $value)
242  {
243  if(!array_key_exists($value, $this->options))
244  $addEntryValue .= $value;
245  }
246  }
247  }
248  }
249 
250  if ($this->addEntry)
251  {
252  echo "&nbsp;{$this->addEntryText}&nbsp;";
253  }
254 
255  if ($this->addEntry)
256  {
257  echo "<input type='text' name='{$field}_addEntry' value='{$addEntryValue}' size='{$this->addEntrySize}'/>";
258  }
259 
260  // Save this count to loop through checkboxes on required validation
261  echo "<input type=\"hidden\" name=\"count_{$field}\" value=\"".$idx."\">";
262 
263  echo "</div>\n";
264 
265  $this->_endField($field);
266  }
preProcess($field="")
FieldRenderers can override this method to provide behavior that occurs prior to the saving of the pa...
_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()

CheckListFieldRenderer::renderReadOnly (   $field)

Definition at line 310 of file checklist_field_renderer.inc.

311  {
312  $this->_startField($field);
313 
314  $value = $this->parent->data->get($field);
315 
316  $items = explode(",", $value);
317 
318  if ($this->grouped)
319  {
320  foreach($this->options as $category => $options)
321  {
322  $out = "";
323 
324  foreach($items as $item)
325  {
326  if (array_key_exists($item, $options))
327  {
328  if (!$out)
329  {
330  $out = "$category: ";
331  }
332  else
333  {
334  $out .= $this->separator;
335  }
336 
337  $out .= $options[$item];
338  }
339  }
340 
341  if ($out) $answers[] = $out;
342  }
343  }
344  else
345  {
346  // JDG 3/12 - show option value, if found, instead of key
347 
348  foreach($items as $item)
349  {
350  $answers[] = array_key_exists($item, $this->options) ? $this->options[$item] : $item;
351  }
352  }
353 
354  $value = implode($this->separator, $answers);
355 
356  echo $value;
357 
358  $this->_endField($field);
359  }
$separator
The separator between values in read only list.

◆ renderScript()

CheckListFieldRenderer::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 268 of file checklist_field_renderer.inc.

269  {
270  if ($this->showSelectAll)
271  {
272  ?>
273  <script type="text/javascript">
274 
275  function <?echo $this->parent->id?>_<?echo $field ?>_toggleSelectAll(link)
276  {
277  link = document.id(link);
278 
279  var value = (link.innerHTML == "Select All");
280 
281  var container = document.id('<?echo $this->parent->id?>_<?echo $field?>_container');
282 
283  container.getElements("input[type=checkbox]").each(function(cbox)
284  {
285  cbox.set('checked', value);
286  });
287 
288  link.innerHTML = (value) ? "Deselect All" : "Select All";
289  if (container.multiSelect) container.multiSelect.selectionChanged();
290  return false;
291  }
292 
293  </script>
294  <?
295  }
296 
297  if ($this->dropdown)
298  {
299  ?>
300  <script type='text/javascript'>
301  window.addEvent('domready', function()
302  {
303  new MultiSelect('<?echo $this->parent->id?>_<?echo $field?>_container', {maxWidth: '<?echo $this->dropdownMaxWidth?>', message: '<?echo jsSafe($this->dropdownMessage)?>'});
304  });
305  </script>
306  <?
307  }
308  }

◆ renderSearchField()

CheckListFieldRenderer::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 369 of file checklist_field_renderer.inc.

370  {
371  $this->_startField($field);
372 
373  $rawValue = $this->parent->params->get($field, $mode);
374 
375  if (is_array($rawValue))
376  {
377  $rawValue = implode(",", array_values($rawValue));
378  $this->parent->params->set($field, $mode, $rawValue);
379  }
380 
381  $values = explode(",", $rawValue);
382  $values = array_combine($values, $values);
383 
384  $divider = $this->horizontal ? " " : "";
385  $layout = $this->horizontal ? " style='display: inline'" : "";
386 
387  if ($this->showSelectAll)
388  {
389  echo "<a href='#' onclick='return {$this->parent->id}_{$field}_toggleSelectAll(this);'>Select All</a><br/>";
390  }
391 
392  if ($this->width && $this->height && $this->getOptionCount() > $this->scrollAfter)
393  {
394  $width = is_numeric($this->width) ? "{$this->width}px" : $this->width;
395  $height = is_numeric($this->height) ? "{$this->height}px" : $this->height;
396  $padding = ($width == "auto") ? "padding-right: 20px; " : "";
397 
398  $resizable = ($this->resizable && !$this->dropdown) ? " resizable": "";
399  $dropdown = $this->dropdown ? " multi_select_dropdown_list" : "";
400  echo "<div id='{$this->parent->id}_{$field}_container' class='selectbox scrollbox{$resizable}{$dropdown}' style='width: {$width}; height: {$height}; $padding overflow: auto'>\n";
401  }
402  else
403  {
404  echo "<div class='selectbox'>";
405  }
406  $idx = 0;
407 
408 
409  if ($this->grouped)
410  {
411  echo "<dl>\n";
412  foreach($this->options as $groupName => $group)
413  {
414  echo "<dt>$groupName</dt>\n<dd>\n";
415  foreach($group as $value => $text)
416  {
417  $checked = (array_search($value, $values) !== FALSE) ? " checked" : "";
418 
419  if ($this->nobr) { $text = str_replace(" ", "&nbsp;", $text); }
420 
421  echo "<label for='{$this->parent->id}_{$field}_$idx'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}_$idx' name='{$field}:{$mode}[$idx]' value='$value'$checked/>$text</label>$divider";
422 
423  $idx++;
424  }
425 
426  echo "</dd>";
427  }
428  echo "</dl>";
429  }
430  else
431  {
432  if(count($this->options) > 0)
433  {
434  foreach($this->options as $value => $text)
435  {
436  $checked = (array_key_exists($value, $values)) ? " checked" : "";
437  echo "<label for='{$this->parent->id}_{$field}_$value'$layout><input type='checkbox' class='checkbox' id='{$this->parent->id}_{$field}_$value' name='{$field}:{$mode}[$value]' value='$value'$checked/>$text</label>$divider";
438 
439  $idx++;
440  }
441  }
442  }
443 
444  if ($this->width && $this->height)
445  {
446  echo "</div>\n";
447  }
448 
449  $this->_endField($field);
450  }

◆ renderSearchScript()

CheckListFieldRenderer::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 361 of file checklist_field_renderer.inc.

362  {
363  $this->renderScript($field);
364  }
renderScript($field)
FieldRenderers can override this method to provide any Javascript that their control requires for an ...

◆ setSize()

CheckListFieldRenderer::setSize (   $width,
  $height,
  $scrollAfter = 0 
)

Definition at line 118 of file checklist_field_renderer.inc.

119  {
120  $this->width = $width;
121  $this->height = $height;
122  $this->scrollAfter = $scrollAfter;
123 
124  return $this;
125  }

Member Data Documentation

◆ $addEntry

CheckListFieldRenderer::$addEntry

Definition at line 76 of file checklist_field_renderer.inc.

◆ $addEntrySize

CheckListFieldRenderer::$addEntrySize = 20

Definition at line 79 of file checklist_field_renderer.inc.

◆ $addEntryText

CheckListFieldRenderer::$addEntryText

Definition at line 77 of file checklist_field_renderer.inc.

◆ $defaultOptions

CheckListFieldRenderer::$defaultOptions = array()

Definition at line 91 of file checklist_field_renderer.inc.

◆ $dropdown

CheckListFieldRenderer::$dropdown

Definition at line 84 of file checklist_field_renderer.inc.

◆ $dropdownMaxWidth

CheckListFieldRenderer::$dropdownMaxWidth = "340px"

Definition at line 85 of file checklist_field_renderer.inc.

◆ $dropdownMessage

CheckListFieldRenderer::$dropdownMessage = "Click to Select Terms"

Definition at line 86 of file checklist_field_renderer.inc.

◆ $fixedOptions

CheckListFieldRenderer::$fixedOptions = array()

Definition at line 90 of file checklist_field_renderer.inc.

◆ $grouped

CheckListFieldRenderer::$grouped

Definition at line 78 of file checklist_field_renderer.inc.

◆ $height

CheckListFieldRenderer::$height

Definition at line 81 of file checklist_field_renderer.inc.

◆ $nobr

CheckListFieldRenderer::$nobr = false

Definition at line 83 of file checklist_field_renderer.inc.

◆ $options

CheckListFieldRenderer::$options

Definition at line 75 of file checklist_field_renderer.inc.

◆ $resizable

CheckListFieldRenderer::$resizable = false

Definition at line 82 of file checklist_field_renderer.inc.

◆ $separator

CheckListFieldRenderer::$separator = ", "

The separator between values in read only list.

Definition at line 88 of file checklist_field_renderer.inc.

◆ $showSelectAll

CheckListFieldRenderer::$showSelectAll = false

Definition at line 87 of file checklist_field_renderer.inc.

◆ $width

CheckListFieldRenderer::$width

Definition at line 80 of file checklist_field_renderer.inc.


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