[TYPO3-mvc] Ordering of Tx_Extbase_Persistence_ObjectStorage Objects

Frank Mey - NEW.EGO mey_mailings at newego.de
Thu May 5 11:00:39 CEST 2011


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>());
	}
}



> -----Original Message-----
> From: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-
> project-typo3v4mvc-bounces at lists.typo3.org] On Behalf Of Frank Mey -
> NEW.EGO
> Sent: Thursday, May 05, 2011 9:54 AM
> To: 'TYPO3 v4 MVC project'
> Subject: Re: [TYPO3-mvc] Ordering of
> Tx_Extbase_Persistence_ObjectStorage Objects
> 
> Hi,
> 
> thx 4 the info, could you sort them in the getter-Method of the model that
> has the relation ? How could that be done without loosing the object-type
?
> Regards,
> Frank
> 
> > -----Original Message-----
> > From: typo3-project-typo3v4mvc-bounces at lists.typo3.org [mailto:typo3-
> > project-typo3v4mvc-bounces at lists.typo3.org] On Behalf Of Sebastian
> > Kurfürst
> > Sent: Wednesday, April 20, 2011 6:40 AM
> > To: typo3-project-typo3v4mvc at lists.typo3.org
> > Subject: Re: [TYPO3-mvc] Ordering of
> > Tx_Extbase_Persistence_ObjectStorage Objects
> >
> > Hi Falk,
> >
> > this is correct, that Object Storages are not sortable... This is
> > because
> they
> > mock \SplObjectStorage, which implement "Set" semantics.
> >
> > I regard this a design flaw in Extbase, which has been recently fixed
> > in
> > FLOW3 by the upgrade to Doctrine. We might lateron introduce some new
> > "List" (something like an Array Collection) which also supports
ordering.
> >
> > Greets,
> > Sebastian
> > _______________________________________________
> > TYPO3-project-typo3v4mvc mailing list
> > TYPO3-project-typo3v4mvc at lists.typo3.org
> > http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4m
> > vc
> 
> _______________________________________________
> 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