Browse Source

Add best score not in LP column see BT#13439

jmontoyaa 7 years ago
parent
commit
cbf0ed71fa
3 changed files with 114 additions and 27 deletions
  1. 10 3
      main/inc/lib/events.lib.php
  2. 30 0
      main/inc/lib/exercise.lib.php
  3. 74 24
      main/inc/lib/tracking.lib.php

+ 10 - 3
main/inc/lib/events.lib.php

@@ -1469,13 +1469,15 @@ class Event
      * @param   int     $exercise_id
      * @param   int     $courseId
      * @param   int     $session_id
+     * @param int $userId
      * @return  array   with the results
      * @todo rename this function
      */
     public static function get_best_exercise_results_by_user(
         $exercise_id,
         $courseId,
-        $session_id = 0
+        $session_id = 0,
+        $userId = 0
     ) {
         $table_track_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
         $table_track_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
@@ -1490,8 +1492,13 @@ class Event
                     exe_exo_id = '$exercise_id' AND
                     session_id = $session_id AND
                     orig_lp_id = 0 AND
-                    orig_lp_item_id = 0
-                ORDER BY exe_id";
+                    orig_lp_item_id = 0";
+
+        if (!empty($userId)) {
+            $userId = (int) $userId;
+            $sql .= " AND exe_user_id = $userId ";
+        }
+        $sql .= " ORDER BY exe_id";
 
         $res = Database::query($sql);
         $list = array();

+ 30 - 0
main/inc/lib/exercise.lib.php

@@ -3189,6 +3189,36 @@ EOT;
         return $avg_score;
     }
 
