Skip to content

Commit 6d347e7

Browse files
committed
Add setting 'allow_notification_setting_per_exercise' see BT#13019
Allows to setup "email notifications" per exercise as a complement of the course setting. If there's not an exercise notification setting, then it will take the course setting. Requires a DB change.
1 parent ba0bf64 commit 6d347e7

File tree

4 files changed

+130
-19
lines changed

4 files changed

+130
-19
lines changed

main/course_info/infocours.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -327,18 +327,21 @@ function is_settings_editable()
327327
$group[] = $form->createElement('radio', 'email_alert_on_new_doc_dropbox', null, get_lang('DropboxEmailAlertDeactivate'), 0);
328328
$form->addGroup($group, '', array(get_lang("DropboxEmailAlert")));
329329

330-
$group = array();
331-
332-
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentStartQuiz'), ['value' => 2]);
333-
// Default
334-
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuiz'), ['value' => 1]);
335330

336-
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOpenQuestion'), ['value' => 3]);
337-
$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOralQuestion'), ['value' => 4]);
338-
//$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('QuizEmailAlertDeactivate'), ['value' => 0]);
331+
// Exercises notifications
332+
$emailAlerts = ExerciseLib::getNotificationSettings();
333+
$group = [];
334+
foreach ($emailAlerts as $itemId => $label) {
335+
$group[] = $form->createElement(
336+
'checkbox',
337+
'email_alert_manager_on_new_quiz[]',
338+
null,
339+
$label,
340+
['value' => $itemId]
341+
);
342+
}
339343

340-
//$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('QuizEmailSendToTeacherWhenStudentEndQuiz'), ['value' => 3]);
341-
$form->addGroup($group, '', array(get_lang("Exercises")));
344+
$form->addGroup($group, '', array(get_lang('Exercises')));
342345
$form->addButtonSave(get_lang('SaveSettings'), 'submit_save');
343346

344347
$form->addHtml('

main/exercise/exercise.class.php

Lines changed: 95 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class Exercise
7777
public $questionFeedbackEnabled = false;
7878
public $questionTypeWithFeedback;
7979
public $showPreviousButton;
80+
public $notifications;
8081

8182
/**
8283
* Constructor of the class
@@ -178,6 +179,11 @@ public function read($id, $parseQuestionList = true)
178179
$this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null;
179180
$this->hideQuestionTitle = isset($object->hide_question_title) ? (int) $object->hide_question_title : 0;
180181

182+
$this->notifications = [];
183+
if (!empty($object->notifications)) {
184+
$this->notifications = explode(',', $object->notifications);
185+
}
186+
181187
if (isset($object->show_previous_button)) {
182188
$this->showPreviousButton = $object->show_previous_button == 1 ? true : false;
183189
}
@@ -1619,6 +1625,13 @@ public function save($type_e = '')
16191625
if ($allow === true) {
16201626
$paramsExtra['show_previous_button'] = $this->showPreviousButton();
16211627
}
1628+
1629+
$allow = api_get_configuration_value('allow_notification_setting_per_exercise');
1630+
if ($allow === true) {
1631+
$notifications = $this->getNotifications();
1632+
$notifications = implode(',', $notifications);
1633+
$paramsExtra['notifications'] = $notifications;
1634+
}
16221635
}
16231636

16241637
$params = array_merge($params, $paramsExtra);
@@ -1687,6 +1700,18 @@ public function save($type_e = '')
16871700
'hide_question_title' => $this->getHideQuestionTitle()
16881701
];
16891702

1703+
$allow = api_get_configuration_value('allow_quiz_show_previous_button_setting');
1704+
if ($allow === true) {
1705+
$params['show_previous_button'] = $this->showPreviousButton();
1706+
}
1707+
1708+
$allow = api_get_configuration_value('allow_notification_setting_per_exercise');
1709+
if ($allow === true) {
1710+
$notifications = $this->getNotifications();
1711+
$notifications = implode(',', $notifications);
1712+
$params['notifications'] = $notifications;
1713+
}
1714+
16901715
$this->id = Database::insert($TBL_EXERCISES, $params);
16911716

16921717
if ($this->id) {
@@ -1993,11 +2018,30 @@ public function createForm($form, $type = 'full')
19932018

19942019
// Type of questions disposition on page
19952020
$radios = array();
1996-
$radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all'));
1997-
$radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one'));
2021+
$radios[] = $form->createElement(
2022+
'radio',
2023+
'exerciseType',
2024+
null,
2025+
get_lang('SimpleExercise'),
2026+
'1',
2027+
array(
2028+
'onclick' => 'check_per_page_all()',
2029+
'id' => 'option_page_all'
2030+
)
2031+
);
2032+
$radios[] = $form->createElement(
2033+
'radio',
2034+
'exerciseType',
2035+
null,
2036+
get_lang('SequentialExercise'),
2037+
'2',
2038+
array(
2039+
'onclick' => 'check_per_page_one()',
2040+
'id' => 'option_page_one'
2041+
)
2042+
);
19982043

19992044
$form->addGroup($radios, null, get_lang('QuestionsPerPage'));
2000-
20012045
} else {
20022046
// if is Direct feedback but has not questions we can allow to modify the question type
20032047
if ($this->selectNbrQuestions() == 0) {
@@ -2315,7 +2359,30 @@ public function createForm($form, $type = 'full')
23152359
$editor_config
23162360
);
23172361

2318-
$form->addCheckBox('update_title_in_lps', null, get_lang('UpdateTitleInLps'));
2362+
$allow = api_get_configuration_value('allow_notification_setting_per_exercise');
2363+
2364+
if ($allow === true) {
2365+
$settings = ExerciseLib::getNotificationSettings();
2366+
$group = [];
2367+
foreach ($settings as $itemId => $label) {
2368+
$group[] = $form->createElement(
2369+
'checkbox',
2370+
'notifications[]',
2371+
null,
2372+
$label,
2373+
['value' => $itemId]
2374+
);
2375+
}
2376+
2377+
$form->addGroup($group, '', [get_lang('EmailNotifications')]);
2378+
2379+
}
2380+
2381+
$form->addCheckBox(
2382+
'update_title_in_lps',
2383+
null,
2384+
get_lang('UpdateTitleInLps')
2385+
);
23192386

23202387
$defaults = array();
23212388
if (api_get_setting('search_enabled') === 'true') {
@@ -2408,6 +2475,7 @@ public function createForm($form, $type = 'full')
24082475
} else {
24092476
$defaults['enabletimercontroltotalminutes'] = 0;
24102477
}
2478+
$defaults['notifications'] = $this->getNotifications();
24112479
} else {
24122480
$defaults['exerciseType'] = 2;
24132481
$defaults['exerciseAttempts'] = 0;
@@ -2496,6 +2564,7 @@ public function processCreation($form, $type = '')
24962564
$this->setScoreTypeModel($form->getSubmitValue('score_type_model'));
24972565
$this->setGlobalCategoryId($form->getSubmitValue('global_category_id'));
24982566
$this->setShowPreviousButton($form->getSubmitValue('show_previous_button'));
2567+
$this->setNotifications($form->getSubmitValue('notifications'));
24992568

25002569
if ($form->getSubmitValue('activate_start_date_check') == 1) {
25012570
$start_time = $form->getSubmitValue('start_time');
@@ -5444,10 +5513,15 @@ public function send_mail_notification_for_exam(
54445513
) {
54455514
$setting = api_get_course_setting('email_alert_manager_on_new_quiz');
54465515

5447-
if (empty($setting)) {
5516+
if (empty($setting) && empty($this->getNotifications())) {
54485517
return false;
54495518
}
54505519

5520+
$settingFromExercise = $this->getNotifications();
5521+
if (!empty($settingFromExercise)) {
5522+
$setting = $settingFromExercise;
5523+
}
5524+
54515525
// Email configuration settings
54525526
$courseCode = api_get_course_id();
54535527
$courseInfo = api_get_course_info($courseCode);
@@ -5457,7 +5531,6 @@ public function send_mail_notification_for_exam(
54575531
}
54585532

54595533
$sessionId = api_get_session_id();
5460-
54615534
$sendStart = false;
54625535
$sendEnd = false;
54635536
$sendEndOpenQuestion = false;
@@ -7642,4 +7715,20 @@ public function setShowPreviousButton($showPreviousButton)
76427715

76437716
return $this;
76447717
}
7718+
7719+
/**
7720+
* @param array $notifications
7721+
*/
7722+
public function setNotifications($notifications)
7723+
{
7724+
$this->notifications = $notifications;
7725+
}
7726+
7727+
/**
7728+
* @return array
7729+
*/
7730+
public function getNotifications()
7731+
{
7732+
return $this->notifications;
7733+
}
76457734
}

