@@ -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}
0 commit comments