/** * draws the form element * @param array data to preopulate element with * @param int repeat group counter * @return string returns field element */ function render($data, $repeatCounter = 0) { if ($this->isJoin()) { $this->hasSubElements = true; } $params =& $this->getParams(); $formModel =& $this->getForm(); $groupModel =& $this->getGroup(); $element = $this->getElement(); $aGroupRepeats[$element->group_id] = $groupModel->canRepeat(); $displayType = $params->get('database_join_display_type', 'dropdown'); $db = $this->getDb(); if (!$db) { JError::raiseWarning(JText::sprintf('PLG_ELEMENT_DBJOIN_DB_CONN_ERR', $element->name)); return ''; } if (isset($formModel->_aJoinGroupIds[$groupModel->_id])) { $joinId = $formModel->_aJoinGroupIds[$groupModel->_id]; $joinGroupId = $groupModel->_id; } else { $joinId = ''; $joinGroupId = ''; } // $$$ rob dont load in all options for autocomplete as slows loading on large data sets $tmp = $displayType == 'auto-complete' && $this->_editable ? array() : $this->_getOptions($data, $repeatCounter); /*get the default value */ $w = new FabrikWorker(); $default = (array) $this->getValue($data, $repeatCounter); foreach ($default as &$d) { $d = $w->parseMessageForPlaceHolder($d); } $thisElName = $this->getHTMLName($repeatCounter); //get the default label for the drop down (use in read only templates) $defaultLabel = ''; $defaultValue = ''; foreach ($tmp as $obj) { if ($obj->value == JArrayHelper::getValue($default, 0, '')) { $defaultValue = $obj->value; $defaultLabel = $obj->text; } } $id = $this->getHTMLId($repeatCounter); //$$$rob should be canUse() otherwise if user set to view but not use the dd was shown //if ($this->canView()) { if ($this->canUse()) { $str = ''; /*if user can access the drop down*/ switch ($displayType) { case 'dropdown': default: $str .= JHTML::_('select.genericlist', $tmp, $thisElName, 'class="fabrikinput inputbox" size="1"', 'value', 'text', $default, $id); break; case 'radio': // $$$ rob 24/05/2011 - always set one value as selected for radio button if none already set if ($defaultValue == '' && !empty($tmp)) { $defaultValue = $tmp[0]->value; } // $$$ rob 24/05/2011 - add options per row $options_per_row = intval($params->get('dbjoin_options_per_row', 0)); $str .= "<div class=\"fabrikSubElementContainer\" id=\"{$id}\">"; $str .= FabrikHelperHTML::aList($displayType, $tmp, $thisElName, 'class="fabrikinput inputbox" size="1" id="' . $id . '"', $defaultValue, 'value', 'text', $options_per_row); break; case 'checkbox': $idname = $this->getFullName(false, true, false) . "_id"; $defaults = explode(GROUPSPLITTER, JArrayHelper::getValue($data, $idname)); // $$$ rob 24/05/2011 - add options per row $options_per_row = intval($params->get('dbjoin_options_per_row', 0)); $str .= "<div class=\"fabrikSubElementContainer\" id=\"{$id}\">"; //$joinids = $default == '' ? array() : explode(GROUPSPLITTER, $default); $joinids = $default; $str .= FabrikHelperHTML::aList($displayType, $tmp, $thisElName, 'class="fabrikinput inputbox" size="1" id="' . $id . '"', $defaults, 'value', 'text', $options_per_row, $this->_editable); if ($this->isJoin() && $this->_editable) { $join =& $this->getJoin(); $joinidsName = 'join[' . $join->id . '][' . $join->table_join . '___id][]'; $tmpids = array(); foreach ($tmp as $obj) { $o = new stdClass(); $o->text = $obj->text; if (in_array($obj->value, $defaults)) { $index = array_search($obj->value, $defaults); $o->value = $joinids[$index]; } else { $o->value = 0; } $tmpids[] = $o; } $str .= "<div class=\"fabrikHide\">"; $str .= FabrikHelperHTML::aList($displayType, $tmpids, $joinidsName, 'class="fabrikinput inputbox" size="1" id="' . $id . '"', $joinids, 'value', 'text', $options_per_row, $this->_editable); $str .= "</div>"; } $defaultLabel = $str; break; case 'auto-complete': $autoCompleteName = str_replace('[]', '', $thisElName) . '-auto-complete'; $str .= "<input type=\"text\" size=\"20\" name=\"{$autoCompleteName}\" id=\"{$id}-auto-complete\" value=\"{$defaultLabel}\" class=\"fabrikinput inputbox autocomplete-trigger\"/>"; $str .= "<input type=\"hidden\" size=\"20\" name=\"{$thisElName}\" id=\"{$id}\" value=\"" . JArrayHelper::getValue($default, 0, '') . "\"/>"; break; } if ($params->get('fabrikdatabasejoin_frontend_select') && $this->_editable) { $str .= "<a href=\"#\" class=\"toggle-selectoption\" title=\"" . JText::_('COM_FABRIK_SELECT') . "\">" . FabrikHelperHTML::image('search.png', 'form', @$this->tmpl, JText::_('COM_FABRIK_SELECT')) . "</a>"; } if ($params->get('fabrikdatabasejoin_frontend_add') && $this->_editable) { $str .= "<a href=\"#\" title=\"" . JText::_('add option') . "\" class=\"toggle-addoption\">\n"; $str .= FabrikHelperHTML::image('action_add.png', 'form', @$this->tmpl, JText::_('COM_FABRIK_SELECT')) . "</a>"; } $str .= $displayType == "radio" ? "</div>" : ''; } else { /* make a hidden field instead*/ //$$$ rob no - the readonly data should be made in form view _loadTmplBottom //$str = "<input type='hidden' class='fabrikinput' name='$thisElName' id='$id' value='$default' />"; } if (!$this->_editable) { if ($defaultLabel === $params->get('database_join_noselectionlabel', JText::_('COM_FABRIK_PLEASE_SELECT'))) { $defaultLabel = ''; //no point showing 'please select' for read only } if ($params->get('databasejoin_readonly_link') == 1) { $popupformid = (int) $params->get('databasejoin_popupform'); if ($popupformid !== 0) { $db->setQuery("select id from #__{package}_lists where form_id = {$popupformid}"); $listid = $db->loadResult(); $url = 'index.php?option=com_fabrik&view=details&formid=' . $popupformid . '&listid =' . $listid . '&rowid=' . $defaultValue; $defaultLabel = '<a href="' . JRoute::_($url) . '">' . $defaultLabel . '</a>'; } } return $defaultLabel; } if ($params->get('join_desc_column') !== '') { $str .= "<div class=\"dbjoin-description\">"; for ($i = 0; $i < count($this->_optionVals); $i++) { $opt = $this->_optionVals[$i]; $display = $opt->value == $default ? '' : 'none'; $c = $i + 1; $str .= "<div style=\"display:{$display}\" class=\"notice description-" . $c . "\">" . $opt->description . "</div>"; } $str .= "</div>"; } return $str; }
/** * Generates an HTML radio list * @param array An array of objects * @param string The value of the HTML name attribute * @param string Additional HTML attributes for the <select> tag * @param mixed The key that is selected * @param string The name of the object variable for the option value * @param string The name of the object variable for the option text * @param int number of options to show per row @since 2.0.5 * @returns string HTML for the select list */ function radioList(&$arr, $tag_name, $tag_attribs, $selected = null, $key = 'value', $text = 'text', $options_per_row = 0) { return FabrikHelperHTML::aList('radio', $arr, $tag_name, $tag_attribs, $selected, $key, $text, $options_per_row); }
/** * Render checkbox list in form * * @param array $data Form data * @param int $repeatCounter Repeat group counter * @param array &$html HTML to assign output to * @param array $tmp List of value/label objects * @param array $default Default values - the lookup table's primary key values * * @since 3.0.7 * * @return void */ protected function renderCheckBoxList($data, $repeatCounter, &$html, $tmp, $default) { $id = $this->getHTMLId($repeatCounter); $name = $this->getHTMLName($repeatCounter); $params = $this->getParams(); $optsPerRow = (int) $params->get('dbjoin_options_per_row', 0); $html[] = '<div class="fabrikSubElementContainer" id="' . $id . '">'; $editable = $this->isEditable(); $attribs = 'class="fabrikinput inputbox" id="' . $id . '"'; $name = FabrikString::rtrimword($name, '[]'); $targetIds = $this->multiOptionTargetIds($data, $repeatCounter); if ($targetIds !== false) { $default = $targetIds; } $html[] = FabrikHelperHTML::aList('checkbox', $tmp, $name, $attribs, $default, 'value', 'text', $optsPerRow, $editable); if (empty($tmp)) { $tmpids = array(); $o = new stdClass(); $o->text = 'dummy'; $o->value = 'dummy'; $tmpids[] = $o; $tmp = $tmpids; $dummy = FabrikHelperHTML::aList('checkbox', $tmp, $name, $attribs, $default, 'value', 'text', 1, true); $html[] = '<div class="chxTmplNode">' . $dummy . '</div>'; } $html[] = '</div>'; }
/** * 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) { // For repetaing groups we need to unset this where each time the element is rendered unset($this->_autocomplete_where); if ($this->isJoin()) { $this->hasSubElements = true; } $params = $this->getParams(); $formModel = $this->getForm(); $groupModel = $this->getGroup(); $element = $this->getElement(); $aGroupRepeats[$element->group_id] = $groupModel->canRepeat(); $displayType = $params->get('database_join_display_type', 'dropdown'); $db = $this->getDb(); if (!$db) { JError::raiseWarning(JText::sprintf('PLG_ELEMENT_DBJOIN_DB_CONN_ERR', $element->name)); return ''; } if (isset($formModel->_aJoinGroupIds[$groupModel->getId()])) { $joinId = $formModel->_aJoinGroupIds[$groupModel->getId()]; $joinGroupId = $groupModel->getId(); } else { $joinId = ''; $joinGroupId = ''; } $default = (array) $this->getValue($data, $repeatCounter); $tmp = $this->_getOptions($data, $repeatCounter); $w = new FabrikWorker(); foreach ($default as &$d) { $d = $w->parseMessageForPlaceHolder($d); } $thisElName = $this->getHTMLName($repeatCounter); // Get the default label for the drop down (use in read only templates) $defaultLabel = ''; $defaultValue = ''; foreach ($tmp as $obj) { if ($obj->value == JArrayHelper::getValue($default, 0, '')) { $defaultValue = $obj->value; $defaultLabel = $obj->text; break; } } $id = $this->getHTMLId($repeatCounter); // $$$ rob 24/05/2011 - add options per row $options_per_row = intval($params->get('dbjoin_options_per_row', 0)); $html = array(); // $$$ hugh - still need to check $this->isEditable(), as content plugin sets it to false, // as no point rendering editable view for {fabrik view=element ...} in an article. if (!$formModel->isEditable() || !$this->isEditable()) { // $$$ rob 19/03/2012 uncommented line below - needed for checkbox rendering $obj = JArrayHelper::toObject($data); $defaultLabel = $this->renderListData($default, $obj); if ($defaultLabel === $params->get('database_join_noselectionlabel', JText::_('COM_FABRIK_PLEASE_SELECT'))) { // No point showing 'please select' for read only $defaultLabel = ''; } if ($params->get('databasejoin_readonly_link') == 1) { $popupformid = (int) $params->get('databasejoin_popupform'); if ($popupformid !== 0) { $query = $db->getQuery(true); $query->select('id')->from('#__{package}_lists')->where('form_id =' . $popupformid); $db->setQuery($query); $listid = $db->loadResult(); $url = 'index.php?option=com_fabrik&view=details&formid=' . $popupformid . '&listid =' . $listid . '&rowid=' . $defaultValue; $defaultLabel = '<a href="' . JRoute::_($url) . '">' . $defaultLabel . '</a>'; } } $html[] = $defaultLabel; } else { // $$$rob should be canUse() otherwise if user set to view but not use the dd was shown if ($this->canUse()) { $idname = $this->getFullName(false, true, false) . '_id'; $attribs = 'class="fabrikinput inputbox" size="1"'; /*if user can access the drop down*/ switch ($displayType) { case 'dropdown': default: $html[] = JHTML::_('select.genericlist', $tmp, $thisElName, $attribs, 'value', 'text', $default, $id); break; case 'radio': // $$$ rob 24/05/2011 - always set one value as selected for radio button if none already set if ($defaultValue == '' && !empty($tmp)) { $defaultValue = $tmp[0]->value; } // $$$ rob 24/05/2011 - add options per row $options_per_row = intval($params->get('dbjoin_options_per_row', 0)); $html[] = '<div class="fabrikSubElementContainer" id="' . $id . '">'; $html[] = FabrikHelperHTML::aList($displayType, $tmp, $thisElName, $attribs . ' id="' . $id . '"', $defaultValue, 'value', 'text', $options_per_row); break; case 'checkbox': $defaults = $formModel->failedValidation() ? $default : explode(GROUPSPLITTER, JArrayHelper::getValue($data, $idname)); $html[] = '<div class="fabrikSubElementContainer" id="' . $id . '">'; $rawname = $this->getFullName(false, true, false) . '_raw'; $html[] = FabrikHelperHTML::aList($displayType, $tmp, $thisElName, $attribs . ' id="' . $id . '"', $defaults, 'value', 'text', $options_per_row, $this->isEditable()); if ($this->isJoin() && $this->isEditable()) { $join = $this->getJoin(); $joinidsName = 'join[' . $join->id . '][' . $join->table_join . '___id]'; if ($groupModel->canRepeat()) { $joinidsName .= '[' . $repeatCounter . '][]'; $joinids = FArrayHelper::getNestedValue($data, 'join.' . $joinId . '.' . $rawname . '.' . $repeatCounter, 'not found'); } else { $joinidsName .= '[]'; $joinids = explode(GROUPSPLITTER, JArrayHelper::getValue($data, $rawname)); } $tmpids = array(); foreach ($tmp as $obj) { $o = new stdClass(); $o->text = $obj->text; if (in_array($obj->value, $defaults)) { $index = array_search($obj->value, $defaults); $o->value = JArrayHelper::getValue($joinids, $index); } else { $o->value = 0; } $tmpids[] = $o; } $html[] = '<div class="fabrikHide">'; $attribs = 'class="fabrikinput inputbox" size="1" id="' . $id . '"'; $html[] = FabrikHelperHTML::aList($displayType, $tmpids, $joinidsName, $attribs, $joinids, 'value', 'text', $options_per_row, $this->isEditable()); $html[] = '</div>'; } $defaultLabel = implode("\n", $html); break; case 'multilist': $defaults = $formModel->failedValidation() ? $default : explode(GROUPSPLITTER, JArrayHelper::getValue($data, $idname)); if ($this->isEditable()) { $multiSize = (int) $params->get('dbjoin_multilist_size', 6); $attribs = 'class="fabrikinput inputbox" size="' . $multiSize . '" multiple="true"'; $html[] = JHTML::_('select.genericlist', $tmp, $thisElName, $attribs, 'value', 'text', $defaults, $id); } else { $attribs = 'class="fabrikinput inputbox" size="1" id="' . $id . '"'; $html[] = FabrikHelperHTML::aList($displayType, $tmp, $thisElName, $attribs, $defaults, 'value', 'text', $options_per_row, $this->isEditable()); } $defaultLabel = implode("\n", $html); break; case 'auto-complete': // Get the LABEL from the form's data. $label = (array) $this->getValue($data, $repeatCounter, array('valueFormat' => 'label')); // $$$ rob 18/06/2012 if form submitted with errors - reshowing the auto-complete wont have access to the submitted values label if ($formModel->hasErrors()) { $label = (array) $this->getLabelForValue($label[0], $label[0], $repeatCounter); } $autoCompleteName = str_replace('[]', '', $thisElName) . '-auto-complete'; $html[] = '<input type="text" size="' . $params->get('dbjoin_autocomplete_size', '20') . '" name="' . $autoCompleteName . '" id="' . $id . '-auto-complete" value="' . JArrayHelper::getValue($label, 0) . '" class="fabrikinput inputbox autocomplete-trigger"/>'; // $$$ rob - class property required when cloning repeat groups - don't remove $html[] = '<input type="hidden" class="fabrikinput" size="20" name="' . $thisElName . '" id="' . $id . '" value="' . JArrayHelper::getValue($default, 0, '') . '"/>'; break; } if ($params->get('fabrikdatabasejoin_frontend_select') && $this->isEditable()) { JText::script('PLG_ELEMENT_DBJOIN_SELECT'); $html[] = '<a href="#" class="toggle-selectoption" title="' . JText::_('COM_FABRIK_SELECT') . '">' . FabrikHelperHTML::image('search.png', 'form', @$this->tmpl, array('alt' => JText::_('COM_FABRIK_SELECT'))) . '</a>'; } if ($params->get('fabrikdatabasejoin_frontend_add') && $this->isEditable()) { JText::script('PLG_ELEMENT_DBJOIN_ADD'); $html[] = '<a href="#" title="' . JText::_('COM_FABRIK_ADD') . '" class="toggle-addoption">'; $html[] = FabrikHelperHTML::image('action_add.png', 'form', @$this->tmpl, array('alt' => JText::_('COM_FABRIK_SELECT'))) . '</a>'; } $html[] = $displayType == 'radio' ? '</div>' : ''; } elseif ($this->canView()) { $html[] = $this->renderListData($default, JArrayHelper::toObject($data)); } } if ($params->get('join_desc_column', '') !== '') { $html[] = '<div class="dbjoin-description">'; $opts = $this->_getOptionVals($data, $repeatCounter); for ($i = 0; $i < count($opts); $i++) { $opt = $opts[$i]; $display = $opt->value == $default ? '' : 'none'; $c = $i + 1; $html[] = '<div style="display:' . $display . '" class="notice description-' . $c . '">' . $opt->description . '</div>'; } $html[] = '</div>'; } return implode("\n", $html); }
/** * draws the form element * @param array data to preopulate element with * @param int repeat group counter * @return string returns field element */ function render($data, $repeatCounter = 0) { if ($this->isJoin()) { $this->hasSubElements = true; } $params =& $this->getParams(); $formModel =& $this->getForm(); $groupModel =& $this->getGroup(); $element =& $this->getElement(); $aGroupRepeats[$element->group_id] = $groupModel->canRepeat(); $displayType = $params->get('database_join_display_type', 'dropdown'); $db =& $this->getDb(); if (!$db) { JError::raiseWarning(JText::sprintf('Could not make join to %s', $element->name)); return ''; } if (isset($formModel->_aJoinGroupIds[$groupModel->_id])) { $joinId = $formModel->_aJoinGroupIds[$groupModel->_id]; $joinGroupId = $groupModel->_id; } else { $joinId = ''; $joinGroupId = ''; } /*get the default value */ $w = new FabrikWorker(); $default = $this->getValue($data, $repeatCounter); $default = $w->parseMessageForPlaceHolder($default); // $$$ rob dont load in all options for autocomplete as slows loading on large data sets // $tmp = ($displayType == 'auto-complete' && $this->_editable) ? array() : $this->_getOptions($data, $repeatCounter); // $$$ hugh - doesn't matter if editable, otherwise it just failsd on _getROElement(). Don't load for auto-complete, period. //$tmp = $this->_getOptions($data, $repeatCounter); // $$$ rob - huh? (^^ above line + comment ^^) how can it not matter for editable? // If you have repeat auto-completes in a form then we must get the correct label/value to show in the field $tmp = $displayType == 'auto-complete' ? $this->getOneOption($default, $data, $repeatCounter) : $this->_getOptions($data, $repeatCounter); $default = $this->getValue($data, $repeatCounter); $default = $w->parseMessageForPlaceHolder($default); $thisElName = $this->getHTMLName($repeatCounter); //weird situation in http://gb.inetis.ch/ where lots of inner joins and repeating groups meant deafult was a csv list????? if (is_string($default) && strpos($default, ',')) { $default = explode(',', $default); $default = $default[$repeatCounter]; } //get the default label for the drop down (use in read only templates) $defaultLabel = ''; $defaultValue = ''; foreach ($tmp as $obj) { if ($obj->value == $default) { $defaultValue = $obj->value; $defaultLabel = $obj->text; } } $id = $this->getHTMLId($repeatCounter); //$$$rob should be canUse() otherwise if user set to view but not use the dd was shown //if ($this->canView()) { if ($this->canUse()) { $str = ''; /*if user can access the drop down*/ switch ($displayType) { case 'dropdown': default: $str .= JHTML::_('select.genericlist', $tmp, $thisElName, 'class="fabrikinput inputbox" size="1"', 'value', 'text', $default, $id); break; case 'radio': // $$$ rob 24/05/2011 - always set one value as selected for radio button if none already set if ($defaultValue == '' && !empty($tmp)) { $defaultValue = $tmp[0]->value; } // $$$ rob 24/05/2011 - add options per row $options_per_row = intval($params->get('dbjoin_options_per_row', 0)); $str .= "<div class=\"fabrikSubElementContainer\" id=\"{$id}\">"; $str .= FabrikHelperHTML::aList($displayType, $tmp, $thisElName, 'class="fabrikinput inputbox" size="1" id="' . $id . '"', $defaultValue, 'value', 'text', $options_per_row); break; case 'checkbox': $idname = $this->getFullName(false, true, false) . "_id"; $join =& $this->getJoin(); $repeatnumName = $join->table_join . "___repeatnum"; $defaults = explode(GROUPSPLITTER, JArrayHelper::getValue($data, $idname)); if ($groupModel->canRepeat() && $groupModel->isJoin()) { //$$$ rob 21/07/2011 if checkbox is in repeat group then we want to filter the defaults to only show those selected in this repeat group $fk = $groupModel->getJoinModel()->getPrimaryKey() . '_raw'; $fkeyvals = JArrayHelper::getValue($data['join'][$this->getGroup()->getGroup()->join_id], $fk); $repeatNums = JArrayHelper::getValue($data['join'][$this->getGroup()->getGroup()->join_id], $repeatnumName); $currentFkVal = $fkeyvals[$repeatCounter]; $repeatNums = explode(GROUPSPLITTER, $repeatNums[0]); $allDefaults = $defaults; $defaults = array(); foreach ($repeatNums as $rk => $v) { if ($v == $currentFkVal) { $defaults[] = $allDefaults[$rk]; } else { $defaults[] = ''; } } } // $$$ rob 24/05/2011 - add options per row $options_per_row = intval($params->get('dbjoin_options_per_row', 0)); $str .= "<div class=\"fabrikSubElementContainer\" id=\"{$id}\">"; if (is_string($default)) { $joinids = $default == '' ? array() : explode(GROUPSPLITTER, $default); } else { $joinids = $default; } $str .= FabrikHelperHTML::aList($displayType, $tmp, $thisElName, 'class="fabrikinput inputbox" size="1" id="' . $id . '"', $defaults, 'value', 'text', $options_per_row, $this->_editable); //if ($this->isJoin() && $this->_editable) { if ($this->_editable) { $joinidsName = 'join[' . $join->id . '][' . $join->table_join . '___id]'; if ($groupModel->canRepeat()) { $joinidsName .= "[{$repeatCounter}]"; } $joinidsName .= '[]'; $tmpids = array(); foreach ($tmp as $obj) { $o = new stdClass(); $o->text = $obj->text; if (in_array($obj->value, $defaults)) { $index = array_search($obj->value, $defaults); $o->value = JArrayHelper::getValue($joinids, $index); } else { $o->value = 0; } $tmpids[] = $o; } $str .= "<div class=\"fabrikHide\">"; $str .= FabrikHelperHTML::aList($displayType, $tmpids, $joinidsName, 'class="fabrikinput inputbox" size="1" id="' . $id . '"', $joinids, 'value', 'text', $options_per_row, $this->_editable); $str .= "</div>"; } $defaultLabel = $str; break; case 'auto-complete': $str .= "<input type=\"text\" size=\"" . $params->get('dbjoin_autocomplete_size', '20') . "\" name=\"{$thisElName}-auto-complete\" id=\"{$id}-auto-complete\" value=\"{$defaultLabel}\" class=\"fabrikinput inputbox autocomplete-trigger\"/>"; // $$$ rob need class for duplicate group js code to work $str .= "<input type=\"hidden\" size=\"20\" name=\"{$thisElName}\" id=\"{$id}\" class=\"fabrikinput\" value=\"{$default}\"/>"; break; } // $$$ rob 24/02/2011 removed ids from the two <a>s if ($params->get('fabrikdatabasejoin_frontend_select')) { $str .= "<a href=\"#\" class=\"toggle-selectoption\" title=\"" . JText::_('SELECT') . "\">\n\t\t\t\t<img src=\"" . COM_FABRIK_LIVESITE . "media/com_fabrik/images/search.png\" alt=\"" . JText::_('SELECT') . "\" />\n\t\t\t\t</a>"; } if ($params->get('fabrikdatabasejoin_frontend_add')) { $str .= "<a href=\"#\" title=\"" . JText::_('add option') . "\" class=\"toggle-addoption\">"; $str .= "\n<img src=\"" . COM_FABRIK_LIVESITE . "media/com_fabrik/images/action_add.png\" alt=\"" . JText::_('add option') . ">\"/>\n</a>"; } $str .= $displayType == "radio" ? "</div>" : ''; } else { /* make a hidden field instead*/ //$$$ rob no - the readonly data should be made in form view _loadTmplBottom //$str = "<input type='hidden' class='fabrikinput' name='$thisElName' id='$id' value='$default' />"; } if (!$this->_editable) { if ($defaultLabel === $params->get('database_join_noselectionlabel', JText::_('COM_FABRIK_PLEASE_SELECT'))) { $defaultLabel = ''; //no point showing 'please select' for read only } if ($params->get('databasejoin_readonly_link') == 1) { $popupformid = (int) $params->get('fabrikdatabasejoin_popupform'); if ($popupformid !== 0) { $db->setQuery("SELECT id FROM #__fabrik_tables WHERE form_id = {$popupformid}"); $tableid = $db->loadResult(); $url = 'index.php?option=com_fabrik&view=details&fabrik=' . $popupformid . '&tableid=' . $tableid . '&rowid=' . $defaultValue; $defaultLabel = '<a href="' . JRoute::_($url) . '">' . $defaultLabel . '</a>'; } } return $defaultLabel; } if ($params->get('join_desc_column') !== '') { $str .= "<div class=\"dbjoin-description\">"; for ($i = 0; $i < count($this->_optionVals); $i++) { $opt = $this->_optionVals[$i]; $display = $opt->value == $default ? '' : 'none'; $c = $i + 1; $str .= "<div style=\"display:{$display}\" class=\"notice description-" . $c . "\">" . $opt->description . "</div>"; } $str .= "</div>"; } return $str; }
/** * Render checkbox list in form * * @param array $data Form data * @param int $repeatCounter Repeat group counter * @param array &$html HTML to assign output to * @param array $tmp List of value/label objects * @param array $default Default values - the lookup table's primary key values * * @since 3.0.7 * * @return void */ protected function renderCheckBoxList($data, $repeatCounter, &$html, $tmp, $default) { $id = $this->getHTMLId($repeatCounter); $name = $this->getHTMLName($repeatCounter); $params = $this->getParams(); $html[] = '<div class="fabrikSubElementContainer" id="' . $id . '">'; $attributes = 'class="fabrikinput inputbox" id="' . $id . '"'; $name = FabrikString::rtrimword($name, '[]'); if (!$this->getFormModel()->isNewRecord()) { // If its a new record we don't want to look up defaults in the look up table as they will not exist $targetIds = $this->multiOptionTargetIds($data, $repeatCounter); if ($targetIds !== false) { $default = $targetIds; } } $this->renderReadOnlyTrimOptions($tmp, $default); $layout = $this->getLayout('form-checkboxlist'); $displayData = new stdClass(); $displayData->options = $tmp; $displayData->default = (array) $default; $displayData->optsPerRow = (int) $params->get('dbjoin_options_per_row', 1); $displayData->name = $name; $displayData->editable = $this->isEditable(); $displayData->optionLayout = $this->getLayout('form-checkbox'); $html[] = '<div class="fabrikSubElementContainer" id="' . $id . '">'; $singleLayout = 'fabrik-element-' . $this->getPluginName() . '-form-checkbox'; FabrikHelperHTML::jLayoutJs($singleLayout, $singleLayout, $displayData, array($this->layoutBasePath())); if (FabrikWorker::j3()) { $html[] = $layout->render($displayData); } else { $html[] = FabrikHelperHTML::aList('checkbox', $tmp, $name, $attributes, $default, 'value', 'text', $displayData->optsPerRow, $displayData->editable); } if (empty($tmp) && !FabrikWorker::j3()) { $tmpIds = array(); $o = new stdClass(); $o->text = 'dummy'; $o->value = 'dummy'; $tmpIds[] = $o; $tmp = $tmpIds; $dummy = FabrikHelperHTML::aList('checkbox', $tmp, $name, $attributes, $default, 'value', 'text', 1, true); $html[] = '<div class="chxTmplNode">' . $dummy . '</div>'; } $html[] = '</div>'; }