<?php

namespace Club\ShopBundle\Entity;

use Doctrine\ORM\EntityRepository;

/**
 * OrderStatusRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class OrderStatusRepository extends EntityRepository
{
  public function getDefaultStatus()
  {
    return $this->_em->createQueryBuilder()
      ->select('s')
      ->from('ClubShopBundle:OrderStatus','s')
      ->where('s.cancelled = false')
      ->andWhere('s.paid = false')
      ->andWhere('s.delivered = false')
      ->orderBy('s.priority')
      ->setMaxResults(1)
      ->getQuery()
      ->getSingleResult();
  }

  public function getDelivered()
  {
    return $this->_em->createQueryBuilder()
      ->select('s')
      ->from('ClubShopBundle:OrderStatus','s')
      ->where('s.delivered = 1')
      ->setMaxResults(1)
      ->getQuery()
      ->getSingleResult();
  }

  public function getPaid()
  {
    return $this->_em->createQueryBuilder()
      ->select('s')
      ->from('ClubShopBundle:OrderStatus','s')
      ->where('s.paid = 1')
      ->setMaxResults(1)
      ->getQuery()
      ->getSingleResult();
  }

  public function getCancelled()
  {
    return $this->_em->createQueryBuilder()
      ->select('s')
      ->from('ClubShopBundle:OrderStatus','s')
      ->where('s.cancelled = 1')
      ->setMaxResults(1)
      ->getQuery()
      ->getSingleResult();
  }

}
