Julio Montoya пре 10 година
родитељ
комит
c7e1b7d421
2 измењених фајлова са 117 додато и 76 уклоњено
  1. 75 49
      main/exercice/exercise.class.php
  2. 42 27
      main/inc/lib/course.lib.php

+ 75 - 49
main/exercice/exercise.class.php

@@ -3626,6 +3626,7 @@ class Exercise
             'open_answer'   => $arrans,
             'answer_type'   => $answerType
         );
+
         return $return_array;
     }
 
@@ -3633,15 +3634,21 @@ class Exercise
      * Sends a notification when a user ends an examn
      *
      */
-    function send_mail_notification_for_exam($question_list_answers, $origin, $exe_id) {
+    public function send_mail_notification_for_exam($question_list_answers, $origin, $exe_id)
+    {
         if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
             return null;
         }
         // Email configuration settings
-        $courseCode     = api_get_course_id();
-        $courseInfo    = api_get_course_info($courseCode);
+        $courseCode = api_get_course_id();
+        $courseInfo = api_get_course_info($courseCode);
+        $sessionId = api_get_session_id();
 
-        $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&id='.$exe_id.'&action=qualify';
+        if (empty($courseInfo)) {
+            return false;
+        }
+
+        $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.$sessionId.'&id='.$exe_id.'&action=qualify';
         $user_info = UserManager::get_user_info_by_id(api_get_user_id());
 
         $msg = '<p>'.get_lang('ExerciseAttempted').' :</p>
@@ -3666,12 +3673,11 @@ class Exercise
                     </table>';
         $open_question_list = null;
 
-        $msg    = str_replace("#email#",       $user_info['email'],$msg);
-        $msg1   = str_replace("#exercise#",    $this->exercise, $msg);
-        $msg    = str_replace("#firstName#",   $user_info['firstname'],$msg1);
-        $msg1   = str_replace("#lastName#",    $user_info['lastname'],$msg);
-
-        $msg    = str_replace("#course#",      $courseInfo['name'],$msg1);
+        $msg = str_replace("#email#", $user_info['email'], $msg);
+        $msg1 = str_replace("#exercise#", $this->exercise, $msg);
+        $msg = str_replace("#firstName#", $user_info['firstname'], $msg1);
+        $msg1 = str_replace("#lastName#", $user_info['lastname'], $msg);
+        $msg = str_replace("#course#", $courseInfo['name'], $msg1);
 
         if ($origin != 'learnpath') {
             $msg.= get_lang('ClickToCommentAndGiveFeedback').', <br />
@@ -3681,32 +3687,35 @@ class Exercise
         $mail_content = $msg1;
         $subject = get_lang('ExerciseAttempted');
 
-        $teachers = array();
-        if (api_get_session_id()) {
-            $teachers = CourseManager::get_coach_list_from_course_code($coursecode, api_get_session_id());
+        if (!empty($sessionId)) {
+            $teachers = CourseManager::get_coach_list_from_course_code($courseCode, $sessionId);
         } else {
-            $teachers = CourseManager::get_teacher_list_from_course_code($courseInfo['code']);
+            $teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
         }
 
         if (!empty($teachers)) {
             foreach ($teachers as $user_id => $teacher_data) {
-                MessageManager::send_message_simple($user_id, $subject, $mail_content);
+                MessageManager::send_message_simple(
+                    $user_id,
+                    $subject,
+                    $mail_content
+                );
             }
         }
-
     }
 
     /**
      * Sends a notification when a user ends an examn
      *
      */
-    function send_notification_for_open_questions($question_list_answers, $origin, $exe_id) {
+    function send_notification_for_open_questions($question_list_answers, $origin, $exe_id)
+    {
         if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
             return null;
         }
         // Email configuration settings
-        $coursecode     = api_get_course_id();
-        $course_info    = api_get_course_info(api_get_course_id());
+        $courseCode     = api_get_course_id();
+        $course_info    = api_get_course_info($courseCode);
 
         $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&id='.$exe_id.'&action=qualify';
         $user_info = UserManager::get_user_info_by_id(api_get_user_id());
@@ -3770,33 +3779,36 @@ class Exercise
             $mail_content = $msg1;
             $subject = get_lang('OpenQuestionsAttempted');
 
-            $teachers = array();
             if (api_get_session_id()) {
-                $teachers = CourseManager::get_coach_list_from_course_code($coursecode, api_get_session_id());
+                $teachers = CourseManager::get_coach_list_from_course_code($courseCode, api_get_session_id());
             } else {
-                $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
+                $teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
             }
 
             if (!empty($teachers)) {
                 foreach ($teachers as $user_id => $teacher_data) {
-                    MessageManager::send_message_simple($user_id, $subject, $mail_content);
+                    MessageManager::send_message_simple(
+                        $user_id,
+                        $subject,
+                        $mail_content
+                    );
                 }
             }
         }
     }
 
-    function send_notification_for_oral_questions($question_list_answers, $origin, $exe_id) {
+    function send_notification_for_oral_questions($question_list_answers, $origin, $exe_id)
+    {
         if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
             return null;
         }
         // Email configuration settings
-        $coursecode     = api_get_course_id();
-        $course_info    = api_get_course_info(api_get_course_id());
+        $courseCode     = api_get_course_id();
+        $course_info    = api_get_course_info($courseCode);
 
         $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&id='.$exe_id.'&action=qualify';
         $user_info = UserManager::get_user_info_by_id(api_get_user_id());
 
-
         $oral_question_list = null;
         foreach ($question_list_answers as $item) {
             $question    = $item['question'];
@@ -3851,16 +3863,19 @@ class Exercise
             $mail_content = $msg1;
             $subject = get_lang('OralQuestionsAttempted');
 
-            $teachers = array();
             if (api_get_session_id()) {
-                $teachers = CourseManager::get_coach_list_from_course_code($coursecode, api_get_session_id());
+                $teachers = CourseManager::get_coach_list_from_course_code($courseCode, api_get_session_id());
             } else {
-                $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
+                $teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
             }
 
             if (!empty($teachers)) {
                 foreach ($teachers as $user_id => $teacher_data) {
-                    MessageManager::send_message_simple($user_id, $subject, $mail_content);
+                    MessageManager::send_message_simple(
+                        $user_id,
+                        $subject,
+                        $mail_content
+                    );
                 }
             }
         }
@@ -3954,7 +3969,8 @@ class Exercise
         return $quiz_id;
     }
 
-    function process_geometry() {
+    function process_geometry()
+    {
 
     }
 
@@ -3963,7 +3979,6 @@ class Exercise
      * @param 	int		attempt id
      * @return 	float 	exercise result
      */
-
     public function get_exercise_result($exe_id) {
         $result = array();
         $track_exercise_info = get_exercise_track_exercise_info($exe_id);
@@ -4125,7 +4140,8 @@ class Exercise
     public function added_in_lp()
     {
         $TBL_LP_ITEM	= Database::get_course_table(TABLE_LP_ITEM);
-        $sql = "SELECT max_score FROM $TBL_LP_ITEM WHERE c_id = ".$this->course_id." AND item_type = '".TOOL_QUIZ."' AND path = '".$this->id."'";
+        $sql = "SELECT max_score FROM $TBL_LP_ITEM
+                WHERE c_id = ".$this->course_id." AND item_type = '".TOOL_QUIZ."' AND path = '".$this->id."'";
         $result = Database::query($sql);
         if (Database::num_rows($result) > 0) {
             return true;
@@ -4133,7 +4149,8 @@ class Exercise
         return false;
     }
 
-    function get_media_list() {
+    function get_media_list()
+    {
         $media_questions = array();
         $question_list = $this->get_validated_question_list();
         if (!empty($question_list)) {
@@ -4150,7 +4167,8 @@ class Exercise
         return $media_questions;
     }
 
-    function media_is_activated($media_list) {
+    function media_is_activated($media_list)
+    {
         $active = false;
         if (isset($media_list) && !empty($media_list)) {
             $media_count = count($media_list);
@@ -4167,7 +4185,8 @@ class Exercise
         return $active;
     }
 
-    function get_validated_question_list() {
+    function get_validated_question_list()
+    {
         $tabres = array();
         $isRandomByCategory = $this->isRandomByCat();
         if ($isRandomByCategory == 0) {
@@ -4221,13 +4240,15 @@ class Exercise
         return $tabres;
     }
 
-    function get_question_list($expand_media_questions = false) {
+    function get_question_list($expand_media_questions = false)
+    {
         $question_list = $this->get_validated_question_list();
         $question_list = $this->transform_question_list_with_medias($question_list, $expand_media_questions);
         return $question_list;
     }
 
-    function transform_question_list_with_medias($question_list, $expand_media_questions = false) {
+    function transform_question_list_with_medias($question_list, $expand_media_questions = false)
+    {
         $new_question_list = array();
         if (!empty($question_list)) {
             $media_questions = $this->get_media_list();
@@ -4268,7 +4289,8 @@ class Exercise
         return $new_question_list;
     }
 
-    public function get_stat_track_exercise_info_by_exe_id($exe_id) {
+    public function get_stat_track_exercise_info_by_exe_id($exe_id)
+    {
         $track_exercises = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
         $exe_id = intval($exe_id);
         $sql_track = "SELECT * FROM $track_exercises WHERE exe_id = $exe_id ";
@@ -4298,7 +4320,8 @@ class Exercise
         return $new_array;
     }
 
-    public function edit_question_to_remind($exe_id, $question_id, $action = 'add') {
+    public function edit_question_to_remind($exe_id, $question_id, $action = 'add')
+    {
         $exercise_info = self::get_stat_track_exercise_info_by_exe_id($exe_id);
         $question_id = intval($question_id);
         $exe_id = intval($exe_id);
@@ -4340,18 +4363,20 @@ class Exercise
                 }
                 $remind_list_string = Database::escape_string($remind_list_string);
                 $sql = "UPDATE $track_exercises SET questions_to_check = '$remind_list_string' WHERE exe_id = $exe_id ";
-                $result = Database::query($sql);
+                Database::query($sql);
             }
         }
     }
 
-    public function fill_in_blank_answer_to_array($answer) {
+    public function fill_in_blank_answer_to_array($answer)
+    {
         api_preg_match_all('/\[[^]]+\]/', $answer, $teacher_answer_list);
         $teacher_answer_list = $teacher_answer_list[0];
         return $teacher_answer_list;
     }
 
-    public function fill_in_blank_answer_to_string($answer) {
+    public function fill_in_blank_answer_to_string($answer)
+    {
         $teacher_answer_list = $this->fill_in_blank_answer_to_array($answer);
         $result = '';
         if (!empty($teacher_answer_list)) {
@@ -4372,13 +4397,15 @@ class Exercise
         return $result;
     }
 
-    function return_time_left_div() {
+    function return_time_left_div()
+    {
         $html  = '<div id="clock_warning" style="display:none">'.Display::return_message(get_lang('ReachedTimeLimit'), 'warning').' '.sprintf(get_lang('YouWillBeRedirectedInXSeconds'), '<span id="counter_to_redirect" class="red_alert"></span>').'</div>';
         $html .= '<div id="exercise_clock_warning" class="well count_down"></div>';
         return $html;
     }
 
-    function get_count_question_list() {
+    function get_count_question_list()
+    {
         //Real question count
         $question_count = 0;
         $question_list = $this->get_question_list();
@@ -4388,7 +4415,8 @@ class Exercise
         return $question_count;
     }
 
-    function get_exercise_list_ordered() {
+    function get_exercise_list_ordered()
+    {
         $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER);
         $course_id = api_get_course_int_id();
         $session_id = api_get_session_id();
@@ -4403,7 +4431,6 @@ class Exercise
         return $list;
     }
 
-
     /**
      * Calculate the max_score of the quiz, depending of question inside, and quiz advanced option
      */
@@ -4480,7 +4507,6 @@ class Exercise
         return api_htmlentities($this->title);
     }
 
-
     /**
      * @param $in_title
      * @return string

+ 42 - 27
main/inc/lib/course.lib.php

@@ -7,7 +7,7 @@ require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
 /**
  * Class CourseManager
  *
- *  This is the course library for Chamilo.
+ * This is the course library for Chamilo.
  *
  * All main course functions should be placed here.
  *
@@ -24,7 +24,8 @@ require_once api_get_path(LIBRARY_PATH).'add_course.lib.inc.php';
 class CourseManager
 {
     const MAX_COURSE_LENGTH_CODE = 40;
-    /** This constant is used to show separate user names in the course list (userportal), footer, etc */
+    /** This constant is used to show separate user names in the course
+     * list (userportal), footer, etc */
     const USER_SEPARATOR = ' |';
     const COURSE_FIELD_TYPE_CHECKBOX = 10;
     public $columns = array();
@@ -136,6 +137,7 @@ class CourseManager
      * Returns all the information of a given coursecode
      * @param   int     the course id
      * @return an array with all the fields of the course table
+     * @deprecated use api_get_course_info_by_id()
      * @assert ('') === false
      */
     public static function get_course_information_by_id($course_id)
@@ -271,8 +273,9 @@ class CourseManager
 
     /**
      * Returns the status of a user in a course, which is COURSEMANAGER or STUDENT.
-     * @param   int      User ID
-     * @param   string   Course code
+     * @param   int      $user_id
+     * @param   string   $course_code
+     *
      * @return int the status of the user in that course
      */
     public static function get_user_in_course_status($user_id, $course_code)
@@ -281,6 +284,7 @@ class CourseManager
             "SELECT status FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
             WHERE course_code = '".Database::escape_string($course_code)."' AND user_id = ".Database::escape_string($user_id))
         );
+
         return $result['status'];
     }
 
@@ -295,6 +299,7 @@ class CourseManager
                 "SELECT tutor_id FROM ".Database::get_main_table(TABLE_MAIN_COURSE_USER)."
                 WHERE course_code = '".Database::escape_string($course_code)."' AND user_id = ".Database::escape_string($user_id))
         );
+
         return $result['tutor_id'];
     }
 
@@ -523,7 +528,8 @@ class CourseManager
             }
 
             // check if the user is registered in the session with other course
-            $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)." WHERE id_session='".$session_id."' AND id_user='$user_id'";
+            $sql = "SELECT id_user FROM ".Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER)."
+                    WHERE id_session='".$session_id."' AND id_user='$user_id'";
             $rs = Database::query($sql);
             if (Database::num_rows($rs) == 0) {
                 // Check whether the user has not already been stored in the session_rel_user table
@@ -588,13 +594,14 @@ class CourseManager
     }
 
     /**
-     * Get the course id based on the original id and field name in the extra fields. Returns 0 if course was not found
-     *
-     * @param string Original course id
-     * @param string Original field name
-     * @return int Course id
-     * @assert ('', '') === false
-     */
+    * Get the course id based on the original id and field name in the
+    * extra fields. Returns 0 if course was not found
+    *
+    * @param string Original course id
+    * @param string Original field name
+    * @return int Course id
+    * @assert ('', '') === false
+    */
     public static function get_course_code_from_original_id($original_course_id_value, $original_course_id_name)
     {
         $t_cfv = Database::get_main_table(TABLE_MAIN_COURSE_FIELD_VALUES);
@@ -719,8 +726,8 @@ class CourseManager
     }
 
     /**
-     *    @return true if there already are one or more courses
-     *    with the same code OR visual_code (visualcode), false otherwise
+     *  @return true if there already are one or more courses
+     *  with the same code OR visual_code (visualcode), false otherwise
      */
     public static function course_code_exists($wanted_course_code)
     {
@@ -732,7 +739,7 @@ class CourseManager
     }
 
     /**
-     *    @return an array with the course info of all real courses on the platform
+     * @return an array with the course info of all real courses on the platform
      */
     public static function get_real_course_list() {
         $sql_result = Database::query("SELECT * FROM ".Database::get_main_table(TABLE_MAIN_COURSE)."
@@ -776,10 +783,13 @@ class CourseManager
                 WHERE course.target_course_code IS NULL
                     AND course_user.user_id = '$user_id'
                     AND course_user.status = '1'");
-        if ($sql_result === false) { return $result_array; }
+        if ($sql_result === false) {
+            return $result_array;
+        }
         while ($result = Database::fetch_array($sql_result)) {
             $result_array[] = $result;
         }
+
         return $result_array;
     }
 
@@ -818,6 +828,7 @@ class CourseManager
                 }
             }
         }
+
         return $courseList;
     }
 
@@ -1644,8 +1655,9 @@ class CourseManager
         $users = array();
 
         // We get the coach for the given course in a given session.
-        $rs = Database::query('SELECT id_user FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).
-                ' WHERE id_session="'.$session_id.'" AND course_code="'.$course_code.'" AND status = 2');
+        $sql = 'SELECT id_user FROM '.Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER).
+               ' WHERE id_session="'.$session_id.'" AND course_code="'.$course_code.'" AND status = 2';
+        $rs = Database::query($sql);
         while ($user = Database::fetch_array($rs)) {
             $user_info = api_get_user_info($user['id_user']);
             $user_info['status'] = $user['status'];
@@ -1656,7 +1668,9 @@ class CourseManager
         }
 
         // We get the session coach.
-        $rs = Database::query('SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).' WHERE id="'.$session_id.'"');
+        $sql = 'SELECT id_coach FROM '.Database::get_main_table(TABLE_MAIN_SESSION).'
+                WHERE id="'.$session_id.'"';
+        $rs = Database::query($sql);
         $session_id_coach = Database::result($rs, 0, 'id_coach');
         $user_info = api_get_user_info($session_id_coach);
         $user_info['status'] = $user['status'];
@@ -1669,15 +1683,15 @@ class CourseManager
     }
 
     /**
-     *    Return user info array of all users registered in the specified real or virtual course
-     *    This only returns the users that are registered in this actual course, not linked courses.
+     *  Return user info array of all users registered in the specified real or virtual course
+     *  This only returns the users that are registered in this actual course, not linked courses.
      *
-     *    @param string $course_code
-     *    @param boolean $with_session
-     *    @param integer $session_id
-     *    @param date $date_from
-     *    @param date $date_to
-     *    @return array with user id
+     *  @param string $course_code
+     *  @param boolean $with_session
+     *  @param integer $session_id
+     *  @param date $date_from
+     *  @param date $date_to
+     *  @return array with user id
      */
     public static function get_student_list_from_course_code(
         $course_code,
@@ -1730,6 +1744,7 @@ class CourseManager
                 $students[$student['id_user']] = $student;
             }
         }
+
         return $students;
     }