function buildTreeCategory($publish = 1, $is_select = 1, $access = 1) { $list = JSFactory::getTable('category', 'jshop')->getAllCategories($publish, $access, 'name'); $tree = new treeObjectList($list, array('parent' => 'category_parent_id', 'id' => 'category_id', 'is_select' => $is_select)); return $tree->getList(); }
function getTreeAllCategories($filter = array(), $order = null, $orderDir = null) { $db = JFactory::getDBO(); $user = JFactory::getUser(); $lang = JSFactory::getLang(); $query = "SELECT ordering, category_id, category_parent_id, `" . $lang->get('name') . "` as name, `" . $lang->get('short_description') . "` as short_description, `" . $lang->get('description') . "` as description, category_publish, category_image FROM `#__jshopping_categories`\n ORDER BY category_parent_id, " . $this->_allCategoriesOrder($order, $orderDir); extract(js_add_trigger(get_defined_vars(), "before")); $db->setQuery($query); $tree = new treeObjectList($db->loadObjectList(), array('parent' => 'category_parent_id', 'id' => 'category_id', 'is_select' => 0)); $categories = $tree->getList(); foreach ($categories as $key => $category) { $category->isPrev = 0; $category->isNext = 0; if (isset($categories[$key - 1]) && $category->category_parent_id == $categories[$key - 1]->category_parent_id) { $category->isPrev = 1; } if (isset($categories[$key + 1]) && $category->category_parent_id == $categories[$key + 1]->category_parent_id) { $category->isNext = 1; } } if (count($categories)) { if (isset($filter['text_search']) && !empty($filter['text_search'])) { $originalCategories = $categories; $filter['text_search'] = strtolower($filter['text_search']); foreach ($categories as $key => $category) { if (strpos(strtolower($category->name), $filter['text_search']) === false && strpos(strtolower($category->short_description), $filter['text_search']) === false && strpos(strtolower($category->description), $filter['text_search']) === false) { unset($categories[$key]); } } if (count($categories)) { foreach ($categories as $key => $category) { $categories[$key]->name = "<span class = 'jshop_green'>" . $categories[$key]->name . "</span>"; $category_parent_id = $category->category_parent_id; $i = 0; while ($category_parent_id || $i < 1000) { foreach ($originalCategories as $originalKey => $originalCategory) { if ($originalCategory->category_id == $category_parent_id) { $categories[$originalKey] = $originalCategory; $category_parent_id = $originalCategory->category_parent_id; break; } } $i++; } } ksort($categories); } } foreach ($categories as $key => $category) { $category->space = ''; for ($i = 0; $i < $category->level; $i++) { $category->space .= '<span class = "gi">|—</span>'; } } } return $categories; }