1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Repository; |
4
|
|
|
|
5
|
|
|
use App\Entity\Bookmark; |
6
|
|
|
use App\Model\BookmarkInterface; |
7
|
|
|
use App\Model\LessonInterface; |
8
|
|
|
use App\Model\UserInterface; |
9
|
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository; |
10
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @method Bookmark|null find($id, $lockMode = null, $lockVersion = null) |
14
|
|
|
* @method Bookmark|null findOneBy(array $criteria, array $orderBy = null) |
15
|
|
|
* @method Bookmark[] findAll() |
16
|
|
|
* @method Bookmark[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null) |
17
|
|
|
*/ |
18
|
|
|
class BookmarkRepository extends ServiceEntityRepository implements BookmarkRepositoryInterface |
19
|
|
|
{ |
20
|
|
|
public function __construct(RegistryInterface $registry) |
21
|
|
|
{ |
22
|
|
|
parent::__construct($registry, Bookmark::class); |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
public function getAllForLessonAndUser(LessonInterface $lesson, UserInterface $user): array |
26
|
|
|
{ |
27
|
|
|
return $this->createQueryBuilder('b') |
28
|
|
|
->where('b.lesson = :lesson') |
29
|
|
|
->andWhere('b.user = :user') |
30
|
|
|
->orWhere('b.user IS NULL') |
31
|
|
|
->setParameter('lesson', $lesson) |
32
|
|
|
->setParameter('user', $user) |
33
|
|
|
->getQuery() |
34
|
|
|
->getResult() |
35
|
|
|
; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function getOneById(string $id): ?BookmarkInterface |
39
|
|
|
{ |
40
|
|
|
return $this->createQueryBuilder('b') |
41
|
|
|
->where('b.id = :id') |
42
|
|
|
->setParameter('id', $id) |
43
|
|
|
->getQuery() |
44
|
|
|
->getOneOrNullResult() |
45
|
|
|
; |
46
|
|
|
} |
47
|
|
|
} |
48
|
|
|
|