/** * Gets the position of the score based in a given score (result/weight) * and the exe_id based in the user list * (NO Exercises in LPs ) * @param float $my_score user score to be compared *attention* * $my_score = score/weight and not just the score * @param int $my_exe_id exe id of the exercise * (this is necessary because if 2 students have the same score the one * with the minor exe_id will have a best position, just to be fair and FIFO) * @param int $exercise_id * @param string $course_code * @param int $session_id * @param array $user_list * @param bool $return_string * * @return int the position of the user between his friends in a course * (or course within a session) */ function get_exercise_result_ranking($my_score, $my_exe_id, $exercise_id, $course_code, $session_id = 0, $user_list = array(), $return_string = true) { //No score given we return if (is_null($my_score)) { return '-'; } if (empty($user_list)) { return '-'; } $best_attempts = array(); foreach ($user_list as $user_data) { $user_id = $user_data['user_id']; $best_attempts[$user_id] = get_best_attempt_by_user($user_id, $exercise_id, $course_code, $session_id); } if (empty($best_attempts)) { return 1; } else { $position = 1; $my_ranking = array(); foreach ($best_attempts as $user_id => $result) { if (!empty($result['exe_weighting']) && intval($result['exe_weighting']) != 0) { $my_ranking[$user_id] = $result['exe_result'] / $result['exe_weighting']; } else { $my_ranking[$user_id] = 0; } } //if (!empty($my_ranking)) { asort($my_ranking); $position = count($my_ranking); if (!empty($my_ranking)) { foreach ($my_ranking as $user_id => $ranking) { if ($my_score >= $ranking) { if ($my_score == $ranking) { $exe_id = $best_attempts[$user_id]['exe_id']; if ($my_exe_id < $exe_id) { $position--; } } else { $position--; } } } } //} $return_value = array('position' => $position, 'count' => count($my_ranking)); if ($return_string) { if (!empty($position) && !empty($my_ranking)) { $return_value = $position . '/' . count($my_ranking); } else { $return_value = '-'; } } return $return_value; } }
/** * Shows the user detail progress (when clicking in the details link) * @param int user id * @param string course code * @param int session id * @return string html code */ static function show_course_detail($user_id, $course_code, $session_id) { $html = ''; if (isset($course_code)) { $user_id = intval($user_id); $session_id = intval($session_id); $course = Database::escape_string($course_code); $course_info = CourseManager::get_course_information($course); //$course_id = $course_info['real_id']; //$session_name = api_get_session_name($session_id); $html .= Display::page_subheader($course_info['title']); $html .= '<table class="data_table" width="100%">'; //Course details $html .= ' <tr> <th class="head" style="color:#000">'.get_lang('Exercices').'</th> <th class="head" style="color:#000">'.get_lang('Attempts').'</th> <th class="head" style="color:#000">'.get_lang('BestAttempt').'</th> <th class="head" style="color:#000">'.get_lang('Ranking').'</th> <th class="head" style="color:#000">'.get_lang('BestResultInCourse').'</th> <th class="head" style="color:#000">'.get_lang('Statistics').' '.Display :: return_icon('info3.gif', get_lang('OnlyBestResultsPerStudent'), array('align' => 'absmiddle', 'hspace' => '3px')).'</th> </tr>'; if (empty($session_id)) { $user_list = CourseManager::get_user_list_from_course_code($course, $session_id, null, null, STUDENT); } else { $user_list = CourseManager::get_user_list_from_course_code($course, $session_id, null, null, 0); } //$exercise_list = get_all_exercises($course_info, $session_id, true); // Show exercise results of invisible exercises? see BT#4091 $exercise_list = get_all_exercises( $course_info, $session_id, false, null, false, 1 ); $to_graph_exercise_result = array(); if (!empty($exercise_list)) { $score = $weighting = $exe_id = 0; foreach ($exercise_list as $exercices) { $exercise_obj = new Exercise($course_info['real_id']); $exercise_obj->read($exercices['id']); $visible_return = $exercise_obj->is_visible(); $score = $weighting = $attempts = 0; //Getting count of attempts by user $attempts = count_exercise_attempts_by_user(api_get_user_id(), $exercices['id'], $course_info['code'], $session_id); $html .= '<tr class="row_even">'; $url = api_get_path(WEB_CODE_PATH)."exercice/overview.php?cidReq={$course_info['code']}&id_session=$session_id&exerciseId={$exercices['id']}"; if ($visible_return['value'] == true) { $exercices['title'] = Display::url($exercices['title'], $url, array('target'=>SESSION_LINK_TARGET)); } $html .= Display::tag('td', $exercices['title']); //Exercise configuration show results or show only score if ($exercices['results_disabled'] == 0 || $exercices['results_disabled'] == 2) { //For graphics $best_exercise_stats = get_best_exercise_results_by_user($exercices['id'], $course_info['code'], $session_id); $to_graph_exercise_result[$exercices['id']] = array('title'=>$exercices['title'], 'data'=>$best_exercise_stats); $latest_attempt_url = ''; $best_score = $position = $percentage_score_result = '-'; $graph = $normal_graph = null; //Getting best results $best_score_data = get_best_attempt_in_course($exercices['id'], $course_info['code'], $session_id); $best_score = show_score($best_score_data['exe_result'], $best_score_data['exe_weighting']); if ($attempts > 0) { $exercise_stat = get_best_attempt_by_user(api_get_user_id(), $exercices['id'], $course_info['code'], $session_id); if (!empty($exercise_stat)) { //Always getting the BEST attempt $score = $exercise_stat['exe_result']; $weighting = $exercise_stat['exe_weighting']; $exe_id = $exercise_stat['exe_id']; $latest_attempt_url .= api_get_path(WEB_CODE_PATH).'exercice/result.php?id='.$exe_id.'&cidReq='.$course_info['code'].'&show_headers=1&id_session='.$session_id; $percentage_score_result = Display::url(show_score($score, $weighting), $latest_attempt_url); $my_score = 0; if (!empty($weighting) && intval($weighting) != 0) { $my_score = $score/$weighting; } //@todo this function slows the page $position = get_exercise_result_ranking($my_score, $exe_id, $exercices['id'], $course_info['code'], $session_id, $user_list); $graph = self::generate_exercise_result_thumbnail_graph($to_graph_exercise_result[$exercices['id']]); $normal_graph = self::generate_exercise_result_graph($to_graph_exercise_result[$exercices['id']]); } } $html .= Display::div($normal_graph, array('id'=>'main_graph_'.$exercices['id'],'class'=>'dialog', 'style'=>'display:none') ); if (empty($graph)) { $graph = '-'; } else { $graph = Display::url($graph, '#', array('id'=>$exercices['id'], 'class'=>'opener')); } $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', $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 .= '</tr>'; } } else { $html .= '<tr><td colspan="5" align="center">'.get_lang('NoEx').'</td></tr>'; } $html .= '</table>'; //LP table results $html .='<table class="data_table">'; $html .= Display::tag('th', get_lang('Learnpaths'), array('class'=>'head', 'style'=>'color:#000')); $html .= Display::tag('th', get_lang('LatencyTimeSpent'), array('class'=>'head', 'style'=>'color:#000')); $html .= Display::tag('th', get_lang('Progress'), array('class'=>'head', 'style'=>'color:#000')); $html .= Display::tag('th', get_lang('Score'), array('class'=>'head', 'style'=>'color:#000')); $html .= Display::tag('th', get_lang('LastConnexion'), array('class'=>'head', 'style'=>'color:#000')); $html .= '</tr>'; $list = new LearnpathList(api_get_user_id(), $course_info['code'], $session_id, 'publicated_on ASC', true); $lp_list = $list->get_flat_list(); if (!empty($lp_list) > 0) { foreach($lp_list as $lp_id => $learnpath) { $progress = Tracking::get_avg_student_progress($user_id, $course, array($lp_id), $session_id); $last_connection_in_lp = Tracking::get_last_connection_time_in_lp($user_id, $course, $lp_id, $session_id); $time_spent_in_lp = Tracking::get_time_spent_in_lp($user_id, $course, array($lp_id), $session_id); $percentage_score = Tracking::get_avg_student_score($user_id, $course, array($lp_id), $session_id); if (is_numeric($percentage_score)) { $percentage_score = $percentage_score.'%'; } else { $percentage_score = '0%'; } $time_spent_in_lp = api_time_to_hms($time_spent_in_lp); $html .= '<tr class="row_even">'; $url = api_get_path(WEB_CODE_PATH)."newscorm/lp_controller.php?cidReq={$course_code}&id_session=$session_id&lp_id=$lp_id&action=view"; $html .= Display::tag('td', Display::url($learnpath['lp_name'], $url, array('target'=>SESSION_LINK_TARGET))); $html .= Display::tag('td', $time_spent_in_lp, array('align'=>'center')); if (is_numeric($progress)) { $progress = $progress.'%'; } $html .= Display::tag('td', $progress, array('align'=>'center')); $html .= Display::tag('td', $percentage_score); $last_connection = '-'; if (!empty($last_connection_in_lp)) { $last_connection = api_convert_and_format_date($last_connection_in_lp, DATE_TIME_FORMAT_LONG); } $html .= Display::tag('td', $last_connection, array('align'=>'center','width'=>'180px')); $html .= "</tr>"; } } else { $html .= '<tr> <td colspan="4" align="center"> '.get_lang('NoLearnpath').' </td> </tr>'; } $html .='</table>'; } return $html; }