[TYPO3-mvc] How to return a filtered subset of child objects?

Thomas "Thasmo" Deinhamer thasmo at gmail.com
Sat Feb 13 12:19:22 CET 2010


That's a neat idea, but how did you thought of implementing
the whole filtering system? Should there be methods like
registerFilter, unregisterFilter etc. inside the service?

Thanks,
Thomas

Am 13.02.2010 03:00, schrieb Franz Koch:
> Hi,
>
>> So, in the end I had no idea where to implement a filter function or
>> system, for filtering out unneeded products.
>>
>> What would be the best place for this? Of course the repository would
>> be a very good place for writing custom find methods, but actually I'm
>> not sure this would help, as fluid directly calls 'getProducts' or
>> 'getDescendentProducts', which will just not call a repository method.
>
> Why don't you move all the logic into the service you already created
> and the model is returning a direct call to the service? I do this in my
> project - but don't know if it's best practice - it's at least better
> then flooding the model with logic where might not belong to.
>
> If you go the way by directly calling the service, I'd suggest to add
> additional getter methods to your model and keep the default ones, if
> you need the opportunity to get all related products. So:
> // default one
> public function getProducts() {
> return $this->products;
> }
> // magic one
> public function getAvailableProducts() {
> return $this->categoryService->getAvailableProducts($this);
> }
>
> And in your service:
>
> public function getAvailableProducts(Tx_YourExt_Domain_Model_Category
> $category) {
> if ($this->applyFilterToProducts()) {
> return $this->productRepository->findByCategoryAndCriteria($category,
> $this->getFilterCriteria());
> }
> return $category->getProducts();
> }
>
>
> Maybe something like that?
>


More information about the TYPO3-project-typo3v4mvc mailing list