From 6d347e73f4635ae7f23a85e43fc696402a036f4a Mon Sep 17 00:00:00 2001 From: jmontoyaa Date: Mon, 10 Jul 2017 14:58:26 +0200 Subject: [PATCH] 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. --- main/course_info/infocours.php | 23 ++++--- main/exercise/exercise.class.php | 101 ++++++++++++++++++++++++++-- main/inc/lib/exercise.lib.php | 21 +++++- main/install/configuration.dist.php | 4 +- 4 files changed, 130 insertions(+), 19 deletions(-) diff --git a/main/course_info/infocours.php b/main/course_info/infocours.php index 36eb6a731a..94152642fc 100755 --- a/main/course_info/infocours.php +++ b/main/course_info/infocours.php @@ -327,18 +327,21 @@ $group[] = $form->createElement('radio', 'email_alert_on_new_doc_dropbox', get_l $group[] = $form->createElement('radio', 'email_alert_on_new_doc_dropbox', null, get_lang('DropboxEmailAlertDeactivate'), 0); $form->addGroup($group, '', array(get_lang("DropboxEmailAlert"))); -$group = array(); - -$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentStartQuiz'), ['value' => 2]); -// Default -$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuiz'), ['value' => 1]); -$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOpenQuestion'), ['value' => 3]); -$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOralQuestion'), ['value' => 4]); -//$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('QuizEmailAlertDeactivate'), ['value' => 0]); +// Exercises notifications +$emailAlerts = ExerciseLib::getNotificationSettings(); +$group = []; +foreach ($emailAlerts as $itemId => $label) { + $group[] = $form->createElement( + 'checkbox', + 'email_alert_manager_on_new_quiz[]', + null, + $label, + ['value' => $itemId] + ); +} -//$group[] = $form->createElement('checkbox', 'email_alert_manager_on_new_quiz[]', null, get_lang('QuizEmailSendToTeacherWhenStudentEndQuiz'), ['value' => 3]); -$form->addGroup($group, '', array(get_lang("Exercises"))); +$form->addGroup($group, '', array(get_lang('Exercises'))); $form->addButtonSave(get_lang('SaveSettings'), 'submit_save'); $form->addHtml(' diff --git a/main/exercise/exercise.class.php b/main/exercise/exercise.class.php index bf9a4f90a0..426bb9a2b5 100755 --- a/main/exercise/exercise.class.php +++ b/main/exercise/exercise.class.php @@ -77,6 +77,7 @@ class Exercise public $questionFeedbackEnabled = false; public $questionTypeWithFeedback; public $showPreviousButton; + public $notifications; /** * Constructor of the class @@ -178,6 +179,11 @@ class Exercise $this->questionSelectionType = isset($object->question_selection_type) ? $object->question_selection_type : null; $this->hideQuestionTitle = isset($object->hide_question_title) ? (int) $object->hide_question_title : 0; + $this->notifications = []; + if (!empty($object->notifications)) { + $this->notifications = explode(',', $object->notifications); + } + if (isset($object->show_previous_button)) { $this->showPreviousButton = $object->show_previous_button == 1 ? true : false; } @@ -1619,6 +1625,13 @@ class Exercise if ($allow === true) { $paramsExtra['show_previous_button'] = $this->showPreviousButton(); } + + $allow = api_get_configuration_value('allow_notification_setting_per_exercise'); + if ($allow === true) { + $notifications = $this->getNotifications(); + $notifications = implode(',', $notifications); + $paramsExtra['notifications'] = $notifications; + } } $params = array_merge($params, $paramsExtra); @@ -1687,6 +1700,18 @@ class Exercise 'hide_question_title' => $this->getHideQuestionTitle() ]; + $allow = api_get_configuration_value('allow_quiz_show_previous_button_setting'); + if ($allow === true) { + $params['show_previous_button'] = $this->showPreviousButton(); + } + + $allow = api_get_configuration_value('allow_notification_setting_per_exercise'); + if ($allow === true) { + $notifications = $this->getNotifications(); + $notifications = implode(',', $notifications); + $params['notifications'] = $notifications; + } + $this->id = Database::insert($TBL_EXERCISES, $params); if ($this->id) { @@ -1993,11 +2018,30 @@ class Exercise // Type of questions disposition on page $radios = array(); - $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all')); - $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'), '2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one')); + $radios[] = $form->createElement( + 'radio', + 'exerciseType', + null, + get_lang('SimpleExercise'), + '1', + array( + 'onclick' => 'check_per_page_all()', + 'id' => 'option_page_all' + ) + ); + $radios[] = $form->createElement( + 'radio', + 'exerciseType', + null, + get_lang('SequentialExercise'), + '2', + array( + 'onclick' => 'check_per_page_one()', + 'id' => 'option_page_one' + ) + ); $form->addGroup($radios, null, get_lang('QuestionsPerPage')); - } else { // if is Direct feedback but has not questions we can allow to modify the question type if ($this->selectNbrQuestions() == 0) { @@ -2315,7 +2359,30 @@ class Exercise $editor_config ); - $form->addCheckBox('update_title_in_lps', null, get_lang('UpdateTitleInLps')); + $allow = api_get_configuration_value('allow_notification_setting_per_exercise'); + + if ($allow === true) { + $settings = ExerciseLib::getNotificationSettings(); + $group = []; + foreach ($settings as $itemId => $label) { + $group[] = $form->createElement( + 'checkbox', + 'notifications[]', + null, + $label, + ['value' => $itemId] + ); + } + + $form->addGroup($group, '', [get_lang('EmailNotifications')]); + + } + + $form->addCheckBox( + 'update_title_in_lps', + null, + get_lang('UpdateTitleInLps') + ); $defaults = array(); if (api_get_setting('search_enabled') === 'true') { @@ -2408,6 +2475,7 @@ class Exercise } else { $defaults['enabletimercontroltotalminutes'] = 0; } + $defaults['notifications'] = $this->getNotifications(); } else { $defaults['exerciseType'] = 2; $defaults['exerciseAttempts'] = 0; @@ -2496,6 +2564,7 @@ class Exercise $this->setScoreTypeModel($form->getSubmitValue('score_type_model')); $this->setGlobalCategoryId($form->getSubmitValue('global_category_id')); $this->setShowPreviousButton($form->getSubmitValue('show_previous_button')); + $this->setNotifications($form->getSubmitValue('notifications')); if ($form->getSubmitValue('activate_start_date_check') == 1) { $start_time = $form->getSubmitValue('start_time'); @@ -5444,10 +5513,15 @@ class Exercise ) { $setting = api_get_course_setting('email_alert_manager_on_new_quiz'); - if (empty($setting)) { + if (empty($setting) && empty($this->getNotifications())) { return false; } + $settingFromExercise = $this->getNotifications(); + if (!empty($settingFromExercise)) { + $setting = $settingFromExercise; + } + // Email configuration settings $courseCode = api_get_course_id(); $courseInfo = api_get_course_info($courseCode); @@ -5457,7 +5531,6 @@ class Exercise } $sessionId = api_get_session_id(); - $sendStart = false; $sendEnd = false; $sendEndOpenQuestion = false; @@ -7642,4 +7715,20 @@ class Exercise return $this; } + + /** + * @param array $notifications + */ + public function setNotifications($notifications) + { + $this->notifications = $notifications; + } + + /** + * @return array + */ + public function getNotifications() + { + return $this->notifications; + } } diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 888f6c5e7a..2946fd0fa5 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -590,14 +590,16 @@ class ExerciseLib $displayForStudent = true; $listAnswerInfo = FillBlanks::getAnswerInfo($answer); - list($answer) = explode('::', $answer); // Correct answers $correctAnswerList = $listAnswerInfo['tabwords']; // Student's answer $studentAnswerList = array(); if (isset($user_choice[0]['answer'])) { - $arrayStudentAnswer = FillBlanks::getAnswerInfo($user_choice[0]['answer'], true); + $arrayStudentAnswer = FillBlanks::getAnswerInfo( + $user_choice[0]['answer'], + true + ); $studentAnswerList = $arrayStudentAnswer['studentanswer']; } @@ -4298,4 +4300,19 @@ HOTSPOT; ['src' => $filePath] ); } + + /** + * @return array + */ + public static function getNotificationSettings() + { + $emailAlerts = [ + 2 => get_lang('SendEmailToTeacherWhenStudentStartQuiz'), + 1 => get_lang('SendEmailToTeacherWhenStudentEndQuiz'), // default + 3 => get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOpenQuestion'), + 4 => get_lang('SendEmailToTeacherWhenStudentEndQuizOnlyIfOralQuestion') + ]; + + return $emailAlerts; + } } diff --git a/main/install/configuration.dist.php b/main/install/configuration.dist.php index b4134d6008..73eeee64f6 100755 --- a/main/install/configuration.dist.php +++ b/main/install/configuration.dist.php @@ -511,11 +511,13 @@ $_configuration['send_all_emails_to'] = [ //$_configuration['allow_quiz_show_previous_button_setting'] = false; // Allow to teachers review exercises question with audio notes //$_configuration["allow_teacher_comment_audio"] = false; - // Hide search form in session list //$_configuration['hide_search_form_in_session_list'] = false; // Allow exchange of messages from teachers/bosses about a user. //$_configuration['private_messages_about_user'] = false; +// Allow send email notification per exercise +//ALTER TABLE c_quiz ADD COLUMN notifications VARCHAR(255) NULL DEFAULT NULL; +//$_configuration['allow_notification_setting_per_exercise'] = false; // Score model // Allow to convert a score into a text/color label