Juan Diego
unread,Apr 25, 2012, 8:03:13 PM4/25/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to joomla-de...@googlegroups.com
Hi
I created a fieldlist class that reads some values from a googlefusiontable, it basically has the categories stored on the google fusion tables, and the value in the database is stored in a string. So for example, if I have selected 3 categories, everything is stored in one string like this: category1, category4, category6.
This is the code of the class
class JFormFieldFusionCategories extends JFormFieldList {
//The field class must know its own type through the variable $type.
protected $type = 'fusioncategories';
public function getOptions() {
// Initialize variables.
$options = array();
// Initialize some field attributes.
$key = $this->element['key_field'] ? (string) $this->element['key_field'] : 'value';
$value = $this->element['value_field'] ? (string) $this->element['value_field'] : (string) $this->element['name'];
$translate = $this->element['translate'] ? (string) $this->element['translate'] : false;
$query = (string) $this->element['query'];
$params=JComponentHelper::getParams('com_mapa');
//var_dump($params);
$guser = $params->get('googleuser');
$gpass = $params->get('googlepass');
$gtable = $params->get('googletablecategories');
//We connect to google
$token = ClientLogin::getAuthToken($guser, $gpass);
$ftclient = new FTClientLogin($token);
$query=$ftclient->query(SQLBuilder::select($gtable, array('Categoria')));
$categories = explode("\n",$query);
$selected=null;
foreach($categories as $key => $category)
{
if($key!=0 && $category[0]){
//$category=str_getcsv($category,",");
$options[] = JHtml::_('select.option', $category);
}
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
protected function getInput()
{
// Initialize variables.
$html = array();
$attr = '';
// Initialize some field attributes.
$attr .= $this->element['class'] ? ' class="' . (string) $this->element['class'] . '"' : '';
// To avoid user's confusion, readonly="true" should imply disabled="true".
if ((string) $this->element['readonly'] == 'true' || (string) $this->element['disabled'] == 'true')
{
$attr .= ' disabled="disabled"';
}
$attr .= $this->element['size'] ? ' size="' . (int) $this->element['size'] . '"' : '';
$attr .= $this->multiple ? ' multiple="multiple"' : '';
// Initialize JavaScript field attributes.
$attr .= $this->element['onchange'] ? ' onchange="' . (string) $this->element['onchange'] . '"' : '';
// Get the field options.
$options = (array) $this->getOptions();
// Create a read-only list (no name) with a hidden input to store the value.
if ((string) $this->element['readonly'] == 'true')
{
$html[] = JHtml::_('select.genericlist', $options, '', trim($attr), 'value', 'text', $this->value, $this->id);
$html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>';
}
// Create a regular list.
else
{
$values = str_getcsv($this->value,",");
var_dump($values);
$html[] = JHtml::_('select.genericlist', $options, $this->name, trim($attr), 'value', 'text', $values, $this->id);
}
return implode($html);
}
}
As you can see I have a var_dump on $values, and it shows me something like this array(3) {
[0]=>
string(10) "Category3"
[1]=>
string(7) " Category6"
[2]=>
string(9) " Category7"
}, but the only category that is selected is the first one of the array. Am I passing the values in wrong way?