1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Repository; |
4
|
|
|
|
5
|
|
|
use App\Entity\Video; |
6
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
7
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* @method Video|null find($id, $lockMode = null, $lockVersion = null) |
11
|
|
|
* @method Video|null findOneBy(array $criteria, array $orderBy = null) |
12
|
|
|
* @method Video[] findAll() |
13
|
|
|
* @method Video[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
14
|
|
|
*/ |
15
|
|
|
class VideoRepository extends ServiceEntityRepository |
16
|
|
|
{ |
17
|
|
|
public function __construct(RegistryInterface $registry) |
18
|
|
|
{ |
19
|
|
|
parent::__construct($registry, Video::class); |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
public function findBySearchQuery(array $searchTerms){ |
23
|
|
|
|
24
|
|
|
$queryBuilder = $this->createQueryBuilder('p'); |
25
|
|
|
|
26
|
|
|
foreach ($searchTerms as $key => $term) { |
27
|
|
|
$queryBuilder |
28
|
|
|
->orWhere('p.title LIKE :term_' . $key) |
29
|
|
|
->setParameter('term_' . $key, '%' . $term . '%'); |
30
|
|
|
|
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $queryBuilder |
34
|
|
|
->getQuery() |
35
|
|
|
->getResult(); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// /** |
39
|
|
|
// * @return Video[] Returns an array of Video objects |
40
|
|
|
// */ |
41
|
|
|
/* |
42
|
|
|
public function findByExampleField($value) |
43
|
|
|
{ |
44
|
|
|
return $this->createQueryBuilder('v') |
45
|
|
|
->andWhere('v.exampleField = :val') |
46
|
|
|
->setParameter('val', $value) |
47
|
|
|
->orderBy('v.id', 'ASC') |
48
|
|
|
->setMaxResults(10) |
49
|
|
|
->getQuery() |
50
|
|
|
->getResult() |
51
|
|
|
; |
52
|
|
|
} |
53
|
|
|
*/ |
54
|
|
|
|
55
|
|
|
/* |
56
|
|
|
public function findOneBySomeField($value): ?Video |
57
|
|
|
{ |
58
|
|
|
return $this->createQueryBuilder('v') |
59
|
|
|
->andWhere('v.exampleField = :val') |
60
|
|
|
->setParameter('val', $value) |
61
|
|
|
->getQuery() |
62
|
|
|
->getOneOrNullResult() |
63
|
|
|
; |
64
|
|
|
} |
65
|
|
|
*/ |
66
|
|
|
} |
67
|
|
|
|