[TYPO3-mvc] counting methods for the repository

Martin Kutschker masi-no at spam-typo3.org
Sun Jan 24 18:51:28 CET 2010


Hi!

I wanted to get an overview of the data without the need to count arrays in PHP. So I have added
these two methods to a custom repository (a child class of the standard repository).

function countAll() {
	return $this->createQuery()->count();
}

// implements countWith[Property]
public function __call($methodName, $arguments) {
	if (substr($methodName, 0, 9) === 'countWith' && strlen($methodName) > 10) {
		$propertyName = strtolower(substr(substr($methodName, 9), 0, 1) ) . substr(substr($methodName, 9), 1);
		$query = $this->createQuery();
		$result = $query->matching($query->equals($propertyName, $arguments[0]))
			->count();
		return $result;
	}
	parent::__call($methodName, $arguments);
}

Will adding them to Tx_Extbase_Persistence_Repository blow up the class too much?

Masi


More information about the TYPO3-project-typo3v4mvc mailing list