[DCOM-134] [GH-213] Added sort option for array collection Created: 11/Nov/12  Updated: 14/Jan/13  Resolved: 14/Jan/13

Status: Closed
Project: Doctrine Common
Component/s: None
Affects Version/s: None
Fix Version/s: None
Security Level: All

Type: Bug Priority: Major
Reporter: Benjamin Eberlei Assignee: Benjamin Eberlei
Resolution: Won't Fix Votes: 0
Labels: None


This issue is created automatically through a Github pull request on behalf of andrewtarry:

Url: https://github.com/doctrine/common/pull/213


I have added a sorter class and sortBy method for the ArrayCollection class. It gives the option to reorder the ArrayCollection after someone has gotten it from the database, e.g. from a relationship. It takes an array of method names to sort by in order to priority and it takes an optional boolean to set the order to ascending. Here is an example:

`$arraycollection->sortBy(array('getName()', 'getAddress()'));`

It will recursively loop the collection change the order. Each time it will look to see if the previous matching option is the same as for the previous element and then store those elements in list to be reordered.

Once it has looped all the elements it will reorder the elements it has matched and if there is another option to reorder by it will loop only the elements it matched last time so it is not looping the whole array each time.

Comment by Marco Pivetta [ 14/Jan/13 ]

Can't change because of BC, and the performance impact is too high

Generated at Wed Sep 02 19:52:40 EDT 2015 using JIRA 6.4.10#64025-sha1:5b8b74079161cd76a20ab66dda52747ee6701bd6.