[TYPO3-mvc] apply sorting to a Tx_Extbase_Persistence_ObjectStorage in a model's getter method

Föder, Adrian a.foeder at iveins.de
Mon Sep 27 15:14:19 CEST 2010


Hi Folks,

I have built a simple Extbase extension that hold persons and tradefairs and, whooom, information about which person being on which tradefair. Each tradefair has, in addition, an information about its starting and ending date (but *not* via TYPO3's default START/STOP mechanism).


When attempting to list "all available" tradefairs via the indexAction() of the TradefairController, I wrote

	$this->view->assign('tradefairs', $this->tradefairRepository->findAllActiveAndSorted());

The tradefairRepository's function is simply

	public function findAllActiveAndSorted() {
		$query = $this->createQuery();
		return $query
			->matching($query->greaterThan('end', $GLOBALS['SIM_EXEC_TIME']))
			->setOrderings(Array('start' => Tx_Extbase_Persistence_Query::ORDER_ASCENDING))
			->execute();
	}


Now, when listing all those tradefairs all is fine.



But there is another situation: a detail view of a single person, including information on what tradefair this person will be on. So my Person Model has 

	/**
	 * tradefairs
	 * @var Tx_Extbase_Persistence_ObjectStorage<Tx_Solpersons_Domain_Model_tradefair>
	 */
	protected $tradefairs;


and

	/**
	 * Getter for tradefairs
	 *
	 * @return Tx_Extbase_Persistence_ObjectStorage<Tx_Solpersons_Domain_Model_Tradefair> tradefairs
	 */
	public function getTradefairs() {
		return $this->tradefairs;
	}



$this->tradefairs is randomly sorted and I want to apply the sorting and the start/end-constraint as it is in my repository.
How should I do this best?



Thanks and best regards,


Adrian


More information about the TYPO3-project-typo3v4mvc mailing list