Passed
Push — master ( 306e3e...2f14dc )
by Julito
09:59
created

CForumThreadRepository::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/* For licensing terms, see /license.txt */
6
7
namespace Chamilo\CourseBundle\Repository;
8
9
use Chamilo\CoreBundle\Entity\Course;
10
use Chamilo\CoreBundle\Entity\ResourceInterface;
11
use Chamilo\CoreBundle\Entity\Session;
12
use Chamilo\CoreBundle\Repository\ResourceRepository;
13
use Chamilo\CourseBundle\Entity\CForumThread;
14
use Doctrine\ORM\QueryBuilder;
15
use Doctrine\Persistence\ManagerRegistry;
16
17
class CForumThreadRepository extends ResourceRepository
18
{
19
    public function __construct(ManagerRegistry $registry)
20
    {
21
        parent::__construct($registry, CForumThread::class);
22
    }
23
24
    public function findAllByCourse(
25
        Course $course,
26
        Session $session = null,
27
        ?string $title = null
28
    ): QueryBuilder {
29
        $qb = $this->getResourcesByCourse($course, $session);
30
31
        $this->addTitleQueryBuilder($title, $qb);
32
33
        return $qb;
34
    }
35
36
    public function increaseView(CForumThread $thread): void
37
    {
38
        $thread->setThreadViews($thread->getThreadViews() + 1);
39
        $em = $this->getEntityManager();
40
        $em->persist($thread);
41
        $em->flush();
42
    }
43
44
    public function delete(ResourceInterface $resource): void
45
    {
46
        /** @var CForumThread $resource */
47
        $posts = $resource->getPosts();
48
        foreach ($posts as $post) {
49
            parent::delete($post);
50
        }
51
52
        parent::delete($resource);
53
    }
54
}
55