[TYPO3-mvc] apply sorting to a Tx_Extbase_Persistence_ObjectStorage in a model's getter method
Franz Koch
typo3.RemoveForMessage at elements-net.de
Mon Sep 27 15:48:17 CEST 2010
Hey,
>
> /**
> * 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?
For the sorting, simply define a 'foreign_table_where' in the TCA and
add your default sorting - extbase is respecting that.
For the constraints - well, that now depends on your domain. Personally
I'd keep the 'getTradefairs' method as is for the case you need to
display all at some place and add a additional getter
'getActiveTradefairs' and return the result of
$tradefairRepository->findActiveByPerson($this,array('start' => 'ASC')
/* sorting parameter*/);
From a DDD point of view it's totally ok to ask a person for it's
active tradefairs I think.
If you don't want to add a custom method to your model, you could also
create a custom viewHelper that's filtering the active tradefairs - with
the downside that it'll create much more overhead as it'll fetch and
parse all assigned tradefairs.
hth.
--
kind regards,
Franz Koch
More information about the TYPO3-project-typo3v4mvc
mailing list