[TYPO3-mvc] sorting the values of a for-loop

Christian Essl essl at incert.at
Thu Oct 6 10:19:02 CEST 2011


That is my opinion too. If I would have to use a custom query and seperately assign the object tot he view, instead of accessing it via it's aggregate root, it can't be the ideal way.

I found an interesting fed-ViewHelper:
http://fedext.net/viewhelpers/data/data-sorter/

Logically it would feel more right, to directly sort the values inside a loop-ViewHelper, but the dataSorter should be a quick and easy workaround.

Regards,
Christian

-----Ursprüngliche Nachricht-----
Von: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-project-typo3v4mvc-bounces at lists.typo3.org] Im Auftrag von Christian Kartnig
Gesendet: Donnerstag, 06. Oktober 2011 09:41
An: typo3-project-typo3v4mvc at lists.typo3.org
Betreff: Re: [TYPO3-mvc] sorting the values of a for-loop

Hi!

Another possibility is to set the sorting via TCA. But you are restricted to one column and 'ASC' is hardcoded for the sorting.
(Tim Schoch posted a hack to overcome this in this list, see: "Sorting of StorageObject's with extended foreign_sortby field")

I also used custom repository methods, but it's not satisfying either, because if I have to write a custom method everytime I need sorting, all the getters don't quite make sense anymore...

It would be so nice if Extbase respected the defaultOrderings also in getters...

Best regards,
Christian


Am 06.10.2011 00:50, schrieb Thomas Allmer:
> hey Christian,
>
> I now use in most my repositories something like this
> /**
> * Finds all items of the repository ordered by the $orderings.
> *
> * @param array $orderings
> * @return array Matched labors
> */
> public function findAllOrdered($orderings = array()) { $result = 
> $this->createQuery()->setOrderings($orderings)->execute();
> return $result;
> }
>
> and you can use it like this...
>
> $this->myRepository->findAllOrdered(array('start' => 
> Tx_Extbase_Persistence_QueryInterface::ORDER_ASCENDING);
>
> cheers
>
> On 05.10.2011 10:37, Christian Essl wrote:
>> Hi,
>>
>> I have a "kurstermin"-Model, which contains a start-date and an 
>> end-date, and the category it belongs to. Now I first sort the 
>> kurstermine by their category and then print out the dates with a
>> for-loop:
>>
>> <f:groupedFor each="{kurs.kursTermin}" as="kurstermineByCategory"
>> groupBy=" category " groupKey=" category"> <td> <f:for 
>> each="{kurstermineByCategory}" as="kurstermin" key="von"> 
>> <f:format.date format="d.m.y">{kurstermin.start}</f:format.date>
>> -<f:format.date format="d.m.y">{kurstermin.end}</f:format.date><br /> 
>> </f:for> </td> </f:groupedFor>
>>
>> But by default the values are sorted by the uid. To sort the values 
>> by the start-date, I inserted the following inside my Repository:
>>
>> class Tx_Extensionname_Domain_Repository_KursterminRepository extends 
>> Tx_Extbase_Persistence_Repository {
>>
>> protected $defaultOrderings = array('start' => 
>> Tx_Extbase_Persistence_Query::ORDER_ASCENDING);
>> }
>>
>> ...but it doesn't seem to change anything. There are not custom 
>> methods in the Repository which could override the settings. So what 
>> is the best way to sort the output of a for-loop?
>>
>> Regards,
>> Christian
>
>

_______________________________________________
TYPO3-project-typo3v4mvc mailing list
TYPO3-project-typo3v4mvc at lists.typo3.org
http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc


More information about the TYPO3-project-typo3v4mvc mailing list