Преглед на файлове

Adding email template notification see BT#6041 + fixing BT#6221

Julio Montoya преди 11 години
родител
ревизия
c143ea1c8e
променени са 3 файла, в които са добавени 56 реда и са изтрити 16 реда
  1. 54 16
      main/exercice/exercise.class.php
  2. 1 0
      main/install/1.10.0/db_course.sql
  3. 1 0
      main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql

+ 54 - 16
main/exercice/exercise.class.php

@@ -71,6 +71,7 @@ class Exercise
     public $categoryWithQuestionList;
     public $mediaList;
     public $loadQuestionAJAX = false;
+    public $emailNotificationTemplate = null;
 
     /**
      * Constructor of the class
@@ -109,6 +110,7 @@ class Exercise
         $this->course_id = $course_info['real_id'];
         $this->course = $course_info;
         $this->fastExerciseEdition = api_get_course_setting('allow_fast_exercise_edition') == 1 ? true : false;
+        $this->emailAlert = api_get_course_setting('email_alert_manager_on_new_quiz') == 1 ? true : false;
     }
 
     /**
@@ -156,6 +158,7 @@ class Exercise
             $this->pass_percentage = $object->pass_percentage;
             $this->is_gradebook_locked = api_resource_is_locked_by_gradebook($id, LINK_EXERCISE);
             $this->endButton = $object->end_button;
+            $this->emailNotificationTemplate = $object->email_notification_template;
 
             $this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false;
             $sql = "SELECT max_score FROM $table_lp_item
@@ -316,19 +319,30 @@ class Exercise
     /**
      * @return string
      */
-    function selectPassPercentage()
+    public function selectPassPercentage()
     {
         return $this->pass_percentage;
     }
 
+    /**
+     * @return string
+     */
+    public function selectEmailNotificationTemplate()
+    {
+        return $this->emailNotificationTemplate;
+    }
+
+    /**
+     * @return int
+     */
     public function selectEndButton()
     {
         return $this->endButton;
     }
 
     /**
-     * @author - hubert borderiou 30-11-11
-     * @return - : modify object to update the switch display_category_name
+     * @author Hubert borderiou 30-11-11
+     * @return modify object to update the switch display_category_name
      * $in_txt is an integer 0 or 1
      */
     public function updateDisplayCategoryName($text)
@@ -338,7 +352,7 @@ class Exercise
 
     /**
      * @author - hubert borderiou 28-11-11
-     * @return - html text : the text to display ay the end of the test.
+     * @return string html text : the text to display ay the end of the test.
      */
     public function selectTextWhenFinished()
     {
@@ -965,6 +979,14 @@ class Exercise
         $this->pass_percentage = $value;
     }
 
+    /**
+     * @param $text
+     */
+    public function updateEmailNotificationTemplate($text)
+    {
+        $this->emailNotificationTemplate = $text;
+    }
+
     public function updateEndButton($value)
     {
         $this->endButton = intval($value);
@@ -1166,6 +1188,7 @@ class Exercise
         	        display_category_name = '".Database::escape_string($display_category_name)."',
                     pass_percentage = '".Database::escape_string($pass_percentage)."',
                     end_button = '".$this->selectEndButton()."',
+                    email_notification_template = '".Database::escape_string($this->selectEmailNotificationTemplate())."',
 					results_disabled='".Database::escape_string($results_disabled)."'";
             }
             $sql .= " WHERE iid = ".Database::escape_string($id)." AND c_id = {$this->course_id}";
@@ -1180,11 +1203,12 @@ class Exercise
         } else {
             // Creates a new exercise
             $sql = "INSERT INTO $TBL_EXERCICES (c_id, start_time, end_time, title, description, sound, type, random, random_answers, active,
-                                                results_disabled, max_attempt, feedback_type, expired_time, session_id, review_answers, random_by_category,
-                                                text_when_finished, display_category_name, pass_percentage)
+                                                max_attempt, feedback_type, expired_time, session_id, review_answers, random_by_category,
+                                                text_when_finished, display_category_name, pass_percentage, end_button, email_notification_template, results_disabled)
 					VALUES(
 						".$this->course_id.",
-						'$start_time','$end_time',
+						'$start_time',
+                        '$end_time',
 						'".Database::escape_string($exercise)."',
 						'".Database::escape_string($description)."',
 						'".Database::escape_string($sound)."',
@@ -1192,7 +1216,6 @@ class Exercise
 						'".Database::escape_string($random)."',
 						'".Database::escape_string($random_answers)."',
 						'".Database::escape_string($active)."',
-						'".Database::escape_string($results_disabled)."',
 						'".Database::escape_string($attempts)."',
 						'".Database::escape_string($feedback_type)."',
 						'".Database::escape_string($expired_time)."',
@@ -1201,7 +1224,10 @@ class Exercise
 						'".Database::escape_string($randomByCat)."',
 						'".Database::escape_string($text_when_finished)."',
 						'".Database::escape_string($display_category_name)."',
-                        '".Database::escape_string($pass_percentage)."'
+                        '".Database::escape_string($pass_percentage)."',
+                        '".Database::escape_string($this->selectEndButton())."',
+                        '".Database::escape_string($this->selectEmailNotificationTemplate())."',
+                        '".Database::escape_string($results_disabled)."'
 						)";
             Database::query($sql);
             $this->id = Database::insert_id();
