Last active
December 14, 2015 05:49
-
-
Save dbeuchler/5038457 to your computer and use it in GitHub Desktop.
This method helps you to sort your entity request in an Symfony2 entity!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* This method helps you to sort your entity request in an Symfony2 entity! | |
* | |
* Please, share your tips commenting here: | |
* https://gist.github.com/5038457 | |
* | |
* Author: @dbeuchler | |
* | |
* (Tested and used with doctrine 2.x and Symfony 2.0.x, 2.1.x) | |
*/ | |
public function getProductsSortedByPositionInGroup() | |
{ | |
$arr = $this->product->toArray(); | |
usort($arr, function($a, $b) { | |
if ($a->getPositionInGroup() > $b->getPositionInGroup()) { | |
return 1; | |
} | |
}); | |
return $arr; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment