function no_of_programs_for_category_recursive($id) { //global $no_of_cats_with_programs; $no_of_cats_with_programs = 0; $db = JFactory::getDBO(); $query = "SELECT child_id FROM `#__guru_categoryrel` WHERE parent_id=" . $id; //$this->_promos = $this->_getList($query); $db->setQuery($query); $child_id_object = $db->loadColumn(); if (isset($child_id_object)) { foreach ($child_id_object as $child_id) { $more = guruModelguruPcateg::no_of_programs_for_category_recursive($child_id); $no_of_cats_with_programs = $no_of_cats_with_programs + $more; $db = JFactory::getDBO(); $query = "SELECT count(id) FROM `#__guru_program` WHERE published='1' AND status='1' AND catid=" . $child_id; $db->setQuery($query); $how_many = $db->loadColumn(); $how_many = $how_many["0"]; if ($how_many > 0) { $no_of_cats_with_programs = $no_of_cats_with_programs + $how_many; } } } //echo $no_of_cats_with_programs.' - '.$id.'<br />'; return $no_of_cats_with_programs; }
function categlist_home($cid = '0', $level = '0', $selected_categories = array()) { $tree = ''; $level++; $db = JFactory::getDBO(); $q = "SELECT id, child_id, ordering, published, name FROM #__guru_category,#__guru_categoryrel "; $q .= "WHERE #__guru_categoryrel.parent_id='{$cid}' "; $q .= "AND #__guru_category.id=#__guru_categoryrel.child_id "; $q .= "ORDER BY #__guru_category.ordering ASC"; $db->setQuery($q); $allresults = $db->loadObjectList(); $ask = "SELECT * FROM `#__guru_config` LIMIT 1 "; $db->setQuery($ask); $result = $db->loadObject(); $cols = $result->ctgscols; global $i; $i = 0; foreach ($allresults as $child) { $id = $child->id; $no_programs = guruModelguruPcateg::getnoprograms($id); $no_programs2 = guruModelguruPcateg::no_of_programs_for_category_recursive($id); if ($result->show_empty_categ == '1' || $result->show_empty_categ == '0' && $no_programs > 0 || $result->show_empty_categ == '0' && $no_programs2 > 0) { $link = JRoute::_("index.php?option=com_guru&view=guruPcategs&task=view&cid=" . $id); $child_id = $child->id; if ($child_id != $cid) { $tree = $tree . "<li><a href='" . $link . "'>"; } $tree = $tree . $child->name . " (" . $no_programs . ")</a>"; $no_of_sub_categories = 0; // we extract how many subcategories has a subcategory $sub_category = guruModelguruPcateg::getchildren_of_subcategory($id); $no_of_sub_categories = count($sub_category); if ($no_of_sub_categories > 0) { $tree = $tree . '<ul>' . $this->categlist_home($child_id, $level, $selected_categories) . '</ul>'; } } $i++; } return $tree; }