static function overview($report_user_id, $has_tabs = true) { global $wpdb; // all exams taken $taken_exams = $wpdb->get_results($wpdb->prepare("SELECT tT.*, tE.cat_id as cat_id \n\t\t \tFROM " . WATUPRO_TAKEN_EXAMS . " tT JOIN " . WATUPRO_EXAMS . " tE ON tT.exam_id = tE.id\n\t\t \tWHERE user_id=%d ORDER BY date", $report_user_id)); // tests attempted var $num_attempts = sizeof($taken_exams); // skills practiced (question categories) $skills = $wpdb->get_results($wpdb->prepare("SELECT DISTINCT(cat_id) FROM " . WATUPRO_QUESTIONS . " WHERE ID IN (SELECT question_id FROM " . WATUPRO_STUDENT_ANSWERS . " WHERE user_id=%d)\n\t\t \tAND is_inactive=0 AND is_survey=0", $report_user_id)); $num_skills = sizeof($skills); // certificates earned $cnt_certificates = $wpdb->get_var($wpdb->prepare("SELECT COUNT(ID) FROM " . WATUPRO_USER_CERTIFICATES . "\n\t\t WHERE user_id=%d", $report_user_id)); // figure out num exams taken by exam category - select categories I have access to $cat_ids = WTPCategory::user_cats($report_user_id); $cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_CATS . " WHERE ID IN(" . implode(",", $cat_ids) . ")", ARRAY_A); $cats = array_merge(array(array("ID" => 0, "name" => __('Uncategorized', 'watupro'))), $cats); $report_cats = array(); // for any categories that don't have zero, add them to report_cats along with time_spent foreach ($cats as $cnt => $cat) { $num_attempts = 0; foreach ($taken_exams as $taken_exam) { if ($taken_exam->cat_id == $cat['ID']) { $num_attempts++; } } $cats[$cnt]['num_attempts'] = $num_attempts; if ($num_attempts) { $report_cats[] = $cats[$cnt]; } } // now select question categories $qcats = $wpdb->get_results($wpdb->prepare("SELECT COUNT(tA.ID) as cnt, tC.name as name\n\t\t \tFROM " . WATUPRO_QCATS . " tC JOIN " . WATUPRO_QUESTIONS . " tQ ON tQ.cat_id = tC.ID \n\t\t \tJOIN " . WATUPRO_STUDENT_ANSWERS . " tA ON tA.question_id = tQ.ID \tAND tA.user_id = %d \n\t\t \tGROUP BY tC.ID ORDER BY tC.name", $report_user_id)); $question_cats = array(); // fill only these that has at least 1 answer foreach ($qcats as $qcat) { if ($qcat->cnt > 0) { $question_cats[] = $qcat; } } self::$add_scripts = true; if (@file_exists(get_stylesheet_directory() . '/watupro/reports/overview.php')) { require get_stylesheet_directory() . '/watupro/reports/overview.php'; } else { require WATUPRO_PATH . "/modules/reports/views/overview.php"; } self::print_scripts(); }
static function chart_by_grade($in_shortcode = false) { global $wpdb; // select exam $exam = $wpdb->get_row($wpdb->prepare("SELECT * FROM " . WATUPRO_EXAMS . " WHERE ID=%d", $_GET['exam_id'])); // the code below is the same as in the play plugin controllers/charts.php. Think about a way to re-use it? // select all completed takings $takings = $wpdb->get_results($wpdb->prepare("SELECT tT.ID as ID, tT.points as points, tG.gtitle as grade_title \n\t\t\tFROM " . WATUPRO_TAKEN_EXAMS . " tT JOIN " . WATUPRO_GRADES . " tG ON tG.ID = tT.grade_id\n\t\t\tWHERE tT.exam_id=%d AND tT.in_progress=0 ORDER BY tT.points DESC", $exam->ID)); $num_takings = 0; $grades_arr = array(); // this array will hold grade_ids(keys) and no. users who got that grade (vals) foreach ($takings as $taking) { $num_takings++; if (isset($grades_arr[$taking->grade_title])) { $grades_arr[$taking->grade_title]++; } else { $grades_arr[$taking->grade_title] = 1; } } // now recalculate grade values in % foreach ($grades_arr as $key => $val) { // avoid division by zero error if ($num_takings == 0) { $grades_arr[$key] = 0; continue; } // now calculate $percent = round(100 * $val / $num_takings); $grades_arr[$key] = array("percent" => $percent, "num_takings" => $val); if ($percent == 0) { unset($grades_arr[$key]); } } // ksort($grades_arr); WTPReports::$add_scripts = true; WTPReports::register_scripts(); if (@file_exists(get_stylesheet_directory() . '/watupro/reports/chart-by-grade.html.php')) { require get_stylesheet_directory() . '/watupro/reports/chart-by-grade.html.php'; } else { require WATUPRO_PATH . "/modules/reports/views/chart-by-grade.html.php"; } WTPReports::print_scripts(); }