/** * Отправка описания выбранной категории в формате JSON. * */ public function ajax_get_category_details() { $categoryDetails = new stdClass(); $categoryDetails->id_category = 0; $categoryDetails->sites_in_cat = 0; $categoryDetails->sites_in_cat_and_subcat = 0; try { $categoryId = $this->input->post('id_category'); if (false === $categoryId) { throw new Sppc_Exception('Category not specified'); } $categoryModel = new Sppc_CategoryModel(); $category = $categoryModel->findObjectById($categoryId); if (is_null($category)) { throw new Sppc_Exception('Specified category not found'); } $categoryDetails->id_category = $category->getId(); $categoryDetails->description = $category->getDescription(); $siteModel = new Sppc_SiteModel(); $searchFilter = new Sppc_Site_SearchFilter(); $searchFilter->setHasCpc(true)->setCategories($category); $categoryDetails->sites_in_cat = $siteModel->getCount($searchFilter); $categories = array($category); $childs = $category->getChildCategories(true); $categories = array_merge($categories, $childs); $searchFilter->setCategories($categories); $categoryDetails->sites_in_cat_and_subcat = $siteModel->getCount($searchFilter); echo json_encode(array('message' => 'OK', 'category_details' => $categoryDetails)); } catch (Exception $e) { echo json_encode(array('message' => $e->getMessage(), 'category_details' => $categoryDetails)); } }