orderBy() public méthode

Orders the query.
public orderBy ( array $order, boolean $append = true, boolean $first = false )
$order array
$append boolean
$first boolean
Exemple #1
0
 /**
  * Finds objects by a set of criteria.
  *
  * Optionally sorting and limiting details can be passed. An implementation may throw
  * an UnexpectedValueException if certain values of the sorting or limiting details are
  * not supported.
  *
  * @param array $criteria
  * @param array|null $orderBy
  * @param int|null $limit
  * @param int|null $offset
  * @return mixed The objects.
  */
 public function findBy(array $criteria, array $orderBy = array(), $limit = null, $offset = null, $fetchPlan = '*:0')
 {
     $results = array();
     foreach ($this->getOrientClasses() as $mappedClass) {
         $query = new Query(array($mappedClass));
         foreach ($criteria as $key => $value) {
             $query->andWhere("{$key} = ?", $value);
         }
         foreach ($orderBy as $key => $order) {
             $query->orderBy("{$key} {$order}");
         }
         if ($limit) {
             $query->limit($limit);
         }
         $collection = $this->getManager()->execute($query, $fetchPlan);
         if (!$collection instanceof ArrayCollection) {
             throw new Exception("Problems executing the query \"{$query->getRaw()}\". " . "The server returned {$collection} instead of ArrayCollection.");
         }
         $results = array_merge($results, $collection->toArray());
     }
     return new ArrayCollection($results);
 }