Portfolio: Add email_alert_teachers_student_new_comment to send notifications to teachers and the author when commenting - refs BT#18201

pull/4368/head
Angel Fernando Quiroz Campos 3 years ago
parent 4e97921354
commit 95923072a8
  1. 17
      main/course_info/infocours.php
  2. 2
      main/inc/lib/PortfolioController.php
  3. 102
      main/inc/lib/PortfolioNotifier.php
  4. 1
      main/inc/lib/add_course.lib.inc.php
  5. 1
      main/inc/lib/course.lib.php

@ -517,6 +517,23 @@ if ($allowPortfolioTool) {
2
);
$form->addGroup($group, '', [get_lang("EmailToTeachersWhenNewPost")]);
$group = [];
$group[] = $form->createElement(
'radio',
'email_alert_teachers_student_new_comment',
get_lang('EmailToTeachersAndStudentWhenNewComment'),
get_lang('Yes'),
1
);
$group[] = $form->createElement(
'radio',
'email_alert_teachers_student_new_comment',
null,
get_lang('No'),
2
);
$form->addGroup($group, '', [get_lang("EmailToTeachersAndStudentWhenNewComment")]);
}
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');

@ -3100,6 +3100,8 @@ class PortfolioController
$hook->setEventData(['comment' => $comment]);
$hook->notifyItemCommented();
PortfolioNotifier::notifyTeachersAndAuthor($comment);
Display::addFlash(
Display::return_message(get_lang('CommentAdded'), 'success')
);

@ -0,0 +1,102 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Course as CourseEntity;
use Chamilo\CoreBundle\Entity\PortfolioComment;
use Chamilo\CoreBundle\Entity\Session as SessionEntity;
class PortfolioNotifier
{
public static function notifyTeachersAndAuthor(PortfolioComment $comment)
{
$item = $comment->getItem();
$course = $item->getCourse();
$session = $item->getSession();
$messageSubject = sprintf(
get_lang('PortfolioAlertNewCommentSubject'),
$item->getTitle(true)
);
$userIdListToSend = [];
$userIdListToSend[] = $comment->getItem()->getUser()->getId();
$cidreq = api_get_cidreq_params(
$course ? $course->getCode() : '',
$session ? $session->getId() : 0
);
$commentUrl = api_get_path(WEB_CODE_PATH).'portfolio/index.php?'
.($course ? $cidreq.'&' : '')
.http_build_query(['action' => 'view', 'id' => $item->getId()])."#comment-{$comment->getId()}";
if ($course) {
$courseInfo = api_get_course_info($course->getCode());
if (1 !== (int) api_get_course_setting('email_alert_teachers_student_new_comment', $courseInfo)) {
return;
}
$courseTitle = self::getCourseTitle($course, $session);
$userIdListToSend = array_merge(
$userIdListToSend,
self::getTeacherList($course, $session)
);
$messageContent = sprintf(
get_lang('CoursePortfolioAlertNewCommentContent'),
$item->getTitle(),
$courseTitle,
$commentUrl
);
} else {
$messageContent = sprintf(
get_lang('PortfolioAlertNewCommentContent'),
$item->getTitle(),
$commentUrl
);
}
$messageContent .= '<br><br><figure>'
.'<blockquote>'.$comment->getExcerpt().'</blockquote>'
.'<figcaption>'.$comment->getAuthor()->getCompleteName().'</figcaption>'
.'</figure>';
foreach ($userIdListToSend as $userIdToSend) {
MessageManager::send_message_simple(
$userIdToSend,
$messageSubject,
$messageContent,
0,
false,
false,
[],
false
);
}
}
private static function getCourseTitle(CourseEntity $course, ?SessionEntity $session = null): string
{
if ($session) {
return "{$course->getTitle()} ({$session->getName()})";
}
return $course->getTitle();
}
private static function getTeacherList(CourseEntity $course, ?SessionEntity $session = null): array
{
if ($session) {
$teachers = SessionManager::getCoachesByCourseSession(
$session->getId(),
$course->getId()
);
return array_values($teachers);
}
$teachers = CourseManager::get_teacher_list_from_course_code($course->getCode());
return array_keys($teachers);
}
}

@ -663,6 +663,7 @@ class AddCourse
'show_course_in_user_language' => ['default' => 2, 'category' => null],
'email_to_teachers_on_new_work_feedback' => ['default' => 1, 'category' => null],
'email_alert_teachers_new_post' => ['default' => 1, 'category' => 'portfolio'],
'email_alert_teachers_student_new_comment' => ['default' => 1, 'category' => 'portfolio'],
'agenda_share_events_in_sessions' => ['default' => 0, 'category' => 'agenda'],
];

@ -5840,6 +5840,7 @@ class CourseManager
if (api_get_configuration_value('allow_portfolio_tool')) {
$courseSettings[] = 'email_alert_teachers_new_post';
$courseSettings[] = 'email_alert_teachers_student_new_comment';
$courseSettings[] = 'qualify_portfolio_item';
$courseSettings[] = 'qualify_portfolio_comment';
$courseSettings[] = 'portfolio_max_score';

Loading…
Cancel
Save