|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CourseBundle\Repository; |
|
6
|
|
|
|
|
7
|
|
|
use Chamilo\CoreBundle\Entity\Course; |
|
8
|
|
|
use Chamilo\CoreBundle\Entity\Resource\AbstractResource; |
|
9
|
|
|
use Chamilo\CoreBundle\Repository\ResourceRepository; |
|
10
|
|
|
use Chamilo\CourseBundle\Entity\CForumPost; |
|
11
|
|
|
use Chamilo\CourseBundle\Entity\CForumThread; |
|
12
|
|
|
use Chamilo\CourseBundle\Entity\CGroupInfo; |
|
13
|
|
|
use Chamilo\UserBundle\Entity\User; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class CForumPostRepository. |
|
17
|
|
|
*/ |
|
18
|
|
|
class CForumPostRepository extends ResourceRepository |
|
19
|
|
|
{ |
|
20
|
|
|
/** |
|
21
|
|
|
* @param bool $onlyVisibles |
|
22
|
|
|
* @param bool $isAllowedToEdit |
|
23
|
|
|
* @param string $orderDirection |
|
24
|
|
|
*/ |
|
25
|
|
|
public function findAllInCourseByThread( |
|
26
|
|
|
$onlyVisibles, |
|
27
|
|
|
$isAllowedToEdit, |
|
28
|
|
|
CForumThread $thread, |
|
29
|
|
|
Course $course, |
|
30
|
|
|
User $currentUser = null, |
|
31
|
|
|
CGroupInfo $group = null, |
|
32
|
|
|
$orderDirection = 'ASC' |
|
33
|
|
|
): array { |
|
34
|
|
|
$conditionVisibility = $onlyVisibles ? 'p.visible = 1' : 'p.visible != 2'; |
|
35
|
|
|
$conditionModetared = ''; |
|
36
|
|
|
$filterModerated = true; |
|
37
|
|
|
|
|
38
|
|
|
if ( |
|
39
|
|
|
(empty($group) && $isAllowedToEdit) || |
|
40
|
|
|
( |
|
41
|
|
|
($group ? $group->userIsTutor($currentUser) : false) || |
|
42
|
|
|
!$onlyVisibles |
|
43
|
|
|
) |
|
44
|
|
|
) { |
|
45
|
|
|
$filterModerated = false; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
if ($filterModerated && $onlyVisibles && $thread->getForum()->isModerated()) { |
|
49
|
|
|
$userId = $currentUser ? $currentUser->getId() : 0; |
|
50
|
|
|
|
|
51
|
|
|
$conditionModetared = 'AND p.status = 1 OR |
|
52
|
|
|
(p.status = '.CForumPost::STATUS_WAITING_MODERATION." AND p.posterId = $userId) OR |
|
53
|
|
|
(p.status = ".CForumPost::STATUS_REJECTED." AND p.poster = $userId) OR |
|
54
|
|
|
(p.status IS NULL AND p.posterId = $userId)"; |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$dql = "SELECT p |
|
58
|
|
|
FROM ChamiloCourseBundle:CForumPost p |
|
59
|
|
|
WHERE |
|
60
|
|
|
p.thread = :thread AND |
|
61
|
|
|
p.cId = :course AND |
|
62
|
|
|
$conditionVisibility |
|
63
|
|
|
$conditionModetared |
|
64
|
|
|
ORDER BY p.iid $orderDirection"; |
|
65
|
|
|
|
|
66
|
|
|
return $this |
|
67
|
|
|
->getEntityManager() |
|
68
|
|
|
->createQuery($dql) |
|
69
|
|
|
->setParameters(['thread' => $thread, 'course' => $course]) |
|
70
|
|
|
->getResult(); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
public function delete(AbstractResource $resource) |
|
74
|
|
|
{ |
|
75
|
|
|
$attachments = $resource->getAttachments(); |
|
|
|
|
|
|
76
|
|
|
if (!empty($attachments)) { |
|
77
|
|
|
foreach ($attachments as $attachment) { |
|
78
|
|
|
$this->getEntityManager()->remove($attachment); |
|
79
|
|
|
} |
|
80
|
|
|
} |
|
81
|
|
|
parent::delete($resource); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|