1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* For licensing terms, see /license.txt */ |
4
|
|
|
|
5
|
|
|
use Chamilo\CoreBundle\Entity\Course as CourseEntity; |
6
|
|
|
use Chamilo\CoreBundle\Entity\PortfolioComment; |
7
|
|
|
use Chamilo\CoreBundle\Entity\Session as SessionEntity; |
8
|
|
|
|
9
|
|
|
class PortfolioNotifier |
10
|
|
|
{ |
11
|
|
|
public static function notifyTeachersAndAuthor(PortfolioComment $comment) |
12
|
|
|
{ |
13
|
|
|
$item = $comment->getItem(); |
14
|
|
|
$course = $item->getCourse(); |
15
|
|
|
$session = $item->getSession(); |
16
|
|
|
|
17
|
|
|
$messageSubject = sprintf( |
18
|
|
|
get_lang('PortfolioAlertNewCommentSubject'), |
19
|
|
|
$item->getTitle(true) |
20
|
|
|
); |
21
|
|
|
$userIdListToSend = []; |
22
|
|
|
$userIdListToSend[] = $comment->getItem()->getUser()->getId(); |
23
|
|
|
|
24
|
|
|
$cidreq = api_get_cidreq_params( |
25
|
|
|
$course ? $course->getCode() : '', |
|
|
|
|
26
|
|
|
$session ? $session->getId() : 0 |
|
|
|
|
27
|
|
|
); |
28
|
|
|
$commentUrl = api_get_path(WEB_CODE_PATH).'portfolio/index.php?' |
29
|
|
|
.($course ? $cidreq.'&' : '') |
|
|
|
|
30
|
|
|
.http_build_query(['action' => 'view', 'id' => $item->getId()])."#comment-{$comment->getId()}"; |
31
|
|
|
|
32
|
|
|
if ($course) { |
|
|
|
|
33
|
|
|
$courseInfo = api_get_course_info($course->getCode()); |
34
|
|
|
|
35
|
|
|
if (1 !== (int) api_get_course_setting('email_alert_teachers_student_new_comment', $courseInfo)) { |
36
|
|
|
return; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
$courseTitle = self::getCourseTitle($course, $session); |
40
|
|
|
$userIdListToSend = array_merge( |
41
|
|
|
$userIdListToSend, |
42
|
|
|
self::getTeacherList($course, $session) |
43
|
|
|
); |
44
|
|
|
|
45
|
|
|
$messageContent = sprintf( |
46
|
|
|
get_lang('CoursePortfolioAlertNewCommentContent'), |
47
|
|
|
$item->getTitle(), |
48
|
|
|
$courseTitle, |
49
|
|
|
$commentUrl |
50
|
|
|
); |
51
|
|
|
} else { |
52
|
|
|
$messageContent = sprintf( |
53
|
|
|
get_lang('PortfolioAlertNewCommentContent'), |
54
|
|
|
$item->getTitle(), |
55
|
|
|
$commentUrl |
56
|
|
|
); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
$messageContent .= '<br><br><figure>' |
60
|
|
|
.'<blockquote>'.$comment->getExcerpt().'</blockquote>' |
61
|
|
|
.'<figcaption>'.$comment->getAuthor()->getCompleteName().'</figcaption>' |
62
|
|
|
.'</figure>'; |
63
|
|
|
|
64
|
|
|
foreach ($userIdListToSend as $userIdToSend) { |
65
|
|
|
MessageManager::send_message_simple( |
66
|
|
|
$userIdToSend, |
67
|
|
|
$messageSubject, |
68
|
|
|
$messageContent, |
69
|
|
|
0, |
70
|
|
|
false, |
71
|
|
|
false, |
72
|
|
|
[], |
73
|
|
|
false |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
private static function getCourseTitle(CourseEntity $course, ?SessionEntity $session = null): string |
79
|
|
|
{ |
80
|
|
|
if ($session) { |
81
|
|
|
return "{$course->getTitle()} ({$session->getName()})"; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
return $course->getTitle(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
private static function getTeacherList(CourseEntity $course, ?SessionEntity $session = null): array |
88
|
|
|
{ |
89
|
|
|
if ($session) { |
90
|
|
|
$teachers = SessionManager::getCoachesByCourseSession( |
91
|
|
|
$session->getId(), |
92
|
|
|
$course->getId() |
93
|
|
|
); |
94
|
|
|
|
95
|
|
|
return array_values($teachers); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
$teachers = CourseManager::get_teacher_list_from_course_code($course->getCode()); |
99
|
|
|
|
100
|
|
|
return array_keys($teachers); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|