Passed
Push — develop ( cd696f...5a6fe9 )
by BENARD
02:18
created

ForumService::majParent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace ProjetNormandie\ForumBundle\Service;
4
5
use Doctrine\ORM\EntityManagerInterface;
6
use Doctrine\ORM\ORMException;
7
use ProjetNormandie\ForumBundle\Entity\Forum;
8
9
class ForumService
10
{
11
    private EntityManagerInterface $em;
12
13
    /**
14
     * ForumService constructor.
15
     * @param EntityManagerInterface $em
16
     */
17
    public function __construct(EntityManagerInterface $em)
18
    {
19
        $this->em = $em;
20
    }
21
22
    /**
23
     * @param $forum
24
     * @return Forum
25
     */
26
    private function getForum($forum): Forum
0 ignored issues
show
Unused Code introduced by
The method getForum() is not used, and could be removed.

This check looks for private methods that have been defined, but are not used inside the class.

Loading history...
27
    {
28
        if (!$forum instanceof Forum) {
29
            $forum = $this->em->getRepository('ProjetNormandie\ForumBundle\Entity\Forum')
30
                ->findOneBy(['id' => $forum]);
31
        }
32
        return $forum;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $forum could return the type null which is incompatible with the type-hinted return ProjetNormandie\ForumBundle\Entity\Forum. Consider adding an additional type-check to rule them out.
Loading history...
33
    }
34
35
36
    /**
37
     * @param $forum
38
     * @deprecated
39
     */
40
    /*public function majPosition($forum)
41
    {
42
        $forum = $this->getForum($forum);
43
        if ($forum->getIsParent()) {
44
            foreach ($forum->getChildrens() as $child) {
45
                foreach ($child->getTopics() as $topic) {
46
                    $this->topicService->majPositions($topic);
47
                }
48
            }
49
        } else {
50
            foreach ($forum->getTopics() as $topic) {
51
                $this->topicService->majPositions($topic);
52
            }
53
        }
54
    }*/
55
56
57
    /**
58
     * @param Forum $forum
59
     * @param       $user
60
     */
61
    public function setNotRead(Forum $forum, $user)
62
    {
63
        $forumUser = $this->em->getRepository('ProjetNormandie\ForumBundle\Entity\ForumUser')
64
                ->findOneBy(['forum' => $forum, 'user' => $user]);
65
        $forumUser->setBoolRead(false);
66
        $this->em->flush();
67
    }
68
69
70
    /**
71
     * @param Forum $forum
72
     * @param       $user
73
     * @return int
74
     */
75
    public function countTopicNotRead(Forum $forum, $user): int
76
    {
77
        return $this->em->getRepository('ProjetNormandie\ForumBundle\Entity\TopicUser')
78
                ->countNotRead($forum,$user);
79
    }
80
81
82
    /**
83
     * @param Forum $parent
84
     * @param       $user
85
     * @return int
86
     */
87
    public function countSubForumNotRead(Forum $parent, $user): int
88
    {
89
        return $this->em->getRepository('ProjetNormandie\ForumBundle\Entity\ForumUser')
90
                ->countSubForumNotRead($parent, $user);
91
    }
92
}
93