Completed
Push — master ( 15c28f...7822f9 )
by Paweł
13s queued 11s
created

BookmarkRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
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