OffreRepository.php 2.71 KB
Newer Older
1 2 3 4
<?php

namespace PotageBundle\Repository;

5 6
use PotageBundle\Entity\Offre;

7 8 9 10 11 12 13 14
/**
 * OffreRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class OffreRepository extends \Doctrine\ORM\EntityRepository
{
15 16
    
    /**
17
     * @param $pattern
18 19 20
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
21
    public function findOneLastReference($pattern)
22 23 24
    {
        $qb = $this->createQueryBuilder('o')
            ->select('o.reference')
25 26
            ->where('o.reference LIKE :pattern')
            ->setParameter(':pattern', '%' . $pattern . '%')
27 28 29 30 31 32
            ->orderBy('o.reference', 'DESC')
            ->setMaxResults(1);
        return $qb->getQuery()->getOneOrNullResult();
    }
    
    /**
33 34
     * @param $status
     * @return Offre[]
35
     */
36
    public function findAllByStatusForRead($status)
37 38
    {
        $qb = $this->createQueryBuilder('o')
39 40
            ->where('o.status = :status')
            ->setParameter(':status', $status)
41 42 43 44 45
            ->orderBy('o.status')
            ->addOrderBy('o.reference', 'DESC');
        return $qb->getQuery()->getResult();
    }
    
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForUpdate($id)
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->andWhere('o.status = :status ')
            ->setParameters(array(
                ':id'=> $id,
                ':status' => 'draft'
            ));
        return $qb->getQuery()->getOneOrNullResult();
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForDelete($id)
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->andWhere('o.status = :status ')
            ->setParameters(array(
                ':id'=> $id,
                ':status' => 'draft'
            ));
        return $qb->getQuery()->getOneOrNullResult();
78
    }
79 80 81 82 83 84 85 86 87 88 89 90 91
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPIRead($id)
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
92 93 94 95 96 97 98 99 100 101 102 103 104 105


    /**
     * @param $status
     * @return Offre[]
     */
    public function findAllByStatusForInsert()
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.status = :status')
            ->setParameter(':status', 'draft')
            ->orderBy('o.reference', 'ASC');
        return $qb->getQuery()->getResult();
    }
106
}