main/inc/lib/exercise.lib.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -590,14 +590,16 @@ public static function showQuestion(
590590
$displayForStudent = true;
591591
$listAnswerInfo = FillBlanks::getAnswerInfo($answer);
592592

593-
list($answer) = explode('::', $answer);
594593
// Correct answers
595594
$correctAnswerList = $listAnswerInfo['tabwords'];
596595

597596
// Student's answer
598597
$studentAnswerList = array();
599598
if (isset($user_choice[0]['answer'])) {
600-
$arrayStudentAnswer = FillBlanks::getAnswerInfo($user_choice[0]['answer'], true);
599+
$arrayStudentAnswer = FillBlanks::getAnswerInfo(
600+
$user_choice[0]['answer'],
601+
true
602+
);
601603
$studentAnswerList = $arrayStudentAnswer['studentanswer'];
602604
}
603605

@@ -4298,4 +4300,19 @@ public static function getOralFeedbackAudio($attemptId, $questionId, $userId)
42984300
['src' => $filePath]
42994301
);
43004302
}
4303+
4304+
/**
4305+
* @return array
4306+
*/
4307+
public static function getNotificationSettings()
4308+
{
4309+
$emailAlerts = [
4310+
2 => get_lang('SendEmailToTeacherWhenStudentStartQuiz'),
4311+
1 => get_lang('SendEmailToTeacherWhenStudentEndQuiz'), // default
4312+
3 => get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOpenQuestion'),
4313+
4 => get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOralQuestion')
4314+
];
4315+
4316+
return $emailAlerts;
4317+
}
43014318
}

main/install/configuration.dist.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,11 +511,13 @@
511511
//$_configuration['allow_quiz_show_previous_button_setting'] = false;
512512
// Allow to teachers review exercises question with audio notes
513513
//$_configuration["allow_teacher_comment_audio"] = false;
514-
515514
// Hide search form in session list
516515
//$_configuration['hide_search_form_in_session_list'] = false;
517516
// Allow exchange of messages from teachers/bosses about a user.
518517
//$_configuration['private_messages_about_user'] = false;
518+
// Allow send email notification per exercise
519+
//ALTER TABLE c_quiz ADD COLUMN notifications VARCHAR(255) NULL DEFAULT NULL;
520+
//$_configuration['allow_notification_setting_per_exercise'] = false;
519521

520522
// Score model
521523
// Allow to convert a score into a text/color label

0 commit comments

Comments
 (0)