1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace App\Repository; |
6
|
|
|
|
7
|
|
|
use App\Entity\Course; |
8
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
9
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @method Course|null find($id, $lockMode = null, $lockVersion = null) |
13
|
|
|
* @method Course|null findOneBy(array $criteria, array $orderBy = null) |
14
|
|
|
* @method Course[] findAll() |
15
|
|
|
* @method Course[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
16
|
|
|
*/ |
17
|
|
|
class CourseRepository extends ServiceEntityRepository implements CourseRepositoryInterface |
18
|
|
|
{ |
19
|
|
|
public function __construct(RegistryInterface $registry) |
20
|
|
|
{ |
21
|
|
|
parent::__construct($registry, Course::class); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
public function getAll(): array |
25
|
|
|
{ |
26
|
|
|
return $this->createQueryBuilder('c') |
27
|
|
|
->where('c.visible = true') |
28
|
|
|
->getQuery() |
29
|
|
|
->getResult() |
30
|
|
|
; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
public function getOneById(int $courseId): ?Course |
34
|
|
|
{ |
35
|
|
|
return $this->createQueryBuilder('c') |
36
|
|
|
->where('c.id = :courseId') |
37
|
|
|
->andWhere('c.visible = true') |
38
|
|
|
->setParameter('courseId', $courseId) |
39
|
|
|
->getQuery() |
40
|
|
|
->getOneOrNullResult() |
41
|
|
|
; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function getOneByTitle(string $title): ?Course |
45
|
|
|
{ |
46
|
|
|
return $this->createQueryBuilder('c') |
47
|
|
|
->where('c.title = :title') |
48
|
|
|
->andWhere('c.visible = true') |
49
|
|
|
->setParameter('title', $title) |
50
|
|
|
->getQuery() |
51
|
|
|
->getOneOrNullResult() |
52
|
|
|
; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|