mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 07:23:13 +00:00
Added forgotten files, fixed codestyle a little bit
This commit is contained in:
73
lib/Doctrine/Repositories/OrderRepository.php
Normal file
73
lib/Doctrine/Repositories/OrderRepository.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user