OffreRepository.php 4.06 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
85
86
87
88
89
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForSorted($id)
    {
        $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
102
103
104
105
106
107
108
109
110
111
    }
    
    /**
     * @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();
112
    }
113
114
115
116
117
118
119
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPIRead($id)
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    {
        $qb = $this->createQueryBuilder('o')
            ->select('o.id', 'o.createdAt', 'o.updatedAt', 'o.endedAt', 'o.status', 'o.reference')
            ->where('o.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
    
    /**
     * @param $id
     * @return mixed
     * @throws \Doctrine\ORM\NonUniqueResultException
     */
    public function findOneForAPISorted($id)
134
135
136
137
138
139
    {
        $qb = $this->createQueryBuilder('o')
            ->where('o.id = :id')
            ->setParameter(':id', $id);
        return $qb->getQuery()->getOneOrNullResult();
    }
Mat's avatar
hop    
Mat committed
140
141
142
143
144
145
146
147
148
149
150
151
152
153
    
    /**
     * @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();
    }
    
154
}