Skip to content

Commit 66aefae

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents dc21b92 + 7b524fb commit 66aefae

33 files changed

+6506
-529
lines changed

public/main/inc/lib/PortfolioController.php

Lines changed: 4536 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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+
}

public/main/inc/lib/api.lib.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@
161161
define('TOOL_ATTENDANCE', 'attendance');
162162
define('TOOL_COURSE_PROGRESS', 'course_progress');
163163
define('TOOL_PORTFOLIO', 'portfolio');
164+
define('TOOL_PORTFOLIO_COMMENT', 'portfolio_comment');
164165
define('TOOL_PLAGIARISM', 'compilatio');
165166
define('TOOL_XAPI', 'xapi');
166167

public/main/inc/lib/formvalidator/Element/SelectAjax.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,4 +143,60 @@ public function exportValue(&$submitValues, $assoc = false)
143143

144144
return $this->_prepareValue($value, $assoc);
145145
}
146+
147+
public static function templateResultForUsersInCourse(): string
148+
{
149+
return "function (state) {
150+
if (state.loading) {
151+
return state.text;
152+
}
153+
154+
var \$container = \$(
155+
'<div class=\"select2-result-user clearfix\">' +
156+
'<div class=\"select2-result-user__avatar pull-left\">' +
157+
'<img>' +
158+
'</div>' +
159+
'<div class=\"select2-result-user__info pull-left\">' +
160+
'<div class=\"select2-result-user__name\"></div>' +
161+
'<div class=\"select2-result-user__username small\"></div>' +
162+
'</div>' +
163+
'</div>'
164+
);
165+
166+
\$container.find('.select2-result-user__avatar img')
167+
.prop({ 'src': state.avatarUrl, 'alt': state.username })
168+
.css({ 'width': '40px', 'height': '40px' });
169+
\$container.find('.select2-result-user__info').css({ 'paddingLeft': '6px' });
170+
\$container.find('.select2-result-user__name').text(state.completeName);
171+
\$container.find('.select2-result-user__username').text(state.username);
172+
173+
return \$container;
174+
}";
175+
}
176+
177+
public static function templateSelectionForUsersInCourse(): string
178+
{
179+
return "function (state) {
180+
if (!state.id) {
181+
return state.text;
182+
}
183+
184+
if (!state.avatarUrl) {
185+
var avatarUrl = $(state.element).data('avatarurl');
186+
var username = $(state.element).data('username');
187+
188+
state.avatarUrl = avatarUrl;
189+
state.username = username;
190+
state.completeName = state.text;
191+
}
192+
193+
var \$container = \$('<span><img> ' + state.completeName + '</span>');
194+
195+
\$container.find('img')
196+
.prop({ 'src': state.avatarUrl, 'alt': state.username })
197+
.css({ 'width': '20px', 'height': '20px' });
198+
199+
return \$container;
200+
}";
201+
}
146202
}

public/main/inc/lib/template.lib.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,29 @@ private function getWebPaths()
166166
];
167167
}
168168

169+
public static function getLegacyP(): array
170+
{
171+
return [
172+
'web_self' => api_get_self(),
173+
'web_cid_query' => api_get_cidreq(),
174+
];
175+
}
176+
177+
public static function getLegacyC(): array
178+
{
179+
$course = api_get_course_entity();
180+
$session = api_get_session_entity();
181+
182+
if (!$course) {
183+
return [];
184+
}
185+
186+
return [
187+
'id' => $course->getId(),
188+
'session_id' => $session?->getId(),
189+
];
190+
}
191+
169192
/**
170193
* @param string $helpInput
171194
*/

0 commit comments

Comments
 (0)