/**
	* Returns a flat count of all categories, used for paging purposes. Must use the same visibility rules as the getTree method.
	*
	* @return int
	*/
	public function countAll()
	{
		// isc customer group management does not flag all child categories as not-accessible when you untick a parent category from a customer group access list, so we can't simply count(*) to get a count of all truly visible categories
		// use the nested set query to do a select, but discard the results and then use a FOUND_ROWS call afterwards to get the true count of all visible categories

		$set = new ISC_NESTEDSET_CATEGORIES();

		$sql = $set->generateGetTreeSql(array('categoryid'), ISC_NESTEDSET_START_ROOT, $this->getMaximumDepth(), null, null, true, $this->_getRestrictions());

		$result = $GLOBALS['ISC_CLASS_DB']->Query($sql);
		if (!$result) {
			return false;
		}

		$result = $GLOBALS['ISC_CLASS_DB']->Query("SELECT FOUND_ROWS()");
		return $GLOBALS['ISC_CLASS_DB']->FetchOne($result);
	}
Example #2
0
		/**
		 * Get an array all of the child categories of the current category.
		 *
		 * @return array a list of all of the child categories of the current category.
		 */
		public function GetChildCategories()
		{
			$categoryId = $this->GetCategoryId();
			$childCats = array();
			$set = new ISC_NESTEDSET_CATEGORIES();

			// use a manual query instead of getTree as it's less resource intensive since we only need an array of category ids, not array of result rows
			// nested set results will include the starting node, the HAVING restriction array here will drop it from the final results
			$sql = $set->generateGetTreeSql(array('categoryid'), $categoryId, ISC_NESTEDSET_DEPTH_ALL, null, null, true, array('`node`.`categoryid` != ' . $categoryId));
			$result = $GLOBALS['ISC_CLASS_DB']->Query($sql);
			while ($row = $GLOBALS['ISC_CLASS_DB']->Fetch($result)) {
				$childCats[] = $row['categoryid'];
			}

			return $childCats;
		}