LettreRepository.php 6.64 KB
Newer Older
Mat's avatar
Mat committed
1
2
3
<?php

namespace PotageBundle\Repository;
4
use PotageBundle\Entity\Lettre;
Mat's avatar
Mat committed
5
6
7
8
9
10
11
12
13

/**
 * LettreRepository
 *
 * This class was generated by the Doctrine ORM. Add your own custom
 * repository methods below.
 */
class LettreRepository extends \Doctrine\ORM\EntityRepository
{
14
15
    
    /**
Mat's avatar
Mat committed
16
17
18
     * @param $pattern
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
19
     */
Mat's avatar
Mat committed
20
    public function findOneLastReference($pattern)
21
22
    {
        $qb = $this->createQueryBuilder('l')
Mat's avatar
Mat committed
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
            ->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');
42
43
        return $qb->getQuery()->getResult();
    }
Mat's avatar
Mat committed
44
45
46
47
48
49
50
51
52
53
54
55
56
57
    
    
    /**
     * @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();
    }
58

Mat's avatar
Mat committed
59
60
61
62
63
64
65
66
67
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPIUpdate($id)
    {
        $qb = $this->createQueryBuilder('l')
68
69
70
71
72
73
74
75
            ->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
76
77
78
79
80
81
82
83
84
85
86
87
88
        return $qb->getQuery()->getOneOrNullResult();
    }
    
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPIDelete($id)
    {
        $qb = $this->createQueryBuilder('l')
            ->where('l.id = :id')
89
90
91
92
93
            ->andWhere('l.status = :draft')
            ->setParameters(array(
                ':id' => $id,
                ':draft' => 'draft'
            ));
Mat's avatar
Mat committed
94
95
        return $qb->getQuery()->getOneOrNullResult();
    }
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
    
    
    /**
     * @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();
    }
112
    
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
    /**
     * @param $id
     * @return Lettre[]
     */
    public function findAllBrotherLettre($id)
    {
        $qb = $this->createQueryBuilder('l')
            ->where('l.id != :id')
            ->andWhere('l.status IN( :draft , :current )')
            ->setParameters(array(
                ':id'=> $id,
                ':draft' => 'draft',
                ':current' => 'current'
            ));
        return $qb->getQuery()->getResult();
    }
129
130
131
132
133
134
135
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForSorted($id)
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
    {
        $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)
151
152
153
    {
        $qb = $this->createQueryBuilder('l')
            ->where('l.id = :id')
154
            ->andWhere('l.status IN( :draft , :current )')
155
156
            ->setParameters(array(
                ':id'=> $id,
157
158
                ':draft' => 'draft',
                ':current' => 'current'
159
160
161
            ));
        return $qb->getQuery()->getOneOrNullResult();
    }
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NoResultException
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function countReceivers($id)
    {
        $qb = $this->createQueryBuilder('l')
            ->join('l.groupe', 'g')
            ->join('g.utilisateurs', 'u')
            ->select('count(u.id)')
            ->where('l.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getSingleScalarResult();
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NoResultException
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function countLegumes($id)
    {
        $qb = $this->createQueryBuilder('l')
            ->join('l.offre', 'o')
            ->join('o.offreLegumes', 'ol')
            ->select('count(ol.id)')
            ->where('l.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getSingleScalarResult();
    }
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
    
    /**
     * @param $id
     * @return array
     */
    public function findAllOffreLegumes($id)
    {
        $qb = $this->createQueryBuilder('l')
            ->join('l.offre', 'o')
            ->join('o.offreLegumes', 'ol')
            ->where('l.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getResult();
    }
    
211
212
213
214
215
216
217
218
    /**
     * @param $id_groupe
     * @param $status
     * @return array
     */
    public function findAllByGroupAndByStatus($id_groupe, $status)
    {
        $qb = $this->createQueryBuilder('l')
Mat's avatar
Mat committed
219
220
            ->select('l.id', 'l.subject', 'l.reference', 'l.startedAt', 'l.endedAt', 'l.status')
            ->innerJoin('l.groupe', 'g')
221
            ->innerJoin('l.offre', 'o')
222
            ->addSelect('o.id offre_id', 'o.reference offre_ref', 'o.status offre_status')
223
224
225
226
227
228
229
230
231
            ->where('g.id = :id')
            ->andWhere('l.status = :status')
            ->setParameters(array(
                ':id'=> $id_groupe,
                ':status'=> $status
            ));
        return $qb->getQuery()->getResult();
    }
    
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForSend($id)
    {
        $qb = $this->createQueryBuilder('l')
            ->where('l.id = :id')
            ->setParameters(array(
                ':id'=> $id
            ));
        return $qb->getQuery()->getOneOrNullResult();
    }
Mat's avatar
Mat committed
247
}