Ejemplo n.º 1
0
 /**
  * @param int $user_id
  * @param array $courseInfo
  * @param int $session_id
  * @param string $origin
  * @param bool $export_csv
  * @param int $lp_id
  * @param int $lp_item_id
  * @param int $extendId
  * @param int $extendAttemptId
  * @param string $extendedAttempt
  * @param string $extendedAll
  * @param string $type classic or simple
  * @param boolean $allowExtend Optional. Allow or not extend te results
  * @return null|string
  */
 public static function getLpStats($user_id, $courseInfo, $session_id, $origin, $export_csv, $lp_id, $lp_item_id = null, $extendId = null, $extendAttemptId = null, $extendedAttempt = null, $extendedAll = null, $type = 'classic', $allowExtend = true)
 {
     if (empty($courseInfo) || empty($lp_id)) {
         return null;
     }
     $lp_id = intval($lp_id);
     $lp_item_id = intval($lp_item_id);
     $user_id = intval($user_id);
     $session_id = intval($session_id);
     $origin = Security::remove_XSS($origin);
     $list = learnpath::get_flat_ordered_items_list($lp_id, 0, $courseInfo['real_id']);
     $is_allowed_to_edit = api_is_allowed_to_edit(null, true);
     $course_id = $courseInfo['real_id'];
     $courseCode = $courseInfo['code'];
     $session_condition = api_get_session_condition($session_id);
     // Extend all button
     $output = null;
     $extend_all = 0;
     if ($origin == 'tracking') {
         $url_suffix = '&session_id=' . $session_id . '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . $lp_id . '&origin=' . $origin;
     } else {
         $url_suffix = '&lp_id=' . $lp_id;
     }
     if (!empty($extendedAll)) {
         $extend_all_link = Display::url(Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')), api_get_self() . '?action=stats' . $url_suffix);
         $extend_all = 1;
     } else {
         $extend_all_link = Display::url(Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttempts')), api_get_self() . '?action=stats&extend_all=1' . $url_suffix);
     }
     if ($origin != 'tracking') {
         $output .= '<div class="section-status">';
         $output .= Display::page_header(get_lang('ScormMystatus'));
         $output .= '</div>';
     }
     $actionColumn = null;
     if ($type == 'classic') {
         $actionColumn = ' <th>' . get_lang('Actions') . '</th>';
     }
     $output .= '<div class="table-responsive">';
     $output .= '<table class="table tracking">
         <thead>
         <tr class="table-header">
             <th width="16">' . ($allowExtend == true ? $extend_all_link : '&nbsp;') . '</th>
             <th colspan="4">
                 ' . get_lang('ScormLessonTitle') . '
             </th>
             <th colspan="2">
                 ' . get_lang('ScormStatus') . '
             </th>
             <th colspan="2">
                 ' . get_lang('ScormScore') . '
             </th>
             <th colspan="2">
                 ' . get_lang('ScormTime') . '
             </th>
             ' . $actionColumn . '
             </tr>
         </thead>
         <tbody>
     ';
     // Going through the items using the $items[] array instead of the database order ensures
     // we get them in the same order as in the imsmanifest file, which is rather random when using
     // the database table.
     $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
     $TBL_LP_ITEM_VIEW = Database::get_course_table(TABLE_LP_ITEM_VIEW);
     $TBL_LP_VIEW = Database::get_course_table(TABLE_LP_VIEW);
     $tbl_quiz_questions = Database::get_course_table(TABLE_QUIZ_QUESTION);
     $TBL_QUIZ = Database::get_course_table(TABLE_QUIZ_TEST);
     $tbl_stats_exercices = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
     $tbl_stats_attempts = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
     $sql = "SELECT max(view_count)\n                FROM {$TBL_LP_VIEW}\n                WHERE\n                    c_id = {$course_id} AND\n                    lp_id = {$lp_id} AND\n                    user_id = {$user_id}\n                    {$session_condition}";
     $res = Database::query($sql);
     $view = '';
     if (Database::num_rows($res) > 0) {
         $myrow = Database::fetch_array($res);
         $view = $myrow[0];
     }
     $counter = 0;
     $total_time = 0;
     $h = get_lang('h');
     if (!empty($export_csv)) {
         $csv_content[] = array(get_lang('ScormLessonTitle'), get_lang('ScormStatus'), get_lang('ScormScore'), get_lang('ScormTime'));
     }
     $result_disabled_ext_all = true;
     $chapterTypes = learnpath::getChapterTypes();
     // Show lp items
     if (is_array($list) && count($list) > 0) {
         foreach ($list as $my_item_id) {
             $extend_this = 0;
             $order = 'DESC';
             if (!empty($extendId) && $extendId == $my_item_id || $extend_all) {
                 $extend_this = 1;
                 $order = 'ASC';
             }
             // Prepare statement to go through each attempt.
             $viewCondition = null;
             if (!empty($view)) {
                 $viewCondition = " AND v.view_count = {$view}  ";
             }
             $sql = "SELECT\n                    iv.status as mystatus,\n                    v.view_count as mycount,\n                    iv.score as myscore,\n                    iv.total_time as mytime,\n                    i.id as myid,\n                    i.lp_id as mylpid,\n                    iv.lp_view_id as mylpviewid,\n                    i.title as mytitle,\n                    i.max_score as mymaxscore,\n                    iv.max_score as myviewmaxscore,\n                    i.item_type as item_type,\n                    iv.view_count as iv_view_count,\n                    iv.id as iv_id,\n                    path\n                FROM {$TBL_LP_ITEM} as i\n                INNER JOIN {$TBL_LP_ITEM_VIEW} as iv\n                ON (i.id = iv.lp_item_id AND i.c_id = iv.c_id)\n                INNER JOIN {$TBL_LP_VIEW} as v\n                ON (iv.lp_view_id = v.id AND v.c_id = iv.c_id)\n                WHERE\n                    v.c_id = {$course_id} AND\n                    i.id = {$my_item_id} AND\n                    i.lp_id = {$lp_id}  AND\n                    v.user_id = {$user_id} AND\n                    v.session_id = {$session_id}\n                    {$viewCondition}\n                ORDER BY iv.view_count {$order} ";
             $result = Database::query($sql);
             $num = Database::num_rows($result);
             $time_for_total = 'NaN';
             // Extend all
             if (($extend_this || $extend_all) && $num > 0) {
                 $row = Database::fetch_array($result);
                 $result_disabled_ext_all = false;
                 if ($row['item_type'] == 'quiz') {
                     // Check results_disabled in quiz table.
                     $my_path = Database::escape_string($row['path']);
                     $sql = "SELECT results_disabled\n                                FROM {$TBL_QUIZ}\n                                WHERE\n                                    c_id = {$course_id} AND\n                                    id ='" . $my_path . "'";
                     $res_result_disabled = Database::query($sql);
                     $row_result_disabled = Database::fetch_row($res_result_disabled);
                     if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
                         $result_disabled_ext_all = true;
                     }
                 }
                 // If there are several attempts, and the link to extend has been clicked, show each attempt...
                 if ($counter % 2 == 0) {
                     $oddclass = 'row_odd';
                 } else {
                     $oddclass = 'row_even';
                 }
                 $extend_link = '';
                 if (!empty($inter_num)) {
                     $extend_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&fold_id=' . $my_item_id . $url_suffix);
                 }
                 $title = $row['mytitle'];
                 if (empty($title)) {
                     $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']);
                 }
                 if (in_array($row['item_type'], $chapterTypes)) {
                     $title = "<h4> {$title} </h4>";
                 }
                 $lesson_status = $row['mystatus'];
                 $title = Security::remove_XSS($title);
                 $counter++;
                 $action = null;
                 if ($type == 'classic') {
                     $action = '<td></td>';
                 }
                 if (in_array($row['item_type'], $chapterTypes)) {
                     $output .= '<tr class="' . $oddclass . '">
                             <td>' . $extend_link . '</td>
                             <td colspan="4">
                                ' . $title . '
                             </td>
                             <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             ' . $action . '
                         </tr>';
                     continue;
                 } else {
                     $output .= '<tr class="' . $oddclass . '">
                             <td>' . $extend_link . '</td>
                             <td colspan="4">
                                ' . $title . '
                             </td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             ' . $action . '
                         </tr>';
                 }
                 $attemptCount = 1;
                 do {
                     // Check if there are interactions below.
                     $extend_attempt_link = '';
                     $extend_this_attempt = 0;
                     if ((learnpath::get_interactions_count_from_db($row['iv_id'], $course_id) > 0 || learnpath::get_objectives_count_from_db($row['iv_id'], $course_id) > 0) && !$extend_all) {
                         if ($extendAttemptId == $row['iv_id']) {
                             // The extend button for this attempt has been clicked.
                             $extend_this_attempt = 1;
                             $extend_attempt_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix);
                         } else {
                             // Same case if fold_attempt_id is set, so not implemented explicitly.
                             // The extend button for this attempt has not been clicked.
                             $extend_attempt_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix);
                         }
                     }
                     if ($counter % 2 == 0) {
                         $oddclass = 'row_odd';
                     } else {
                         $oddclass = 'row_even';
                     }
                     $lesson_status = $row['mystatus'];
                     $score = $row['myscore'];
                     $time_for_total = $row['mytime'];
                     $time = learnpathItem::getScormTimeFromParameter('js', $row['mytime']);
                     if ($score == 0) {
                         $maxscore = $row['mymaxscore'];
                     } else {
                         if ($row['item_type'] == 'sco') {
                             if (!empty($row['myviewmaxscore']) && $row['myviewmaxscore'] > 0) {
                                 $maxscore = $row['myviewmaxscore'];
                             } elseif ($row['myviewmaxscore'] === '') {
                                 $maxscore = 0;
                             } else {
                                 $maxscore = $row['mymaxscore'];
                             }
                         } else {
                             $maxscore = $row['mymaxscore'];
                         }
                     }
                     // Remove "NaN" if any (@todo: locate the source of these NaN)
                     $time = str_replace('NaN', '00' . $h . '00\'00"', $time);
                     if ($row['item_type'] != 'dokeos_chapter') {
                         if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                             $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                         } else {
                             switch ($row['item_type']) {
                                 case 'sco':
                                     if ($maxscore == 0) {
                                         $view_score = $score;
                                     } else {
                                         $view_score = ExerciseLib::show_score($score, $maxscore, false);
                                     }
                                     break;
                                 case 'document':
                                     $view_score = $score == 0 ? '/' : ExerciseLib::show_score($score, $maxscore, false);
                                     break;
                                 default:
                                     $view_score = ExerciseLib::show_score($score, $maxscore, false);
                                     break;
                             }
                         }
                         $action = null;
                         if ($type == 'classic') {
                             $action = '<td></td>';
                         }
                         $output .= '<tr class="' . $oddclass . '">
                                 <td></td>
                                 <td>' . $extend_attempt_link . '</td>
                                 <td colspan="3">' . get_lang('Attempt') . ' ' . $attemptCount . '</td>
                                 <td colspan="2">' . learnpathItem::humanize_status($lesson_status, true, $type) . '</td>
                                 <td colspan="2">' . $view_score . '</td>
                                 <td colspan="2">' . $time . '</td>
                                 ' . $action . '
                             </tr>';
                         $attemptCount++;
                         if (!empty($export_csv)) {
                             $temp = array();
                             $temp[] = $title = Security::remove_XSS($title);
                             $temp[] = Security::remove_XSS(learnpathItem::humanize_status($lesson_status, false, $type));
                             if ($row['item_type'] == 'quiz') {
                                 if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                     $temp[] = '/';
                                 } else {
                                     $temp[] = $score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                                 }
                             } else {
                                 $temp[] = $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                             }
                             $temp[] = $time;
                             $csv_content[] = $temp;
                         }
                     }
                     $counter++;
                     $action = null;
                     if ($type == 'classic') {
                         $action = '<td></td>';
                     }
                     if ($extend_this_attempt || $extend_all) {
                         $list1 = learnpath::get_iv_interactions_array($row['iv_id']);
                         foreach ($list1 as $id => $interaction) {
                             if ($counter % 2 == 0) {
                                 $oddclass = 'row_odd';
                             } else {
                                 $oddclass = 'row_even';
                             }
                             $student_response = urldecode($interaction['student_response']);
                             $content_student_response = explode('__|', $student_response);
                             if (count($content_student_response) > 0) {
                                 if (count($content_student_response) >= 3) {
                                     // Pop the element off the end of array.
                                     array_pop($content_student_response);
                                 }
                                 $student_response = implode(',', $content_student_response);
                             }
                             $output .= '<tr class="' . $oddclass . '">
                                     <td></td>
                                     <td></td>
                                     <td></td>
                                     <td>' . $interaction['order_id'] . '</td>
                                     <td>' . $interaction['id'] . '</td>
                                     <td colspan="2">' . $interaction['type'] . '</td>
                                     <td>' . $student_response . '</td>
                                     <td>' . $interaction['result'] . '</td>
                                     <td>' . $interaction['latency'] . '</td>
                                     <td>' . $interaction['time'] . '</td>
                                     ' . $action . '
                                 </tr>';
                             $counter++;
                         }
                         $list2 = learnpath::get_iv_objectives_array($row['iv_id']);
                         foreach ($list2 as $id => $interaction) {
                             if ($counter % 2 == 0) {
                                 $oddclass = 'row_odd';
                             } else {
                                 $oddclass = 'row_even';
                             }
                             $output .= '<tr class="' . $oddclass . '">
                                     <td></td>
                                     <td></td>
                                     <td></td>
                                     <td>' . $interaction['order_id'] . '</td>
                                     <td colspan="2">' . $interaction['objective_id'] . '</td>
                                     <td colspan="2">' . $interaction['status'] . '</td>
                                     <td>' . $interaction['score_raw'] . '</td>
                                     <td>' . $interaction['score_max'] . '</td>
                                     <td>' . $interaction['score_min'] . '</td>
                                     ' . $action . '
                                  </tr>';
                             $counter++;
                         }
                     }
                 } while ($row = Database::fetch_array($result));
             } elseif ($num > 0) {
                 // Not extended.
                 $row = Database::fetch_array($result, 'ASSOC');
                 $my_id = $row['myid'];
                 $my_lp_id = $row['mylpid'];
                 $my_lp_view_id = $row['mylpviewid'];
                 $my_path = $row['path'];
                 $result_disabled_ext_all = false;
                 if ($row['item_type'] == 'quiz') {
                     // Check results_disabled in quiz table.
                     $my_path = Database::escape_string($my_path);
                     $sql = "SELECT results_disabled\n                                FROM {$TBL_QUIZ}\n                                WHERE c_id = {$course_id} AND id ='" . $my_path . "'";
                     $res_result_disabled = Database::query($sql);
                     $row_result_disabled = Database::fetch_row($res_result_disabled);
                     if (Database::num_rows($res_result_disabled) > 0 && (int) $row_result_disabled[0] === 1) {
                         $result_disabled_ext_all = true;
                     }
                 }
                 // Check if there are interactions below
                 $extend_this_attempt = 0;
                 $inter_num = learnpath::get_interactions_count_from_db($row['iv_id'], $course_id);
                 $objec_num = learnpath::get_objectives_count_from_db($row['iv_id'], $course_id);
                 $extend_attempt_link = '';
                 if ($inter_num > 0 || $objec_num > 0) {
                     if (!empty($extendAttemptId) && $extendAttemptId == $row['iv_id']) {
                         // The extend button for this attempt has been clicked.
                         $extend_this_attempt = 1;
                         $extend_attempt_link = Display::url(Display::return_icon('visible.gif', get_lang('HideAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&fold_attempt_id=' . $row['iv_id'] . $url_suffix);
                     } else {
                         // Same case if fold_attempt_id is set, so not implemented explicitly.
                         // The extend button for this attempt has not been clicked.
                         $extend_attempt_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix);
                     }
                 }
                 if ($counter % 2 == 0) {
                     $oddclass = 'row_odd';
                 } else {
                     $oddclass = 'row_even';
                 }
                 $extend_link = '';
                 if ($inter_num > 1) {
                     $extend_link = Display::url(Display::return_icon('invisible.gif', get_lang('ExtendAttemptView')), api_get_self() . '?action=stats&extend_id=' . $my_item_id . '&extend_attempt_id=' . $row['iv_id'] . $url_suffix);
                 }
                 $lesson_status = $row['mystatus'];
                 $score = $row['myscore'];
                 $subtotal_time = $row['mytime'];
                 while ($tmp_row = Database::fetch_array($result)) {
                     $subtotal_time += $tmp_row['mytime'];
                 }
                 $title = $row['mytitle'];
                 // Selecting the exe_id from stats attempts tables in order to look the max score value.
                 $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
                          WHERE
                             exe_exo_id="' . $row['path'] . '" AND
                             exe_user_id="' . $user_id . '" AND
                             orig_lp_id = "' . $lp_id . '" AND
                             orig_lp_item_id = "' . $row['myid'] . '" AND
                             c_id = ' . $course_id . ' AND
                             status <> "incomplete" AND
                             session_id = ' . $session_id . '
                          ORDER BY exe_date DESC
                          LIMIT 1';
                 $resultLastAttempt = Database::query($sql);
                 $num = Database::num_rows($resultLastAttempt);
                 $id_last_attempt = null;
                 if ($num > 0) {
                     while ($rowLA = Database::fetch_array($resultLastAttempt)) {
                         $id_last_attempt = $rowLA['exe_id'];
                     }
                 }
                 if ($score == 0) {
                     $maxscore = $row['mymaxscore'];
                 } else {
                     if ($row['item_type'] == 'sco') {
                         if (!empty($row['myviewmaxscore']) and $row['myviewmaxscore'] > 0) {
                             $maxscore = $row['myviewmaxscore'];
                         } elseif ($row['myviewmaxscore'] === '') {
                             $maxscore = 0;
                         } else {
                             $maxscore = $row['mymaxscore'];
                         }
                     } else {
                         if ($row['item_type'] == 'quiz') {
                             // Get score and total time from last attempt of a exercise en lp.
                             $sql = "SELECT score\n                                        FROM {$TBL_LP_ITEM_VIEW}\n                                        WHERE\n                                            c_id = {$course_id} AND\n                                            lp_item_id = '" . (int) $my_id . "' AND\n                                            lp_view_id = '" . (int) $my_lp_view_id . "'\n                                        ORDER BY view_count DESC limit 1";
                             $res_score = Database::query($sql);
                             $row_score = Database::fetch_array($res_score);
                             $sql = "SELECT SUM(total_time) as total_time\n                                        FROM {$TBL_LP_ITEM_VIEW}\n                                        WHERE\n                                            c_id = {$course_id} AND\n                                            lp_item_id = '" . (int) $my_id . "' AND\n                                            lp_view_id = '" . (int) $my_lp_view_id . "'";
                             $res_time = Database::query($sql);
                             $row_time = Database::fetch_array($res_time);
                             if (Database::num_rows($res_score) > 0 && Database::num_rows($res_time) > 0) {
                                 $score = (double) $row_score['score'];
                                 $subtotal_time = (int) $row_time['total_time'];
                             } else {
                                 $score = 0;
                                 $subtotal_time = 0;
                             }
                             // Selecting the max score from an attempt.
                             $sql = "SELECT SUM(t.ponderation) as maxscore\n                                        FROM (\n                                            SELECT DISTINCT\n                                                question_id, marks, ponderation\n                                            FROM {$tbl_stats_attempts} as at\n                                            INNER JOIN  {$tbl_quiz_questions} as q\n                                            ON (q.id = at.question_id AND q.c_id = {$course_id})\n                                            WHERE exe_id ='{$id_last_attempt}'\n                                        ) as t";
                             $result = Database::query($sql);
                             $row_max_score = Database::fetch_array($result);
                             $maxscore = $row_max_score['maxscore'];
                         } else {
                             $maxscore = $row['mymaxscore'];
                         }
                     }
                 }
                 $time_for_total = $subtotal_time;
                 $time = learnpathItem::getScormTimeFromParameter('js', $subtotal_time);
                 if (empty($title)) {
                     $title = rl_get_resource_name($courseInfo['code'], $lp_id, $row['myid']);
                 }
                 $action = null;
                 if ($type == 'classic') {
                     $action = '<td></td>';
                 }
                 if (in_array($row['item_type'], $chapterTypes)) {
                     $title = Security::remove_XSS($title);
                     $output .= '<tr class="' . $oddclass . '">
                             <td>' . $extend_link . '</td>
                             <td colspan="4">
                             <h4>' . $title . '</h4>
                             </td>
                             <td colspan="2">' . learnpathitem::humanize_status($lesson_status) . '</td>
                             <td colspan="2"></td>
                             <td colspan="2"></td>
                             ' . $action . '
                         </tr>';
                 } else {
                     $correct_test_link = '-';
                     if ($row['item_type'] == 'quiz') {
                         $my_url_suffix = '&course=' . $courseCode . '&student_id=' . $user_id . '&lp_id=' . intval($row['mylpid']) . '&origin=' . $origin;
                         $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
                                  WHERE
                                     exe_exo_id="' . $row['path'] . '" AND
                                     exe_user_id="' . $user_id . '" AND
                                     orig_lp_id = "' . $lp_id . '" AND
                                     orig_lp_item_id = "' . $row['myid'] . '" AND
                                     c_id = ' . $course_id . ' AND
                                     status <> "incomplete" AND
                                     session_id = ' . $session_id . '
                                  ORDER BY exe_date DESC ';
                         $resultLastAttempt = Database::query($sql);
                         $num = Database::num_rows($resultLastAttempt);
                         if ($num > 0) {
                             if ($extendedAttempt == 1 && $lp_id == $my_lp_id && $lp_item_id == $my_id) {
                                 $correct_test_link = Display::url(Display::return_icon('view_less_stats.gif', get_lang('HideAllAttempts')), api_get_self() . '?action=stats' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id);
                             } else {
                                 $correct_test_link = Display::url(Display::return_icon('view_more_stats.gif', get_lang('ShowAllAttemptsByExercise')), api_get_self() . '?action=stats&extend_attempt=1' . $my_url_suffix . '&session_id=' . $session_id . '&lp_item_id=' . $my_id);
                             }
                         }
                     }
                     $title = Security::remove_XSS($title);
                     $action = null;
                     if ($type == 'classic') {
                         $action = '<td>' . $correct_test_link . '</td>';
                     }
                     if ($lp_id == $my_lp_id && false) {
                         $output .= '<tr class =' . $oddclass . '>
                                 <td>' . $extend_link . '</td>
                                 <td colspan="4">' . $title . '</td>
                                 <td colspan="2">&nbsp;</td>
                                 <td colspan="2">&nbsp;</td>
                                 <td colspan="2">&nbsp;</td>
                                 ' . $action . '
                             </tr>';
                         $output .= '</tr>';
                     } else {
                         if ($lp_id == $my_lp_id && $lp_item_id == $my_id) {
                             $output .= "<tr class='{$oddclass}'>";
                         } else {
                             $output .= "<tr class='{$oddclass}'>";
                         }
                         $scoreItem = null;
                         if ($row['item_type'] == 'quiz') {
                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                 $scoreItem .= Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                             } else {
                                 $scoreItem .= ExerciseLib::show_score($score, $maxscore, false);
                             }
                         } else {
                             $scoreItem .= $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . $maxscore);
                         }
                         $output .= '
                             <td>' . $extend_link . '</td>
                             <td colspan="4">' . $title . '</td>
                             <td colspan="2">' . learnpathitem::humanize_status($lesson_status) . '</td>
                             <td colspan="2">' . $scoreItem . '</td>
                             <td colspan="2">' . $time . '</td>
                             ' . $action . '
                          ';
                         $output .= '</tr>';
                     }
                     if (!empty($export_csv)) {
                         $temp = array();
                         $temp[] = api_html_entity_decode($title, ENT_QUOTES);
                         $temp[] = api_html_entity_decode($lesson_status, ENT_QUOTES);
                         if ($row['item_type'] == 'quiz') {
                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                 $temp[] = '/';
                             } else {
                                 $temp[] = $score == 0 ? '0/' . $maxscore : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                             }
                         } else {
                             $temp[] = $score == 0 ? '/' : ($maxscore == 0 ? $score : $score . '/' . float_format($maxscore, 1));
                         }
                         $temp[] = $time;
                         $csv_content[] = $temp;
                     }
                 }
                 $counter++;
                 $action = null;
                 if ($type == 'classic') {
                     $action = '<td></td>';
                 }
                 if ($extend_this_attempt || $extend_all) {
                     $list1 = learnpath::get_iv_interactions_array($row['iv_id']);
                     foreach ($list1 as $id => $interaction) {
                         if ($counter % 2 == 0) {
                             $oddclass = 'row_odd';
                         } else {
                             $oddclass = 'row_even';
                         }
                         $output .= '<tr class="' . $oddclass . '">
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td>' . $interaction['order_id'] . '</td>
                                 <td>' . $interaction['id'] . '</td>
                                 <td colspan="2">' . $interaction['type'] . '</td>
                                 <td>' . urldecode($interaction['student_response']) . '</td>
                                 <td>' . $interaction['result'] . '</td>
                                 <td>' . $interaction['latency'] . '</td>
                                 <td>' . $interaction['time'] . '</td>
                                 ' . $action . '
                            </tr>';
                         $counter++;
                     }
                     $list2 = learnpath::get_iv_objectives_array($row['iv_id']);
                     foreach ($list2 as $id => $interaction) {
                         if ($counter % 2 == 0) {
                             $oddclass = 'row_odd';
                         } else {
                             $oddclass = 'row_even';
                         }
                         $output .= '<tr class="' . $oddclass . '">
                                 <td></td>
                                 <td></td>
                                 <td></td>
                                 <td>' . $interaction['order_id'] . '</td>
                                 <td colspan="2">' . $interaction['objective_id'] . '</td>
                                 <td colspan="2">' . $interaction['status'] . '</td>
                                 <td>' . $interaction['score_raw'] . '</td>
                                 <td>' . $interaction['score_max'] . '</td>
                                 <td>' . $interaction['score_min'] . '</td>
                                 ' . $action . '
                            </tr>';
                         $counter++;
                     }
                 }
                 // Attempts listing by exercise.
                 if ($lp_id == $my_lp_id && $lp_item_id == $my_id && $extendedAttempt) {
                     // Get attempts of a exercise.
                     if (!empty($lp_id) && !empty($lp_item_id) && $row['item_type'] === 'quiz') {
                         $sql = "SELECT path FROM {$TBL_LP_ITEM}\n                                    WHERE\n                                        c_id = {$course_id} AND\n                                        id = '{$lp_item_id}' AND\n                                        lp_id = '{$lp_id}'";
                         $res_path = Database::query($sql);
                         $row_path = Database::fetch_array($res_path);
                         if (Database::num_rows($res_path) > 0) {
                             $sql = 'SELECT * FROM ' . $tbl_stats_exercices . '
                                     WHERE
                                         exe_exo_id="' . (int) $row_path['path'] . '" AND
                                         status <> "incomplete" AND
                                         exe_user_id="' . $user_id . '" AND
                                         orig_lp_id = "' . (int) $lp_id . '" AND
                                         orig_lp_item_id = "' . (int) $lp_item_id . '" AND
                                         c_id = ' . $course_id . '  AND
                                         session_id = ' . $session_id . '
                                     ORDER BY exe_date';
                             $res_attempts = Database::query($sql);
                             $num_attempts = Database::num_rows($res_attempts);
                             if ($num_attempts > 0) {
                                 $n = 1;
                                 while ($row_attempts = Database::fetch_array($res_attempts)) {
                                     $my_score = $row_attempts['exe_result'];
                                     $my_maxscore = $row_attempts['exe_weighting'];
                                     $my_exe_id = $row_attempts['exe_id'];
                                     $my_orig_lp = $row_attempts['orig_lp_id'];
                                     $my_orig_lp_item = $row_attempts['orig_lp_item_id'];
                                     $my_exo_exe_id = $row_attempts['exe_exo_id'];
                                     $mktime_start_date = api_strtotime($row_attempts['start_date'], 'UTC');
                                     $mktime_exe_date = api_strtotime($row_attempts['exe_date'], 'UTC');
                                     if ($mktime_start_date && $mktime_exe_date) {
                                         $mytime = (int) $mktime_exe_date - (int) $mktime_start_date;
                                         $time_attemp = learnpathItem::getScormTimeFromParameter('js', $mytime);
                                         $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
                                     } else {
                                         $time_attemp = ' - ';
                                     }
                                     if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                         $view_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
                                     } else {
                                         // Show only float when need it
                                         if ($my_score == 0) {
                                             $view_score = ExerciseLib::show_score(0, $my_maxscore, false);
                                         } else {
                                             if ($my_maxscore == 0) {
                                                 $view_score = $my_score;
                                             } else {
                                                 $view_score = ExerciseLib::show_score($my_score, $my_maxscore, false);
                                             }
                                         }
                                     }
                                     $my_lesson_status = $row_attempts['status'];
                                     if ($my_lesson_status == '') {
                                         $my_lesson_status = learnpathitem::humanize_status('completed');
                                     } elseif ($my_lesson_status == 'incomplete') {
                                         $my_lesson_status = learnpathitem::humanize_status('incomplete');
                                     }
                                     $output .= '<tr class="' . $oddclass . '" >
                                     <td></td>
                                     <td>' . $extend_attempt_link . '</td>
                                     <td colspan="3">' . get_lang('Attempt') . ' ' . $n . '</td>
                                     <td colspan="2">' . $my_lesson_status . '</td>
                                     <td colspan="2">' . $view_score . '</td>
                                     <td colspan="2">' . $time_attemp . '</td>';
                                     if ($action == 'classic') {
                                         if ($origin != 'tracking') {
                                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                                 $output .= '<td>
                                                         <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '">
                                                         </td>';
                                             } else {
                                                 $output .= '<td>
                                                         <a href="../exercice/exercise_show.php?origin=' . $origin . '&id=' . $my_exe_id . '&cidReq=' . $courseCode . '" target="_parent">
                                                         <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '">
                                                         </a></td>';
                                             }
                                         } else {
                                             if (!$is_allowed_to_edit && $result_disabled_ext_all) {
                                                 $output .= '<td>
                                                             <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></td>';
                                             } else {
                                                 $output .= '<td>
                                                                 <a href="../exercice/exercise_show.php?cidReq=' . $courseCode . '&origin=correct_exercise_in_lp&id=' . $my_exe_id . '" target="_parent">
                                                                 <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAndQualifyAttempt') . '" title="' . get_lang('ShowAndQualifyAttempt') . '"></a></td>';
                                             }
                                         }
                                     }
                                     $output .= '</tr>';
                                     $n++;
                                 }
                             }
                             $output .= '<tr><td colspan="12">&nbsp;</td></tr>';
                         }
                     }
                 }
             }
             $total_time += $time_for_total;
             // QUIZZ IN LP
             $a_my_id = array();
             if (!empty($my_lp_id)) {
                 $a_my_id[] = $my_lp_id;
             }
         }
     }
     // NOT Extend all "left green cross"
     if (!empty($a_my_id)) {
         if ($extendedAttempt) {
             // "Right green cross" extended
             $total_score = self::get_avg_student_score($user_id, $course_id, $a_my_id, $session_id, false, false);
         } else {
             // "Left green cross" extended
             $total_score = self::get_avg_student_score($user_id, $course_id, $a_my_id, $session_id, false, true);
         }
     } else {
         // Extend all "left green cross"
         $total_score = self::get_avg_student_score($user_id, $course_id, array($lp_id), $session_id, false, false);
     }
     $total_time = learnpathItem::getScormTimeFromParameter('js', $total_time);
     $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
     if (!$is_allowed_to_edit && $result_disabled_ext_all) {
         $final_score = Display::return_icon('invisible.gif', get_lang('ResultsHiddenByExerciseSetting'));
     } else {
         if (is_numeric($total_score)) {
             $final_score = $total_score . '%';
         } else {
             $final_score = $total_score;
         }
     }
     $progress = learnpath::getProgress($lp_id, $user_id, $course_id, $session_id);
     if ($counter % 2 == 0) {
         $oddclass = 'row_odd';
     } else {
         $oddclass = 'row_even';
     }
     $action = null;
     if ($type == 'classic') {
         $action = '<td></td>';
     }
     $output .= '<tr class="' . $oddclass . '">
             <td></td>
             <td colspan="4">
                 <i>' . get_lang('AccomplishedStepsTotal') . '</i>
             </td>
             <td colspan="2">' . $progress . '%</td>
             <td colspan="2">
                 ' . $final_score . '
             </td>
             <td colspan="2">' . $total_time . '</div>
             ' . $action . '
        </tr>';
     $output .= '
                 </tbody>
             </table>
         </div>
     ';
     if (!empty($export_csv)) {
         $temp = array('', '', '', '');
         $csv_content[] = $temp;
         $temp = array(get_lang('AccomplishedStepsTotal'), '', $final_score, $total_time);
         $csv_content[] = $temp;
         ob_end_clean();
         Export::arrayToCsv($csv_content, 'reporting_learning_path_details');
         exit;
     }
     return $output;
 }
