News:

Looking for documentation? Take a look on our wiki

Main Menu

how limit the number of categories in select at three

Started by amounita, June 24, 2013, 11:57:02 AM

Previous topic - Next topic

amounita

Hi and sorry for my english, I use a module which displays the categories list in a select and add a new select with adding a new category , I want to limit the select at three and no more
There is my code :



public static function getCategoriesTree($params){

$db = JFactory::getDBO();
$query = $db->getQuery(true);

$query->from('#__virtuemart_categories_'.VMLANG.' AS l');

$query->join('INNER', '#__virtuemart_categories AS c using (virtuemart_category_id)');
$query->join('LEFT', '#__virtuemart_category_categories AS cx ON l.virtuemart_category_id = cx.category_child_id ');

$query->select('c.virtuemart_category_id as id,  l.category_name as title, cx.category_child_id as child_id, cx.category_parent_id as parent_id');

$query->where('c.published = 1');

if ($params->get('ordering', 'ordering') == 'title') {
$query->order('l.category_name');
} else {
$query->order('cx.ordering');
}
//echo $query->dump();
$db->setQuery($query);

$results = $db->loadObjectList('id');
if (empty($results)) {
return array();
}

$categories = array();
$categories[0] = (object) array(
'id' => 0,
'parent_id' => null,
'title' => 'Top Level Category'
);
$categories += $results;
$i = 1;
foreach ($categories as $cat) {
                   
$categories[$cat->id]->ordering = $i;

if (empty($categories[$cat->id]->children)) {
$categories[$cat->id]->children = array();
}
if (isset($categories[$cat->parent_id])) {
if (empty($categories[$cat->parent_id]->children)) {
$categories[$cat->parent_id]->children = array();
}
                               $p= $categories[$cat->parent_id] ;
                             
$categories[$cat->parent_id]->children[] = $cat;
                        }
                     
                       $i--; 
                       
}

return $categories;
        }



I tried to apply  display none : <script type="text/javascript">

var v_obj = document.getElementsByName('select_item_2_8');

v_obj.setAttribute('style','display:none');
</script>

But not working, please help me , Thanks