[TYPO3-mvc] Ordering of Tx_Extbase_Persistence_ObjectStorage Objects
Lorenz Ulrich
lorenz-typo3 at visol.ch
Tue Nov 22 12:37:36 CET 2011
Hi everyone
Is the solutions Felix describes in
<http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2010-June/005131.html>
still state of the art?
I have a similar problem with a relation of a work (a work of an artist)
that has tags attached by an MM intermediate table. I have no way of
influencing the way the tags are ordered:
$tags = $workObject->getTags();
returns the Tags sorted by the sorting field of the MM table, but I
would like to have it sorted alphabetically by the name field of the Tag
table.
Any hints are very welcome.
Thanks and best regards,
Lorenz
Am 05.05.2011 11:00, schrieb Frank Mey - NEW.EGO:
> Update:
>
> I solved the problem via a utility class as posted in this list before
> (http://lists.typo3.org/pipermail/typo3-project-typo3v4mvc/2010-June/005131.
> html).
> Only drawback is, that you have to turn the
> Tx_Extbase_Persistence_ObjectStorage into an array to
> get a usort, but that is also fine for me and Fluid.
>
> It would be nice if the splObjectStorage could be extended by sorting in the
> Extbase core or sth like that,
> Because there are many cases you want to combine the power and easiness
> fluid/extbase offers to handle
> m:n relations on an object-based level without SQL-statements and stuff :).
>
> If you have questions regarding this utility class and how it should
> interact, feel free to ask.
>
> PS: Here is the code of my utility class in Classes/Utility/ArraySort.php :
>
> class Tx_<yourExtensionName>_Utility_ArraySort {
>
> static public function sortBySeitennummer($array) {
> usort($array,
> 'Tx_<yourExtensionName>_Utility_ArraySort::usortBy<yourSortProperty>');
>
> return $array;
> }
>
> static public function usortBy<yourSortProperty>($a, $b) {
>
> return
> strnatcasecmp($a->get<your-Property-GetMethod-O-fObject-Stored-In-ObjectStor
> age>(),
> $b->get<your-Property-GetMethod-O-fObject-Stored-In-ObjectStorage>());
> }
> }
More information about the TYPO3-project-typo3v4mvc
mailing list