LettreRepository.php 2.44 KB
Newer Older
Mat's avatar
Mat committed
1
2
3
4
5
6
7
8
9
10
11
12
<?php

namespace PotageBundle\Repository;

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