|
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 |
|
|
|
|
|
|
27
|
|
|
{ |
|
28
|
|
|
if (!$forum instanceof Forum) { |
|
29
|
|
|
$forum = $this->em->getRepository('ProjetNormandie\ForumBundle\Entity\Forum') |
|
30
|
|
|
->findOneBy(['id' => $forum]); |
|
31
|
|
|
} |
|
32
|
|
|
return $forum; |
|
|
|
|
|
|
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
|
|
|
|
This check looks for private methods that have been defined, but are not used inside the class.