Browse Source

Rename function register_user_info_about_certificate registerUserInfoAboutCertificate, improve queries

jmontoyaa 8 years ago
parent
commit
03a12a248d

+ 2 - 1
main/forum/forumfunction.inc.php

@@ -5384,7 +5384,8 @@ function count_number_of_post_for_user_thread($thread_id, $user_id)
 {
     $table_posts = Database::get_course_table(TABLE_FORUM_POST);
     $course_id = api_get_course_int_id();
-    $sql = "SELECT count(*) as count FROM $table_posts
+    $sql = "SELECT count(iid) as count 
+            FROM $table_posts
             WHERE c_id = $course_id AND
                   thread_id=".intval($thread_id)." AND
                   poster_id = ".intval($user_id)." AND visible = 1 ";

+ 12 - 10
main/gradebook/lib/GradebookUtils.php

@@ -573,19 +573,21 @@ class GradebookUtils
 
     /**
      * register user info about certificate
-     * @param int The category id
-     * @param int The user id
-     * @param float The score obtained for certified
-     * @param Datetime The date when you obtained the certificate
-     * @param integer $cat_id
-     * @param integer $user_id
-     * @param string $date_certificate
+     * @param int $cat_id The category id
+     * @param int $user_id The user id
+     * @param float $score_certificate The score obtained for certified
+     * @param string $date_certificate The date when you obtained the certificate
+     *
      * @return void
      */
-    public static function register_user_info_about_certificate($cat_id, $user_id, $score_certificate, $date_certificate)
-    {
+    public static function registerUserInfoAboutCertificate(
+        $cat_id,
+        $user_id,
+        $score_certificate,
+        $date_certificate
+    ) {
         $table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
-        $sql = 'SELECT COUNT(*) as count
+        $sql = 'SELECT COUNT(id) as count
                 FROM ' . $table . ' gc
                 WHERE gc.cat_id="' . intval($cat_id) . '" AND user_id="' . intval($user_id) . '" ';
         $rs_exist = Database::query($sql);

+ 1 - 1
main/gradebook/lib/be/category.class.php

@@ -1992,7 +1992,7 @@ class Category implements GradebookItem
         );
 
         if (empty($my_certificate)) {
-            GradebookUtils::register_user_info_about_certificate(
+            GradebookUtils::registerUserInfoAboutCertificate(
                 $category_id,
                 $user_id,
                 $my_score_in_gradebook,

+ 11 - 13
main/inc/lib/course.lib.php

@@ -1661,7 +1661,8 @@ class CourseManager
         $courseInfo = api_get_course_info($course_code);
         $courseId = $courseInfo['real_id'];
 
-        $sql = 'SELECT DISTINCT count(*) as count  FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
+        $sql = 'SELECT DISTINCT count(user.id) as count  
+                FROM ' . Database::get_main_table(TABLE_MAIN_USER) . ' as user ';
         $where = array();
         if (!empty($session_id)) {
             $sql .= ' LEFT JOIN ' . Database::get_main_table(TABLE_MAIN_SESSION_COURSE_USER) . ' as session_course_user
@@ -1704,8 +1705,8 @@ class CourseManager
 
     /**
      * Get a list of coaches of a course and a session
-     * @param   string  Course code
-     * @param   int     Session ID
+     * @param   string  $course_code
+     * @param   int     $session_id
      * @param   bool $addGeneralCoach
      * @return  array   List of users
      */
@@ -1808,7 +1809,6 @@ class CourseManager
 
         // students subscribed to the course through a session
         if ($with_session) {
-
             $joinSession = "";
             //Session creation date
             if (!empty($date_from) && !empty($date_to)) {
@@ -1881,7 +1881,6 @@ class CourseManager
         return $teachers;
     }
 
-
     /**
      * Return user info array of all teacher-users registered in a course
      * This only returns the users that are registered in this actual course, not linked courses.
@@ -1964,7 +1963,7 @@ class CourseManager
             }
 
             if (!empty($list)) {
-                if ($orderList === true){
+                if ($orderList === true) {
                     $html .= '<ul class="user-teacher">';
                     foreach ($list as $teacher){
                         $html .= Display::tag('li', Display::return_icon('teacher.png', $teacher, null, ICON_SIZE_TINY) . ' ' . $teacher);
@@ -2063,14 +2062,14 @@ class CourseManager
                 $course_coachs[] = $coach_name;
             }
         }
-        $coaches_to_string = null;
 
+        $coaches_to_string = '';
         if (!empty($course_coachs)) {
-            if ($orderList === true){
+            if ($orderList === true) {
                 $html .= '<ul class="user-coachs">';
-                    foreach ($course_coachs as $coachs){
-                        $html .= Display::tag('li', Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs);
-                    }
+                foreach ($course_coachs as $coachs) {
+                    $html .= Display::tag('li', Display::return_icon('teacher.png', $coachs, null, ICON_SIZE_TINY) . ' ' . $coachs);
+                }
                 $html .= '</ul>';
             } else {
                 $coaches_to_string = array_to_string($course_coachs, $separator);
@@ -2093,7 +2092,6 @@ class CourseManager
     public static function get_real_and_linked_user_list($course_code, $with_sessions = true, $session_id = 0)
     {
         $complete_user_list = array();
-
         //get users from real course
         $user_list = self::get_user_list_from_course_code($course_code, $session_id);
         foreach ($user_list as $this_user) {
@@ -4251,7 +4249,7 @@ class CourseManager
             $wanted_code = CourseManager::generate_course_code($wanted_code);
             $table = Database::get_main_table(TABLE_MAIN_COURSE);
             $wanted_code = Database::escape_string($wanted_code);
-            $sql = "SELECT count(*) as count
+            $sql = "SELECT count(id) as count
                     FROM $table
                     WHERE code LIKE '$wanted_code%'";
             $result = Database::query($sql);

+ 18 - 15
main/inc/lib/tracking.lib.php

@@ -2712,9 +2712,9 @@ class Tracking
      * This function does not take the results of a Test out of a LP
      *
      * @param   int|array   Array of user ids or an user id
-     * @param   string      Course code
-     * @param   array       List of LP ids
-     * @param   int         Session id (optional), if param $session_id is null(default)
+     * @param   string      $course_code Course code
+     * @param   array       $lp_ids List of LP ids
+     * @param   int         $session_id Session id (optional), if param $session_id is 0(default)
      * it'll return results including sessions, 0 = session is not filtered
      * @param   bool        Returns an array of the type [sum_score, num_score] if set to true
      * @param   bool        get only the latest attempts or ALL attempts
@@ -2722,9 +2722,9 @@ class Tracking
      */
     public static function getAverageStudentScore(
         $student_id,
-        $course_code = null,
+        $course_code = '',
         $lp_ids = array(),
-        $session_id = null
+        $session_id = 0
     ) {
         if (empty($student_id)) {
             return 0;
@@ -2764,9 +2764,9 @@ class Tracking
         }
 
         $conditionsToString = implode('AND ', $conditions);
-        $sql = "SELECT  SUM(lp_iv.score) sum_score,
-                        SUM(lp_i.max_score) sum_max_score,
-                        count(*) as count
+        $sql = "SELECT  
+                    SUM(lp_iv.score) sum_score,
+                    SUM(lp_i.max_score) sum_max_score
                 FROM $lp_table as lp
                 INNER JOIN $lp_item_table as lp_i
                 ON lp.id = lp_id AND lp.c_id = lp_i.c_id
@@ -2776,7 +2776,7 @@ class Tracking
                 ON lp_i.id = lp_iv.lp_item_id AND lp_view.c_id = lp_iv.c_id AND lp_iv.lp_view_id = lp_view.id
                 WHERE (lp_i.item_type='sco' OR lp_i.item_type='".TOOL_QUIZ."') AND
                 $conditionsToString
-                ";
+        ";
         $result = Database::query($sql);
         $row = Database::fetch_array($result, 'ASSOC');
 
@@ -2784,7 +2784,7 @@ class Tracking
             return 0;
         }
 
-        return ($row['sum_score'] / $row['sum_max_score'])*100;
+        return ($row['sum_score'] / $row['sum_max_score']) * 100;
 
     }
 
@@ -4017,7 +4017,7 @@ class Tracking
      * BUT NO ROW MATCH THE CONDITION, IT SHOULD BE FINE TO USE IT WHEN YOU USE USER DEFINED DATES AND NO CHAMILO DATES
      * @param   int     User Id
      * @param   int     Course Id
-     * @param   int     Session Id (optional), if param $session_id is null(default) it'll return results including sessions, 0 = session is not filtered
+     * @param   int     Session Id (optional), if param $session_id is 0 (default) it'll return results including sessions, 0 = session is not filtered
      * @param   string  Date from
      * @param   string  Date to
      * @return  array   Data
@@ -4146,7 +4146,7 @@ class Tracking
      * @param    int        Limit (optional, default = 0, 0 = without limit)
      * @return    array     documents downloaded
      */
-    public static function get_documents_most_downloaded_by_course($course_code, $session_id = null, $limit = 0)
+    public static function get_documents_most_downloaded_by_course($course_code, $session_id = 0, $limit = 0)
     {
         //protect data
         $courseId = api_get_course_int_id($course_code);
@@ -4154,11 +4154,14 @@ class Tracking
 
         $TABLETRACK_DOWNLOADS   = Database::get_main_table(TABLE_STATISTIC_TRACK_E_DOWNLOADS);
         $condition_session = '';
-        if (isset($session_id)) {
-            $session_id = intval($session_id);
+        $session_id = intval($session_id);
+        if (!empty($session_id)) {
             $condition_session = ' AND down_session_id = '. $session_id;
         }
-        $sql = "SELECT down_doc_path, COUNT(DISTINCT down_user_id), COUNT(down_doc_path) as count_down
+        $sql = "SELECT 
+                    down_doc_path, 
+                    COUNT(DISTINCT down_user_id), 
+                    COUNT(down_doc_path) as count_down
                 FROM $TABLETRACK_DOWNLOADS
                 WHERE c_id = $courseId
                     $condition_session