/** * Draws the html form element * * @param array $data To pre-populate element with * @param int $repeatCounter Repeat group counter * * @return string Elements html */ public function render($data, $repeatCounter = 0) { $name = $this->getHTMLName($repeatCounter); $app = JFactory::getApplication(); $input = $app->input; $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); $values = $this->getSubOptionValues(); $labels = $this->getSubOptionLabels(); /** * $$$ hugh -- working on issue with radio and checkbox, where extra blank subitem gets added * if nothing selected. this fix assumes that 'value' cannot be empty string for sub-options, * and I'm not sure if we enforce that. Problem being that if we just cast directly to * an array, the array isn't "empty()", as it has a single, empty string entry. So then * the array_diff() we're about to do sees that as a diff. * * $$$ rob - Need more logic that the previous test, as we weren't applying default value/label if set and data empty */ $selected = (array) $this->getValue($data, $repeatCounter); if (FArrayHelper::emptyIsh($selected)) { $selected = array(); // Nothing previously selected, and not editable, set selected to default value, which later on is replaced with default label if (!$this->isEditable() && $params->get('sub_default_value', '') !== '') { $selected[] = $params->get('sub_default_value'); } } // $$$ rob 06/10/2011 if front end add option on, but added option not saved we should add in the selected value to the // values and labels. $diff = array_diff($selected, $values); if (!empty($diff)) { $values = array_merge($values, $diff); // Swap over the default value to the default label if (!$this->isEditable()) { foreach ($diff as &$di) { if ($di === $params->get('sub_default_value')) { $di = $params->get('sub_default_label'); } } } $labels = array_merge($labels, $diff); } if (!$this->isEditable()) { $aRoValues = array(); for ($i = 0; $i < count($values); $i++) { if (in_array($values[$i], $selected)) { $aRoValues[] = $this->getReadOnlyOutput($values[$i], $labels[$i]); } } $splitter = $params->get('icon_folder') != -1 && $params->get('icon_folder') != '' ? ' ' : ', '; if (empty($aRoValues)) { return ''; } return $this->isMultiple() && $this->renderWithHTML ? '<ul class="fabrikRepeatData"><li>' . implode('</li><li>', $aRoValues) . '</li></ul>' : implode($splitter, $aRoValues); } // Remove the default value $key = array_search($params->get('sub_default_value'), $values); if ($key) { unset($values[$key]); } $optionsPerRow = (int) $this->getParams()->get('options_per_row', 4); $elBeforeLabel = (bool) $this->getParams()->get('element_before_label', true); // Element_before_label if ($input->get('format') == 'raw') { $optionsPerRow = 1; } $classes = $this->labelClasses(); $buttonGroup = $this->buttonGroup(); $grid = FabrikHelperHTML::grid($values, $labels, $selected, $name, $this->inputType, $elBeforeLabel, $optionsPerRow, $classes, $buttonGroup); array_unshift($grid, '<div class="fabrikSubElementContainer" id="' . $id . '">'); $grid[] = '</div><!-- close subElementContainer -->'; if ($params->get('allow_frontend_addto', false)) { $onlylabel = $params->get('allowadd-onlylabel'); $grid[] = $this->getAddOptionFields($repeatCounter, $onlylabel); } return implode("\n", $grid); }
<?php defined('JPATH_BASE') or die; $d = $displayData; echo implode("\n", FabrikHelperHTML::grid($d->values, $d->labels, $d->default, $d->name, 'checkbox', false, 1, array('input' => array('fabrik_filter'))));
/** * draws the form element * @param array data * @param int repeat group counter * @return string returns element html */ public function render($data, $repeatCounter = 0) { $name = $this->getHTMLName($repeatCounter); $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); $values = $this->getSubOptionValues(); $labels = $this->getSubOptionLabels(); // $$$ hugh -- working on issue with radio and checkbox, where extra blank subitem gets added // if nothing selected. this fix assumes that 'value' cannot be empty string for sub-options, // and I'm not sure if we enforce that. Problem being that if we just cast directly to // an array, the array isn't "empty()", as it has a single, empty string entry. So then // the array_diff() we're about to do sees that as a diff. // $selected = (array)$this->getValue($data, $repeatCounter); $selected = $this->getValue($data, $repeatCounter); if (is_string($selected)) { if ($selected === '') { $selected = array(); } else { $selected = array($selected); } } //$$$ rob 06/10/2011 if front end add option on, but added option not saved we should add in the selected value to the // values and labels. $diff = array_diff($selected, $values); if (!empty($diff)) { $values = array_merge($values, $diff); $labels = array_merge($labels, $diff); } if (!$this->_editable) { $aRoValues = array(); for ($i = 0; $i < count($values); $i++) { if (in_array($values[$i], $selected)) { $aRoValues[] = $this->getReadOnlyOutput($values[$i], $labels[$i]); } } $splitter = $params->get('icon_folder') != -1 && $params->get('icon_folder') != '' ? ' ' : ', '; return implode($splitter, $aRoValues); } $optionsPerRow = (int) $this->getParams()->get('options_per_row', 0); $elBeforeLabel = (bool) $this->getParams()->get('element_before_label', true); //element_before_label if (JRequest::getVar('format') == 'raw') { $optionsPerRow = 1; } $grid = FabrikHelperHTML::grid($values, $labels, $selected, $name, $this->inputType, $elBeforeLabel, $optionsPerRow); array_unshift($grid, '<div class="fabrikSubElementContainer" id="' . $id . '">'); $grid[] = '</div>'; if ($params->get('allow_frontend_addto', false)) { $onlylabel = $params->get('allowadd-onlylabel'); $grid[] = $this->getAddOptionFields($onlylabel, $repeatCounter); } return implode("\n", $grid); }
/** * Draws the html form element * * @param array $data to preopulate element with * @param int $repeatCounter repeat group counter * * @return string elements html */ public function render($data, $repeatCounter = 0) { $name = $this->getHTMLName($repeatCounter); $id = $this->getHTMLId($repeatCounter); $params = $this->getParams(); $values = $this->getSubOptionValues(); $labels = $this->getSubOptionLabels(); /** * $$$ hugh -- working on issue with radio and checkbox, where extra blank subitem gets added * if nothing selected. this fix assumes that 'value' cannot be empty string for sub-options, * and I'm not sure if we enforce that. Problem being that if we just cast directly to * an array, the array isn't "empty()", as it has a single, empty string entry. So then * the array_diff() we're about to do sees that as a diff. */ $selected = $this->getValue($data, $repeatCounter); if (is_string($selected) || is_null($selected)) { // $$$ hugh - ooops, '0' will count as empty. // $selected = empty($selected) ? array() : array($selected); $selected = $selected === '' ? array() : array($selected); } // $$$ rob 06/10/2011 if front end add option on, but added option not saved we should add in the selected value to the // values and labels. $diff = array_diff($selected, $values); if (!empty($diff)) { $values = array_merge($values, $diff); // Swap over the default value to the default label if (!$this->isEditable()) { foreach ($diff as &$di) { if ($di === $params->get('sub_default_value')) { $di = $params->get('sub_default_label'); } } } $labels = array_merge($labels, $diff); } if (!$this->isEditable()) { $aRoValues = array(); for ($i = 0; $i < count($values); $i++) { if (in_array($values[$i], $selected)) { $aRoValues[] = $this->getReadOnlyOutput($values[$i], $labels[$i]); } } $splitter = $params->get('icon_folder') != -1 && $params->get('icon_folder') != '' ? ' ' : ', '; return $this->isMultiple() && $this->renderWithHTML ? '<ul class="fabrikRepeatData"><li>' . implode('</li><li>', $aRoValues) . '</li></ul>' : implode($splitter, $aRoValues); } // Remove the default value $key = array_search($params->get('sub_default_value'), $values); if ($key) { unset($values[$key]); } $optionsPerRow = (int) $this->getParams()->get('options_per_row', 4); $elBeforeLabel = (bool) $this->getParams()->get('element_before_label', true); // Element_before_label if (JRequest::getVar('format') == 'raw') { $optionsPerRow = 1; } $grid = FabrikHelperHTML::grid($values, $labels, $selected, $name, $this->inputType, $elBeforeLabel, $optionsPerRow); array_unshift($grid, '<div class="fabrikSubElementContainer" id="' . $id . '">'); $grid[] = '</div>'; if ($params->get('allow_frontend_addto', false)) { $onlylabel = $params->get('allowadd-onlylabel'); $grid[] = $this->getAddOptionFields($repeatCounter, $onlylabel); } return implode("\n", $grid); }
/** * Checkbox filter * * @param array $rows Filter list options * @param array $default Selected filter values * @param string $v Filter name * * @since 3.0.7 * * @return string Checkbox filter HTML */ protected function checkboxFilter($rows, $default, $v) { $values = array(); $labels = array(); foreach ($rows as $row) { $values[] = $row->value; $labels[] = $row->text; } $default = (array) $default; return implode("\n", FabrikHelperHTML::grid($values, $labels, $default, $v, 'checkbox', false, 1, array('input' => array('fabrik_filter')))); }