@@ -1772,6 +1798,13 @@ class Exercise
                 }
             }
 
+            if ($this->emailAlert) {
+
+                // Text when ending an exam
+                $form->add_html_editor('email_notification_template', array(get_lang('EmailNotificationTemplate'), get_lang('EmailNotificationTemplateDescription')), null, false, $editor_config);
+            }
+
+
             $form->addElement('html', '</div>'); //End advanced setting
             $form->addElement('html', '</div>');
         }
@@ -1813,12 +1846,12 @@ class Exercise
                 $defaults['results_disabled'] = $this->selectResultsDisabled();
                 $defaults['propagate_neg'] = $this->selectPropagateNeg();
                 $defaults['review_answers'] = $this->review_answers;
-                $defaults['randomByCat'] = $this->selectRandomByCat(); //
-                $defaults['text_when_finished'] = $this->selectTextWhenFinished(); //
-                $defaults['display_category_name'] = $this->selectDisplayCategoryName(); //
+                $defaults['randomByCat'] = $this->selectRandomByCat();
+                $defaults['text_when_finished'] = $this->selectTextWhenFinished();
+                $defaults['display_category_name'] = $this->selectDisplayCategoryName();
                 $defaults['pass_percentage'] = $this->selectPassPercentage();
                 $defaults['end_button'] = $this->selectEndButton();
-
+                $defaults['email_notification_template'] = $this->selectEmailNotificationTemplate();
 
                 if (($this->start_time != '0000-00-00 00:00:00')) {
                     $defaults['activate_start_date_check'] = 1;
@@ -1889,6 +1922,7 @@ class Exercise
         $this->updatePassPercentage($form->getSubmitValue('pass_percentage'));
         $this->updateCategories($form->getSubmitValue('category'));
         $this->updateEndButton($form->getSubmitValue('end_button'));
+        $this->updateEmailNotificationTemplate($form->getSubmitValue('email_notification_template'));
 
         if ($form->getSubmitValue('activate_start_date_check') == 1) {
             $start_time = $form->getSubmitValue('start_time');
@@ -4330,6 +4364,11 @@ class Exercise
         return $return_array;
     }
 
+    public function sendCustomNotification($exeId)
+    {
+        $this->emailAlertContent;
+    }
+
     /**
      * Sends a notification when a user ends an examn
      * @param array $question_list_answers
@@ -4339,7 +4378,7 @@ class Exercise
      */
     public function sendNotificationForOpenQuestions($question_list_answers, $origin, $exe_id)
     {
-        if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1) {
+        if ($this->emailAlert == false) {
             return null;
         }
         // Email configuration settings
@@ -4423,7 +4462,7 @@ class Exercise
 
     public function sendNotificationForOralQuestions($question_list_answers, $origin, $exe_id)
     {
-        if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1) {
+        if ($this->emailAlert == false) {
             return null;
         }
         // Email configuration settings
@@ -5638,5 +5677,4 @@ class Exercise
             echo '</div>';
         }
     }
-
 }

+ 1 - 0
main/install/1.10.0/db_course.sql

@@ -1305,6 +1305,7 @@ CREATE TABLE c_quiz (
   pass_percentage int(11) DEFAULT NULL,
   autolaunch INT DEFAULT 0,
   end_button int NOT NULL DEFAULT 0,
+  email_notification_template text default '',
   PRIMARY KEY (iid)
 ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
 /*!40101 SET character_set_client = @saved_cs_client */;

+ 1 - 0
main/install/1.10.0/migrate-db-1.9.0-1.10.0-pre.sql

@@ -95,6 +95,7 @@ ALTER TABLE session ADD INDEX idx_id_coach (id_coach);
 ALTER TABLE session ADD INDEX idx_id_session_admin_id (session_admin_id);
 
 ALTER TABLE c_quiz_question ADD COLUMN parent_id INT unsigned NOT NULL DEFAULT 0;
+ALTER TABLE c_quiz ADD COLUMN email_notification_template TEXT DEFAULT '';
 
 CREATE TABLE IF NOT EXISTS gradebook_evaluation_type(id INT unsigned PRIMARY KEY NOT NULL AUTO_INCREMENT, name varchar(255), external_id INT unsigned NOT NULL DEFAULT 0);