/**
* @param TSqlCriteria $criteria
* @return integer number of records.
*/
public function count($criteria)
{
if ($criteria === null) {
return (int) $this->getBuilder()->createCountCommand()->queryScalar();
}
$where = $criteria->getCondition();
$parameters = $criteria->getParameters()->toArray();
$ordering = $criteria->getOrdersBy();
$limit = $criteria->getLimit();
$offset = $criteria->getOffset();
$command = $this->getBuilder()->createCountCommand($where, $parameters, $ordering, $limit, $offset);
$this->onCreateCommand($command, $criteria);
return $this->onExecuteCommand($command, (int) $command->queryScalar());
}