function getSearchFilter() { $companiesTable = $this->getTable("Company"); $searchDetails = $this->getSearchParams(); $searchDetails["categoriesIds"] = null; $categoriesTotal = $companiesTable->getTotalCompaniesByCategories($searchDetails); $categoryService = new JBusinessDirectorCategoryLib(); $category = array(); if (!empty($this->categoryId) && $this->appSettings->search_type != 1) { $category = $categoryService->getCompleteCategoryById($this->categoryId); } else { $category["subCategories"] = $categoryService->getCategories(); $category["path"] = array(); //dump($category["subCategories"]); } $subcategories = ''; $enableSelection = false; $this->searchFilter["path"] = $category["path"]; if (isset($category["subCategories"]) && count($category["subCategories"]) > 0) { $subcategories = $category["subCategories"]; } else { $parentCategories = $category["path"]; // dump($parentCategories); if (count($parentCategories) > 0) { $categoryId = $parentCategories[count($parentCategories)][0]; //dump($categoryId); $parentCategory = $categoryService->getCompleteCategoryById($categoryId); $subcategories = $parentCategory["subCategories"]; $this->searchFilter["enableSelection"] = 1; $enableSelection = true; } } $categories = array(); if (isset($subcategories) && $subcategories != '') { foreach ($subcategories as $cat) { if (!is_array($cat)) { continue; } $childCategoryIds = $categoryService->getCategoryChilds($cat); if (count($childCategoryIds) == 0) { $childCategoryIds = array($cat[0]->id); } else { $mainCat = array($cat[0]->id); $childCategoryIds = array_merge($mainCat, $childCategoryIds); } $companies = array(); foreach ($categoriesTotal as $categoryTotal) { if (in_array($categoryTotal->id, $childCategoryIds)) { $cmp = explode(",", $categoryTotal->listings_ids); $companies = array_merge($companies, $cmp); $companies = array_unique($companies); } } $companiesNumber = count($companies); if ($companiesNumber > 0 || $enableSelection) { $this->searchFilter["categories"][] = array($cat, $companiesNumber); } } } return $this->searchFilter; }
function getSeachFilter() { $searchDetails = $this->getSearchParameters(); $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $starttime = $mtime; $offersTable = JTable::getInstance("Offer", "JTable"); $categoryService = new JBusinessDirectorCategoryLib(); //dump($this->categoryId); $category = array(); if (!empty($this->categoryId)) { $category = $categoryService->getCompleteCategoryById($this->categoryId); } else { $category["subCategories"] = $categoryService->getCategories(); $category["path"] = array(); //dump($category["subCategories"]); } //dump($category); $subcategories = array(); $enableSelection = false; $this->searchFilter["path"] = $category["path"]; if (isset($category["subCategories"]) && count($category["subCategories"]) > 0) { $subcategories = $category["subCategories"]; } else { $parentCategories = $category["path"]; //dump($parentCategories); if (count($parentCategories) > 0) { $categoryId = $parentCategories[count($parentCategories)][0]; //dump($categoryId); $parentCategory = $categoryService->getCompleteCategoryById($categoryId); $subcategories = $parentCategory["subCategories"]; $this->searchFilter["enableSelection"] = 1; $enableSelection = true; } } //dump($subcategories); if (isset($subcategories) && $subcategories != '') { foreach ($subcategories as $cat) { if (!is_array($cat)) { continue; } $childCategoryIds = $categoryService->getCategoryChilds($cat); if (count($childCategoryIds) == 0) { $childCategoryIds = array($cat[0]->id); } else { } $searchDetails["categoriesIds"] = $childCategoryIds; //dump($searchDetails); $companiesNumber = $offersTable->getTotalOffersByCategories($searchDetails, $this->enablePackages, $this->showPendingApproval); //dump($companiesNumber); if ($companiesNumber > 0 || $enableSelection) { $this->searchFilter["categories"][] = array($cat, $companiesNumber); } } } $mtime = microtime(); $mtime = explode(" ", $mtime); $mtime = $mtime[1] + $mtime[0]; $endtime = $mtime; $totaltime = $endtime - $starttime; //echo "This function was done in ".$totaltime." seconds"; // dump($this->searchFilter); return $this->searchFilter; }