LettreRepository.php 3.75 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
    
    
    /**
     * @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();
    }
57

Mat's avatar
Mat committed
58
59
60
61
62
63
64
65
66
    
    /**
     * @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();
    }
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
    
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForLettreInfosAjaxDisplay($id)
    {
        $qb = $this->createQueryBuilder('l')
            //->join('l.groupe', 'g')
            //->addSelect('g')
            ->where('l.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
111
112
113
114
115
116
117
118
    
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForSorted($id)
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    {
        $qb = $this->createQueryBuilder('l')
            ->where('l.id = :id')
            ->setParameters(array(
                ':id'=> $id
            ));
        return $qb->getQuery()->getOneOrNullResult();
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForSortedWhereStatus($id)
134
135
136
    {
        $qb = $this->createQueryBuilder('l')
            ->where('l.id = :id')
137
            ->andWhere('l.status IN( :draft , :current )')
138
139
            ->setParameters(array(
                ':id'=> $id,
140
141
                ':draft' => 'draft',
                ':current' => 'current'
142
143
144
            ));
        return $qb->getQuery()->getOneOrNullResult();
    }
Mat's avatar
Mat committed
145
}