Add new option "send_to_coaches" checkbox see BT#15899

This option will send a copy of the email to all the course coaches of the
session.
pull/2958/head
Julio Montoya 6 years ago
parent 909e5101de
commit 22291a843d
  1. 40
      main/inc/lib/ScheduledAnnouncement.php
  2. 1
      main/install/configuration.dist.php
  3. 34
      main/session/scheduled_announcement.php

@ -300,6 +300,7 @@ class ScheduledAnnouncement extends Model
$messagesSent = 0; $messagesSent = 0;
$now = api_get_utc_datetime(); $now = api_get_utc_datetime();
$result = $this->get_all(); $result = $this->get_all();
$extraFieldValue = new ExtraFieldValue('scheduled_announcement');
foreach ($result as $result) { foreach ($result as $result) {
if (empty($result['sent'])) { if (empty($result['sent'])) {
@ -323,21 +324,34 @@ class ScheduledAnnouncement extends Model
} }
if ($users) { if ($users) {
$sendToCoaches = $extraFieldValue->get_values_by_handler_and_field_variable($result['id'], 'send_to_coaches');
$courseList = SessionManager::getCoursesInSession($sessionId);
$coachList = [];
if (!empty($sendToCoaches) && !empty($sendToCoaches['value']) && $sendToCoaches['value'] == 1) {
foreach ($courseList as $courseItemId) {
$result = SessionManager::getCoachesByCourseSession(
$sessionId,
$courseItemId
);
$coachList = array_merge($coachList, $result);
}
$coachList = array_unique($coachList);
}
$this->update(['id' => $result['id'], 'sent' => 1]); $this->update(['id' => $result['id'], 'sent' => 1]);
$attachments = $this->getAttachmentToString($result['id']); $attachments = $this->getAttachmentToString($result['id']);
$subject = $result['subject']; $subject = $result['subject'];
$courseInfo = [];
if (!empty($courseList)) {
$courseId = current($courseList);
$courseInfo = api_get_course_info_by_id($courseId);
}
foreach ($users as $user) { foreach ($users as $user) {
// Take original message // Take original message
$message = $result['message']; $message = $result['message'];
$userInfo = api_get_user_info($user['user_id']); $userInfo = api_get_user_info($user['user_id']);
$courseList = SessionManager::getCoursesInSession($sessionId);
$courseInfo = [];
if (!empty($courseList)) {
$courseId = current($courseList);
$courseInfo = api_get_course_info_by_id($courseId);
}
$progress = ''; $progress = '';
if (!empty($sessionInfo) && !empty($courseInfo)) { if (!empty($sessionInfo) && !empty($courseInfo)) {
@ -377,6 +391,7 @@ class ScheduledAnnouncement extends Model
$generalCoachEmail = $coachInfo['email']; $generalCoachEmail = $coachInfo['email'];
} }
} }
$tags = [ $tags = [
'((session_name))' => $sessionInfo['name'], '((session_name))' => $sessionInfo['name'],
'((session_start_date))' => $startTime, '((session_start_date))' => $startTime,
@ -399,6 +414,17 @@ class ScheduledAnnouncement extends Model
$coachId $coachId
); );
} }
$message = get_lang('YouAreReceivingACopyBecauseYouAreACourseCoach').'<br /><br />'.$message;
foreach ($coachList as $courseCoachId) {
MessageManager::send_message_simple(
$courseCoachId,
get_lang('YouAreReceivingACopyBecauseYouAreACourseCoach').'&nbsp;'.$subject,
$message,
$coachId
);
}
} }
$messagesSent++; $messagesSent++;

@ -541,6 +541,7 @@ ALTER TABLE c_survey_question ADD is_required TINYINT(1) DEFAULT 0 NOT NULL;
//CREATE TABLE scheduled_announcements (id INT AUTO_INCREMENT NOT NULL, subject VARCHAR(255) NOT NULL, message LONGTEXT NOT NULL, date DATETIME DEFAULT NULL, sent TINYINT(1) NOT NULL, session_id INT NOT NULL, c_id INT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB; //CREATE TABLE scheduled_announcements (id INT AUTO_INCREMENT NOT NULL, subject VARCHAR(255) NOT NULL, message LONGTEXT NOT NULL, date DATETIME DEFAULT NULL, sent TINYINT(1) NOT NULL, session_id INT NOT NULL, c_id INT DEFAULT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
// sudo mkdir app/upload/scheduled_announcement // sudo mkdir app/upload/scheduled_announcement
// Add "attachment" file extra field in: main/admin/extra_fields.php?type=scheduled_announcement&action=add // Add "attachment" file extra field in: main/admin/extra_fields.php?type=scheduled_announcement&action=add
// Add "send_to_coaches" checkbox field in: main/admin/extra_fields.php?type=scheduled_announcement&action=add
//$_configuration['allow_scheduled_announcements'] = false; //$_configuration['allow_scheduled_announcements'] = false;
// Add the list of emails as a bcc when sending an email. // Add the list of emails as a bcc when sending an email.
/* /*

@ -34,26 +34,11 @@ $interbreadcrumb[] = [
'name' => get_lang('SessionOverview'), 'name' => get_lang('SessionOverview'),
]; ];
if ($action == 'add') { $tool_name = get_lang('ScheduledAnnouncements');
$interbreadcrumb[] = [
'url' => api_get_self().'?session_id='.$sessionId,
'name' => get_lang('ScheduledAnnouncements'),
];
$tool_name = get_lang('Add');
} elseif ($action == 'edit') {
$tool_name = get_lang('Edit');
$interbreadcrumb[] = [
'url' => api_get_self().'?session_id='.$sessionId,
'name' => get_lang('ScheduledAnnouncements'),
];
} else {
$tool_name = get_lang('ScheduledAnnouncements');
}
switch ($action) { switch ($action) {
case 'run': case 'run':
$messagesSent = $object->sendPendingMessages(); $messagesSent = $object->sendPendingMessages();
Display::addFlash( Display::addFlash(
Display::return_message( Display::return_message(
get_lang('MessageSent').': '.$messagesSent, get_lang('MessageSent').': '.$messagesSent,
@ -61,10 +46,15 @@ switch ($action) {
) )
); );
$content = $object->getGrid($sessionId); $content = $object->getGrid($sessionId);
break; break;
case 'add': case 'add':
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&session_id='.$sessionId; $interbreadcrumb[] = [
'url' => api_get_self().'?session_id='.$sessionId,
'name' => get_lang('ScheduledAnnouncements'),
];
$tool_name = get_lang('Add');
$url = api_get_self().'?action=add&session_id='.$sessionId;
$form = $object->returnForm($url, 'add', $sessionInfo); $form = $object->returnForm($url, 'add', $sessionInfo);
// The validation or display // The validation or display
@ -125,8 +115,14 @@ switch ($action) {
} }
break; break;
case 'edit': case 'edit':
$tool_name = get_lang('Edit');
$interbreadcrumb[] = [
'url' => api_get_self().'?session_id='.$sessionId,
'name' => get_lang('ScheduledAnnouncements'),
];
// Action handling: Editing // Action handling: Editing
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.$id.'&session_id='.$sessionId; $url = api_get_self().'?action=edit&id='.$id.'&session_id='.$sessionId;
$form = $object->returnSimpleForm($id, $url, 'edit', $sessionInfo); $form = $object->returnSimpleForm($id, $url, 'edit', $sessionInfo);
if ($form->validate()) { if ($form->validate()) {
$values = $form->getSubmitValues(); $values = $form->getSubmitValues();

Loading…
Cancel
Save