findBy(['user' => $user->getId()]); } /** * Returns an array of all the orders, starting at $offsetStart, limited to $perPage * * @param array $baseIds * @param integer $offsetStart * @param integer $perPage * @param string $sort * * @return array */ public function listOrders($baseIds, $offsetStart = 0, $perPage = 20, $sort = "created_on") { $qb = $this ->createQueryBuilder('o') ->innerJoin('o.elements', 'e'); if (!empty($baseIds)) { $qb->where($qb->expr()->in('e.baseId', $baseIds)); } if ($sort === 'user') { $qb->orderBy('o.user', 'ASC'); } elseif ($sort === 'usage') { $qb->orderBy('o.orderUsage', 'ASC'); } else { $qb->orderBy('o.createdOn', 'ASC'); } $qb ->setFirstResult((int) $offsetStart) ->setMaxResults(max(10, (int) $perPage)); return $qb->getQuery()->getResult(); } /** * Returns the total number of orders from an array of base_id * * @param array $baseIds * * @return integer */ public function countTotalOrders(array $baseIds = []) { $qb = $this ->createQueryBuilder('o'); $qb->select($qb->expr()->countDistinct('o.id')) ->innerJoin('o.elements', 'e'); if (!empty($baseIds)) { $qb->where($qb->expr()->in('e.baseId', $baseIds)); } $qb->groupBy('o.id'); try { return $qb->getQuery()->getSingleScalarResult(); } catch (NoResultException $e) { return 0; } } }