OffreRepository.php 4.59 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
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForUpdate($id)
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->andWhere('o.status = :status ')
56
57
58
59
60
61
62
            ->setParameters(array(
                ':id'=> $id,
                ':status' => 'draft'
            ));
        return $qb->getQuery()->getOneOrNullResult();
    }
    
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForUpdateStatus($id)
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->andWhere('o.status = :status ')
            ->setParameters(array(
                ':id'=> $id,
                ':status' => 'draft'
            ));
        return $qb->getQuery()->getOneOrNullResult();
    }
    
80
81
82
83
84
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
Mat's avatar
Mat committed
85
    public function findOneForDelete($id)
86
87
88
89
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->andWhere('o.status = :status ')
90
91
92
93
94
            ->setParameters(array(
                ':id'=> $id,
                ':status' => 'draft'
            ));
        return $qb->getQuery()->getOneOrNullResult();
95
96
97
98
99
100
101
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
Mat's avatar
Mat committed
102
    public function findOneForAPIRead($id)
103
104
    {
        $qb = $this->createQueryBuilder('o')
Mat's avatar
Mat committed
105
            ->select('o.id', 'o.createdAt', 'o.updatedAt', 'o.endedAt', 'o.status', 'o.reference')
106
            ->where('o.id = :id')
Mat's avatar
Mat committed
107
            ->setParameter(':id', $id);
108
        return $qb->getQuery()->getOneOrNullResult();
109
    }
110
    
Mat's avatar
Mat committed
111
    
112
113
114
115
116
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
Mat's avatar
Mat committed
117
    public function findOneForSorted($id)
118
119
120
121
122
123
124
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
    
Mat's avatar
Mat committed
125
    
126
127
128
129
130
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
Mat's avatar
Mat committed
131
    public function findOneForSortedWhereStatus($id)
132
133
134
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
Mat's avatar
Mat committed
135
136
137
138
139
            ->andWhere('o.status = :status ')
            ->setParameters(array(
                ':id'=> $id,
                ':status' => 'draft'
            ));
140
141
        return $qb->getQuery()->getOneOrNullResult();
    }
Mat's avatar
Mat committed
142

Mat's avatar
hop    
Mat committed
143
144
145
146
147
148
149
150
151
152
153
154
155
156
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAjaxDisplay($id)
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
    
Mat's avatar
Mat committed
157
158
159
160
161
162
163
164
165
    /**
     * @param $reference
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneByReference($reference)
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.reference = :reference')
166
167
168
169
170
            ->andWhere('o.status = :status')
            ->setParameters(array(
                ':reference' => $reference,
                ':status' => "current"
            ))
Mat's avatar
Mat committed
171
172
173
174
        ;
        return $qb->getQuery()->getOneOrNullResult();
        
    }
175
}