/** * Render (NOTE when rendering admin settings I *think* the repeat group is set with $this->counter_override) * * @param string $name The name of the control, or the default text area if a setup file is not found * @param string $group Group * @param bool $write Write out or return * @param int $repeatSingleVal If set and group is repeat only return int row from rendered params * * @return string HTML * * @since 1.5 */ public function render($name = 'params', $group = '_default', $write = true, $repeatSingleVal = null) { $return = ''; $this->_group = $group; // $$$rob experimental again /** * Problem - when rendering plugin params - e.g. calendar vis - params like the table drop down * are repeated n times. I think the best way to deal with this is to get the data recorded for * the viz and update this objects _xml array duplicate the relevant JSimpleXMLElement Objects * for the required number of table drop downs */ $repeat = false; $repeatControls = true; $repeatMin = 0; if (is_array($this->_xml)) { if (array_key_exists($group, $this->_xml)) { $repeat = $this->_xml[$group]->attributes('repeat'); $repeatMin = (int) $this->_xml[$group]->attributes('repeatmin'); $repeatControls = $this->_xml[$group]->attributes('repeatcontrols'); } } if ($repeat) { // Get the name of the first element in the group $children = $this->_xml[$group]->children(); if (empty($children)) { $firstElName = ''; $allParamData = ''; $value = ''; } else { $firstElName = str_replace("[]", "", $children[0]->attributes('name')); $allParamData = $this->_registry['_default']['data']; $value = $this->get($firstElName, array(), $group, 'array'); } $c = 0; // Limit the number of groups of repeated params written out if (!is_null($repeatSingleVal) && is_int($repeatSingleVal)) { $total = $repeatSingleVal + 1; $start = $repeatSingleVal; } else { $total = count($value); $start = 0; } $return .= '<div id="container' . $this->_identifier . '">'; // Add in the 'add' button to duplicate the group // Only show for first added group if ($repeatControls && $repeatSingleVal == 0) { $return .= "<a href='#' class='addButton'>" . FText::_('COM_FABRIK_ADD') . "</a>"; } for ($x = $start; $x < $total; $x++) { // Call render for the number of time the group is repeated $return .= '<div class="repeatGroup" id="' . $this->_identifier . 'group-' . $x . '">'; $params = $this->getParams($name, $group, 'array', $x); $html = array(); $html[] = '<table width="100%" class="paramlist admintable" cellspacing="1">'; if ($description = $this->_xml[$group]->attributes('description')) { // Add the params description to the display $desc = FText::_($description); $html[] = '<tr><td class="paramlist_description" colspan="2">' . $desc . '</td></tr>'; } foreach ($params as $param) { $html[] = '<tr>'; if ($param[0]) { $html[] = '<td width="40%" class="paramlist_key"><span class="editlinktip">' . $param[0] . '</span></td>'; $html[] = '<td class="paramlist_value">' . $param[1] . '</td>'; } else { $html[] = '<td class="paramlist_value" colspan="2">' . $param[1] . '</td>'; } $html[] = '</tr>'; } if (count($params) < 1) { $html[] = "<tr><td colspan=\"2\"><i>" . FText::_('COM_FABRIK_THERE_ARE_NO_PARAMETERS_FOR_THIS_ITEM') . "</i></td></tr>"; } $html[] = '</table>'; if ($repeatControls) { $html[] = "<a href='#' class=\"removeButton delete\">" . FText::_('COM_FABRIK_DELETE') . "</a>"; } $return .= implode("\n", $html); $c++; $return .= "</div>"; } $return .= "</div>"; } else { $return .= parent::render($name, $group); } if ($repeat && $repeatControls && ($repeatSingleVal == null || $repeatSingleVal == 0)) { FabrikHelperHTML::script('components/com_fabrik/libs/params.js'); // Watch add and remove buttons $document = JFactory::getDocument(); $script = "window.addEvent('fabrik.loaded', function() {\n\t\t\t new RepeatParams('container{$this->_identifier}', {repeatMin:{$repeatMin}});\n\t});"; FabrikHelperHTML::addScriptDeclaration($script); } if ($write) { echo $return; } else { return $return; } }