mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 03:23:19 +00:00
85 lines
2.1 KiB
PHP
85 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Alchemy\Phrasea\Model\Repositories;
|
|
|
|
use Doctrine\ORM\EntityRepository;
|
|
|
|
/**
|
|
* OrderRepository
|
|
*
|
|
* This class was generated by the Doctrine ORM. Add your own custom
|
|
* repository methods below.
|
|
*/
|
|
class OrderRepository extends EntityRepository
|
|
{
|
|
/**
|
|
* Returns the orders initiated by a given user.
|
|
*
|
|
* @param \User_Adapter $user
|
|
*
|
|
* @return array
|
|
*/
|
|
public function findByUser(\User_Adapter $user)
|
|
{
|
|
return $this->findBy(['usrId' => $user->get_id()]);
|
|
}
|
|
|
|
/**
|
|
* 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.userId', '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');
|
|
|
|
return $qb->getQuery()->getSingleScalarResult();
|
|
}
|
|
}
|