+    /**
+     * Get average score by score (NO Exercises in LPs )
+     * @param    int        exercise id
+     * @param    int $courseId
+     * @param    int        session id
+     * @return    float    Best average score
+     */
+    public static function getBestScoreByExercise(
+        $exercise_id,
+        $courseId,
+        $session_id
+    ) {
+        $user_results = Event::get_best_exercise_results_by_user(
+            $exercise_id,
+            $courseId,
+            $session_id
+        );
+        $avg_score = 0;
+        if (!empty($user_results)) {
+            foreach ($user_results as $result) {
+                if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) {
+                    $score = $result['exe_result'] / $result['exe_weighting'];
+                    $avg_score += $score;
+                }
+            }
+        }
+
+        return $avg_score;
+    }
+
     /**
      * @param string $course_code
      * @param int $session_id

+ 74 - 24
main/inc/lib/tracking.lib.php

@@ -4587,7 +4587,8 @@ class Tracking
                           '.Display::tag('th', get_lang('Course'), array('width'=>'300px')).'
                           '.Display::tag('th', get_lang('TimeSpentInTheCourse')).'
                           '.Display::tag('th', get_lang('Progress')).'
-                          '.Display::tag('th', get_lang('BestScore')).'
+                          '.Display::tag('th', get_lang('BestScoreInLearningPath')).'
+                          '.Display::tag('th', get_lang('BestScoreNotInLearningPath')).'
                           '.Display::tag('th', get_lang('LastConnexion')).'
                           '.Display::tag('th', get_lang('Details')).'
                         </tr>';
@@ -4616,6 +4617,39 @@ class Tracking
                         true
                     );
 
+                    $exerciseList = ExerciseLib::get_all_exercises(
+                        $courseInfo,
+                        0,
+                        false,
+                        null,
+                        false,
+                        1
+                    );
+
+                    $bestScoreAverageNotInLP = 0;
+                    if (!empty($exerciseList)) {
+                        foreach ($exerciseList as $exerciseData) {
+                            $results = Event::get_best_exercise_results_by_user(
+                                $exerciseData['id'],
+                                $courseInfo['real_id'],
+                                0,
+                                $user_id
+                            );
+                            $best = 0;
+                            if (!empty($results)) {
+                                foreach ($results as $result) {
+                                    $score = $result['exe_result'] / $result['exe_weighting'];
+                                    if ($score > $best) {
+                                        $best = $score;
+                                    }
+                                }
+                            }
+                            $bestScoreAverageNotInLP += $best;
+                        }
+
+                        $bestScoreAverageNotInLP = round($bestScoreAverageNotInLP / count($exerciseList) * 100, 2);
+                    }
+
                     $last_connection = self::get_last_connection_date_on_the_course(
                         $user_id,
                         $courseInfo
@@ -4636,11 +4670,12 @@ class Tracking
                         $html .= '<tr class="row_even">';
                     }
                     $url = api_get_course_url($course_code, $session_id);
-                    $course_url = Display::url($course_title, $url, array('target'=>SESSION_LINK_TARGET));
+                    $course_url = Display::url($course_title, $url, array('target' => SESSION_LINK_TARGET));
                     $html .= '<td>'.$course_url.'</td>';
-                    $html .= '<td align="center">'.$time.'</td>';
-                    $html .= '<td align="center">'.$progress.'</td>';
-                    $html .= '<td align="center">';
+                    $html .= '<td>'.$time.'</td>';
+                    $html .= '<td>'.$progress.'</td>';
+                    $html .= '<td>';
+
                     if (empty($bestScore)) {
                         $html .= '-';
                     } else {
@@ -4648,8 +4683,20 @@ class Tracking
                     }
 
                     $html .= '</td>';
-                    $html .= '<td align="center">'.$last_connection.'</td>';
-                    $html .= '<td align="center">';
+
+
+                    $html .= '<td>';
+
+                    if (empty($bestScoreAverageNotInLP)) {
+                        $html .= '-';
+                    } else {
+                        $html .= $bestScoreAverageNotInLP.'%';
+                    }
+
+                    $html .= '</td>';
+
+                    $html .= '<td>'.$last_connection.'</td>';
+                    $html .= '<td>';
                     if (isset($_GET['course']) &&
                         $course_code == $_GET['course'] &&
                         empty($_GET['session_id'])
@@ -4926,7 +4973,12 @@ class Tracking
                         get_lang('LPProgress'),
                     ],
                     'score'  => [
-                        get_lang('Score').Display::return_icon('info3.gif', get_lang('ScormAndLPTestTotalAverage'), array('align' => 'absmiddle', 'hspace' => '3px')),
+                        get_lang('Score').
+                        Display::return_icon(
+                            'info3.gif',
+                            get_lang('ScormAndLPTestTotalAverage'),
+                            array('align' => 'absmiddle', 'hspace' => '3px')
+                        ),
                     ],
                     'best_score'  => [
                         get_lang('BestScore'),
@@ -5325,25 +5377,25 @@ class Tracking
                             );
                         }
 
-                        $html .= Display::tag('td', $attempts, array('align'=>'center'));
-                        $html .= Display::tag('td', $percentage_score_result, array('align'=>'center'));
-                        $html .= Display::tag('td', $position, array('align'=>'center'));
-                        $html .= Display::tag('td', $best_score, array('align'=>'center'));
-                        $html .= Display::tag('td', $graph, array('align'=>'center'));
+                        $html .= Display::tag('td', $attempts);
+                        $html .= Display::tag('td', $percentage_score_result);
+                        $html .= Display::tag('td', $position);
+                        $html .= Display::tag('td', $best_score);
+                        $html .= Display::tag('td', $graph);
                         //$html .= Display::tag('td', $latest_attempt_url,       array('align'=>'center', 'width'=>'25'));
 
                     } else {
                         // Exercise configuration NO results
-                        $html .= Display::tag('td', $attempts, array('align'=>'center'));
-                        $html .= Display::tag('td', '-', array('align'=>'center'));
-                        $html .= Display::tag('td', '-', array('align'=>'center'));
-                        $html .= Display::tag('td', '-', array('align'=>'center'));
-                        $html .= Display::tag('td', '-', array('align'=>'center'));
+                        $html .= Display::tag('td', $attempts);
+                        $html .= Display::tag('td', '-');
+                        $html .= Display::tag('td', '-');
+                        $html .= Display::tag('td', '-');
+                        $html .= Display::tag('td', '-');
                     }
                     $html .= '</tr>';
                 }
             } else {
-                $html .= '<tr><td colspan="5" align="center">'.get_lang('NoEx').'</td></tr>';
+                $html .= '<tr><td colspan="5">'.get_lang('NoEx').'</td></tr>';
             }
             $html .= '</tbody></table></div>';
 
@@ -5478,16 +5530,14 @@ class Tracking
                     if (in_array('time', $columnHeadersKeys)) {
                         $html .= Display::tag(
                             'td',
-                            $time_spent_in_lp,
-                            array('align' => 'center')
+                            $time_spent_in_lp
                         );
                     }
 
                     if (in_array('progress', $columnHeadersKeys)) {
                         $html .= Display::tag(
                             'td',
-                            $progress,
-                            array('align' => 'center')
+                            $progress
                         );
                     }
 
@@ -5499,7 +5549,7 @@ class Tracking
                     }
 
                     if (in_array('last_connection', $columnHeadersKeys)) {
-                        $html .= Display::tag('td', $last_connection, array('align'=>'center', 'width'=>'180px'));
+                        $html .= Display::tag('td', $last_connection, array('width'=>'180px'));
                     }
                     $html .= '</tr>';
                 }