Skip to content

Instantly share code, notes, and snippets.

@dbeuchler
Last active December 14, 2015 05:49

Revisions

  1. dbeuchler revised this gist Feb 26, 2013. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions AnyEntity.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,12 @@
    /**
    * 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()
  2. dbeuchler created this gist Feb 26, 2013.
    15 changes: 15 additions & 0 deletions AnyEntity.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    /**
    * This method helps you to sort your entity request in an Symfony2 entity!
    */

    public function getProductsSortedByPositionInGroup()
    {
    $arr = $this->product->toArray();
    usort($arr, function($a, $b) {
    if ($a->getPositionInGroup() > $b->getPositionInGroup()) {
    return 1;
    }
    });

    return $arr;
    }