Ejemplo n.º 2
0
     // Show only float when need it
     if ($my_score == 0) {
         $view_score = ExerciseLib::show_score(0, $my_maxscore, false);
     } else {
         if ($my_maxscore == 0) {
             $view_score = $my_score;
         } else {
             $view_score = ExerciseLib::show_score($my_score, $my_maxscore, false);
         }
     }
 }
 $my_lesson_status = $row_attempts['status'];
 if ($my_lesson_status == '') {
     $my_lesson_status = learnpathitem::humanize_status('completed');
 } elseif ($my_lesson_status == 'incomplete') {
     $my_lesson_status = learnpathitem::humanize_status('incomplete');
 }
 $output .= '<tr class="' . $oddclass . '" >
                 <td></td>
                 <td>' . $extend_attempt_link . '</td>
                 <td colspan="3">' . get_lang('Attempt') . ' ' . $n . '</td>
                 <td colspan="2">' . $my_lesson_status . '</td>
                 <td colspan="2">' . $view_score . '</td>
                 <td colspan="2">' . $time_attemp . '</td>';
 if ($origin != 'tracking') {
     if (!$is_allowed_to_edit && $result_disabled_ext_all) {
         $output .= '<td><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz_na.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></td>';
     } else {
         $output .= '<td><a href="../exercice/exercise_show.php?origin=' . $origin . '&id=' . $my_exe_id . '&cidReq=' . $course_code . $from_link . '" target="_parent">
                         <img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif" alt="' . get_lang('ShowAttempt') . '" title="' . get_lang('ShowAttempt') . '"></a></td>';
     }