function opigno_quiz_app_get_course_data_result in Opigno Quiz App 7
Helper function to get all results for a given course and user.
Parameters
int $uid:
int $nid:
bool $filter_access = FALSE:
Return value
array|false
3 calls to opigno_quiz_app_get_course_data_result()
- opigno_quiz_app_courses_results in includes/
opigno_quiz_app.pages.inc - Page callback: view all user results for all courses (where allowed).
- opigno_quiz_app_course_results in includes/
opigno_quiz_app.pages.inc - Page callback: view all user results for a specific course.
- opigno_quiz_app_user_results in includes/
opigno_quiz_app.pages.inc - Page callback: view user results.
File
- ./
opigno_quiz_app.module, line 991 - Module file. Defines module hooks.
Code
function opigno_quiz_app_get_course_data_result($uid, $nid, $filter_access = FALSE) {
$cache =& drupal_static(__FUNCTION__);
$filter_access = (int) $filter_access;
if (!isset($cache["{$nid}:{$uid}:{$filter_access}"])) {
$node = node_load($nid);
$quizzes = opigno_quiz_app_get_all_required_quizzes($node);
$final_score = 0;
$failed = OPIGNO_QUIZ_APP_PASSED;
$total_time = 0;
$count = 0;
if ($filter_access) {
$temp = array();
foreach ($quizzes as $quiz_nid => $quiz) {
if (opigno_quiz_app_access_node_teacher_results($node, $quiz)) {
$temp[$quiz_nid] = $quiz;
}
}
$quizzes = $temp;
}
if (empty($quizzes)) {
$cache["{$nid}:{$uid}:{$filter_access}"] = FALSE;
return FALSE;
}
$nids = array_keys($quizzes);
// Fetch all scores to calculate the total time spent.
$all_scores = opigno_quiz_app_get_score_data($nids, $uid);
$quiz_total_time = array();
foreach ($all_scores as $quiz_nid => $results) {
foreach ($results as $rid => $score) {
if ($score->time_end != 0) {
if (!isset($quiz_total_time[$quiz_nid])) {
$quiz_total_time[$quiz_nid] = 0;
}
$total_time += $score->time_end - $score->time_start;
$quiz_total_time[$quiz_nid] += $score->time_end - $score->time_start;
}
}
}
// Get only best scores for final table.
$all_scores = quiz_get_score_data($nids, $uid);
foreach ($all_scores as $score) {
if (isset($quizzes[$score->nid])) {
$info['quizzes'][$quizzes[$score->nid]->title]['passed'] = isset($score->percent_score) ? $score->percent_score >= $score->percent_pass ? OPIGNO_QUIZ_APP_PASSED : OPIGNO_QUIZ_APP_FAILED : OPIGNO_QUIZ_APP_PENDING;
$info['quizzes'][$quizzes[$score->nid]->title]['score'] = isset($score->percent_score) ? $score->percent_score : NULL;
$info['quizzes'][$quizzes[$score->nid]->title]['total_time'] = isset($quiz_total_time[$score->nid]) ? $quiz_total_time[$score->nid] : NULL;
if (isset($score->percent_score) && isset($quizzes[$score->nid]->quiz_weight[LANGUAGE_NONE][0]['value'])) {
$final_score += $quizzes[$score->nid]->quiz_weight[LANGUAGE_NONE][0]['value'] * $score->percent_score;
$count += $quizzes[$score->nid]->quiz_weight[LANGUAGE_NONE][0]['value'];
}
elseif (isset($score->percent_score)) {
$final_score += $score->percent_score;
$count++;
}
else {
$failed = OPIGNO_QUIZ_APP_PENDING;
}
if ($failed !== OPIGNO_QUIZ_APP_PENDING && $failed !== OPIGNO_QUIZ_APP_FAILED && $score->percent_score < $score->percent_pass) {
$failed = OPIGNO_QUIZ_APP_FAILED;
}
}
}
////////////////resultschange//////////////
if (module_exists('opigno_in_house_training_app')) {
$iht = opigno_in_house_get_all_required_iht($node);
foreach ($iht as $index => $rest) {
$value = opigno_in_house_training_score_form_get_default_value($index, $uid);
$info['iht'][$rest->title]['passed'] = OPIGNO_QUIZ_APP_PASSED;
$info['iht'][$rest->title]['score'] = t("Attended");
$info['iht'][$rest->title]['total_time'] = opigno_calendar_app_get_node_duration($rest);
if ($value['status'] != 1) {
$failed = OPIGNO_QUIZ_APP_FAILED;
$info['iht'][$rest->title]['passed'] = OPIGNO_QUIZ_APP_FAILED;
$info['iht'][$rest->title]['score'] = t("Absent");
$info['iht'][$rest->title]['total_time'] = 0;
}
$total_time += $info['iht'][$rest->title]['total_time'];
}
}
if (module_exists('opigno_live_meetings')) {
$meetings = opigno_live_meetings_get_all_required_meetings($node);
foreach ($meetings as $index => $rest) {
$value = opigno_live_meetings_score_get_db_values($index, $uid);
$info['live_meeting'][$rest->title]['passed'] = OPIGNO_QUIZ_APP_PASSED;
$info['live_meeting'][$rest->title]['score'] = t("Attended");
$info['live_meeting'][$rest->title]['total_time'] = opigno_calendar_app_get_node_duration($rest);
if ($value['status'] != 1) {
$failed = OPIGNO_QUIZ_APP_FAILED;
$info['live_meeting'][$rest->title]['passed'] = OPIGNO_QUIZ_APP_FAILED;
$info['live_meeting'][$rest->title]['score'] = t("Absent");
$info['live_meeting'][$rest->title]['total_time'] = 0;
}
$total_time += $info['live_meeting'][$rest->title]['total_time'];
}
}
if (module_exists('opigno_webex_app')) {
$webx = opigno_webex_app_get_all_required_quizzes($node);
foreach ($webx as $index => $rest) {
$value = opigno_webex_attendance_form_get_default_value($index, $uid);
$info['webx'][$rest->title]['passed'] = OPIGNO_QUIZ_APP_PASSED;
$info['webx'][$rest->title]['score'] = t("Attended");
$info['webx'][$rest->title]['total_time'] = opigno_calendar_app_get_node_duration($rest);
if ($value['status'] != 1) {
$failed = OPIGNO_QUIZ_APP_FAILED;
$info['webx'][$rest->title]['passed'] = OPIGNO_QUIZ_APP_FAILED;
$info['webx'][$rest->title]['score'] = t("Absent");
$info['webx'][$rest->title]['total_time'] = 0;
}
$total_time += $info['webx'][$rest->title]['total_time'];
}
}
///////////////////////////////////////////////
// Failsafe. There were no visible results for allowed quizzes.
if (empty($info['quizzes'])) {
$cache["{$nid}:{$uid}:{$filter_access}"] = FALSE;
return FALSE;
}
$info['passed'] = $failed;
$info['total_score'] = $count ? round($final_score / $count) : 0;
$info['total_time'] = $total_time;
$cache["{$nid}:{$uid}:{$filter_access}"] = $info;
}
return $cache["{$nid}:{$uid}:{$filter_access}"];
}