|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Repository; |
|
4
|
|
|
|
|
5
|
|
|
use App\Entity\AdSearch; |
|
6
|
|
|
use App\Entity\Advert; |
|
7
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
|
8
|
|
|
use Doctrine\ORM\Query; |
|
9
|
|
|
use Doctrine\ORM\QueryBuilder; |
|
10
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @method Advert|null find($id, $lockMode = null, $lockVersion = null) |
|
14
|
|
|
* @method Advert|null findOneBy(array $criteria, array $orderBy = null) |
|
15
|
|
|
* @method Advert[] findAll() |
|
16
|
|
|
* @method Advert[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
|
17
|
|
|
*/ |
|
18
|
|
|
class AdvertRepository extends ServiceEntityRepository |
|
19
|
|
|
{ |
|
20
|
|
|
public function __construct(RegistryInterface $registry) |
|
21
|
|
|
{ |
|
22
|
|
|
parent::__construct($registry, Advert::class); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
// /** |
|
26
|
|
|
// * @return Advert[] Returns an array of Advert objects |
|
27
|
|
|
// */ |
|
28
|
|
|
/* |
|
29
|
|
|
public function findByExampleField($value) |
|
30
|
|
|
{ |
|
31
|
|
|
return $this->createQueryBuilder('a') |
|
32
|
|
|
->andWhere('a.exampleField = :val') |
|
33
|
|
|
->setParameter('val', $value) |
|
34
|
|
|
->orderBy('a.id', 'ASC') |
|
35
|
|
|
->setMaxResults(10) |
|
36
|
|
|
->getQuery() |
|
37
|
|
|
->getResult() |
|
38
|
|
|
; |
|
39
|
|
|
} |
|
40
|
|
|
*/ |
|
41
|
|
|
|
|
42
|
|
|
/* |
|
43
|
|
|
public function findOneBySomeField($value): ?Advert |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->createQueryBuilder('a') |
|
46
|
|
|
->andWhere('a.exampleField = :val') |
|
47
|
|
|
->setParameter('val', $value) |
|
48
|
|
|
->getQuery() |
|
49
|
|
|
->getOneOrNullResult() |
|
50
|
|
|
; |
|
51
|
|
|
} |
|
52
|
|
|
*/ |
|
53
|
|
|
|
|
54
|
|
|
public function findDepartment($department) |
|
55
|
|
|
{ |
|
56
|
|
|
$query = $this->createQueryBuilder('a') |
|
57
|
|
|
->andWhere('a.department = :d') |
|
58
|
|
|
->setParameter('d', $department) |
|
59
|
|
|
->getQuery() |
|
60
|
|
|
->getResult(); |
|
61
|
|
|
|
|
62
|
|
|
return $query; |
|
63
|
|
|
|
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string|null $term |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getWithSearchQueryBuilder(?string $term): QueryBuilder |
|
|
|
|
|
|
70
|
|
|
{ |
|
71
|
|
|
$qb = $this->createQueryBuilder('a'); |
|
72
|
|
|
|
|
73
|
|
|
return $qb |
|
74
|
|
|
->orderBy('a.date', 'DESC') |
|
75
|
|
|
; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* @param string|null $term |
|
80
|
|
|
*/ |
|
81
|
|
|
public function getByDepartmentQueryBuilder(?string $department): QueryBuilder |
|
82
|
|
|
{ |
|
83
|
|
|
$qb = $this->createQueryBuilder('a') |
|
84
|
|
|
->andWhere('a.department LIKE :department') |
|
85
|
|
|
->setParameter('department', $department) |
|
86
|
|
|
->getQuery() |
|
87
|
|
|
->getResult(); |
|
88
|
|
|
|
|
89
|
|
|
return $qb; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
|
93
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.