mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-12 04:23:19 +00:00
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace 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 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, $perPage, $sort)
|
|
{
|
|
$dql = 'SELECT o
|
|
FROM Entities\OrderElement e, Entities\Order o
|
|
WHERE e.base_id IN (' . implode(', ', $baseIds) . ')
|
|
AND e.order = o
|
|
GROUP BY o.id';
|
|
|
|
if ($sort == 'created_on') {
|
|
$dql .= ' ORDER BY o.created_on DESC';
|
|
} elseif ($sort == 'user') {
|
|
$dql .= ' ORDER BY o.user_id ASC';
|
|
}
|
|
elseif ($sort == 'o.order_usage') {
|
|
$dql .= ' ORDER BY o.usage ASC';
|
|
}
|
|
|
|
$query = $this->_em->createQuery($dql);
|
|
if (null !== $offsetStart && 0 !== $offsetStart) {
|
|
$query->setFirstResult($offsetStart);
|
|
}
|
|
if (null !== $perPage) {
|
|
$query->setMaxResults($perPage);
|
|
}
|
|
|
|
return $query->getResult();
|
|
}
|
|
|
|
/**
|
|
* Returns the total number of orders from an array of base_id
|
|
*
|
|
* @param array $baseIds
|
|
*
|
|
* @return integer
|
|
*/
|
|
public function countTotalOrders(array $baseIds = array())
|
|
{
|
|
$dql = 'SELECT distinct o.id
|
|
FROM Entities\OrderElement e, Entities\Order o
|
|
WHERE ' . (count($baseIds > 0 ) ? 'e.base_id IN (' . implode(', ', $baseIds) . ') AND ': '' ).
|
|
'e.order = o
|
|
GROUP BY o.id';
|
|
|
|
$query = $this->_em->createQuery($dql);
|
|
|
|
return count($query->getResult());
|
|
}
|
|
}
|