Exemple #1
0
function watupro_my_exams($passed_cat_ids = "", $orderby = "tE.ID")
{
    global $wpdb, $user_ID;
    // admin can see this for every student
    if (!empty($_GET['user_id']) and current_user_can(WATUPRO_MANAGE_CAPS)) {
        $user_id = $_GET['user_id'];
    } else {
        $user_id = $user_ID;
    }
    $user = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->users} WHERE ID=%d", $user_id));
    // select what categories I have access to
    get_currentuserinfo();
    $cat_ids = WTPCategory::user_cats($user_id);
    if (!empty($passed_cat_ids)) {
        $passed_cat_ids = explode(",", $passed_cat_ids);
        $cat_ids = array_intersect($cat_ids, $passed_cat_ids);
    }
    $cat_id_sql = implode(",", $cat_ids);
    list($my_exams, $takings, $num_taken) = WTPExam::my_exams($user_id, $cat_id_sql, $orderby);
    // intelligence dependencies
    if (watupro_intel()) {
        require_once WATUPRO_PATH . "/i/models/dependency.php";
        $my_exams = WatuPRODependency::mark($my_exams, $takings);
    }
    $num_to_take = sizeof($my_exams) - $num_taken;
    $dateformat = get_option('date_format');
    wp_enqueue_script('thickbox', null, array('jquery'));
    wp_enqueue_style('thickbox.css', '/' . WPINC . '/js/thickbox/thickbox.css', null, '1.0');
    wp_enqueue_style('style.css', plugins_url() . '/watupro/style.css', null, '1.0');
    if (@file_exists(get_stylesheet_directory() . '/watupro/my_exams.php')) {
        require get_stylesheet_directory() . '/watupro/my_exams.php';
    } else {
        require WATUPRO_PATH . "/views/my_exams.php";
    }
}
Exemple #2
0
 static function skills($report_user_id, $has_tabs = true)
 {
     global $wpdb;
     // select exam categories that I can access
     $cat_ids = WTPCategory::user_cats($report_user_id);
     $cat_id_sql = implode(",", $cat_ids);
     $exam_cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_CATS . " WHERE ID IN ({$cat_id_sql}) ORDER BY name");
     // question categories
     $q_cats = $wpdb->get_results("SELECT * FROM " . WATUPRO_QCATS . " ORDER BY name");
     // add uncategorized
     $q_cats[] = (object) array("ID" => 0, "name" => __('Uncategorized', 'watupro'));
     // exam category filter?
     $exam_cat_sql = @$_POST['cat'] < 0 ? $cat_id_sql : @$_POST['cat'];
     // now select all exams I have access to
     list($my_exams) = WTPExam::my_exams($report_user_id, $exam_cat_sql);
     $skill_filter = empty($_POST['skill_filter']) ? "all" : $_POST['skill_filter'];
     // practiced only?
     if ($skill_filter == 'practiced') {
         $final_exams = array();
         foreach ($my_exams as $exam) {
             if (!empty($exam->taking->ID)) {
                 $final_exams[] = $exam;
             }
         }
         $my_exams = $final_exams;
     }
     // proficiency filter selected? If yes, we'll need to limit exams
     // to those that are taken with at least $_POST['proficiency_goal'] % correct answers
     if ($skill_filter == 'proficient') {
         $final_exams = array();
         foreach ($my_exams as $exam) {
             if (!empty($exam->taking->ID) and $exam->taking->percent_correct >= $_POST['proficiency_goal']) {
                 $final_exams[] = $exam;
             }
         }
         // end exams loop
         $my_exams = $final_exams;
     }
     // for each exam select match answers and fill % correct info by category
     $taking_ids = array(0);
     foreach ($my_exams as $my_exam) {
         if (!empty($my_exam->taking->ID)) {
             $taking_ids[] = $my_exam->taking->ID;
         }
     }
     $user_answers = $wpdb->get_results("SELECT tA.is_correct as is_correct, tA.taking_id as taking_id, tQ.cat_id as cat_id \n\t\t\tFROM " . WATUPRO_STUDENT_ANSWERS . " tA JOIN " . WATUPRO_QUESTIONS . " tQ ON tQ.ID = tA.question_id\n\t\t\tWHERE tA.taking_id IN (" . implode(',', $taking_ids) . ") ORDER BY tA.ID");
     foreach ($my_exams as $cnt => $my_exam) {
         if (empty($my_exam->taking->ID)) {
             continue;
         }
         $cats = array();
         foreach ($user_answers as $answer) {
             if ($answer->taking_id != $my_exam->taking->ID) {
                 continue;
             }
             $correct_key = $answer->is_correct ? 'num_correct' : 'num_incorrect';
             if (isset($cats[$answer->cat_id][$correct_key])) {
                 $cats[$answer->cat_id][$correct_key]++;
             } else {
                 $cats[$answer->cat_id][$correct_key] = 1;
             }
         }
         // now foreach cat calculate the correctness
         foreach ($cats as $cat_id => $cat) {
             $num_correct = isset($cat['num_correct']) ? $cat['num_correct'] : 0;
             $num_incorrect = isset($cat['num_incorrect']) ? $cat['num_incorrect'] : 0;
             $total = $num_correct + $num_incorrect;
             $percentage = $total ? round(100 * $num_correct / $total) : 0;
             $cats[$cat_id]['percentage'] = $percentage;
         }
         // finally add cats to exam
         $my_exams[$cnt]->cats = $cats;
     }
     // group exams by question category
     $skills = array();
     // skills equal question categories
     $num_proficient = 0;
     foreach ($q_cats as $q_cat) {
         // skill filter (question category) selected in the drop-down?
         if (@$_POST['q_cat'] > -1 and $q_cat->ID != @$_POST['q_cat']) {
             continue;
         }
         // now construct array of this category along with the exams in it
         // then add in $skills. $skills is the final array that we'll use in the view
         $exams = array();
         foreach ($my_exams as $exam) {
             $has_questions = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . WATUPRO_QUESTIONS . " \n\t\t\t\t \tWHERE exam_id=%d AND cat_id=%d AND is_inactive=0 AND is_survey=0", $exam->ID, $q_cat->ID));
             if (!$has_questions) {
                 continue;
             }
             $exams[] = $exam;
         }
         $skills[] = array("category" => $q_cat, "exams" => $exams, "id" => $q_cat->ID);
         if (sizeof($exams)) {
             $num_proficient++;
         }
         // proficient in X skills
     }
     // by default $skills is ordered by category (name). Do we have to reorder?
     // NOT SURE THIS MAKES SENSE, SO FOR NOW NYI
     if (!empty($_POST['sort_skills']) and $_POST['sort_skills'] == 'proficiency') {
         // Sort by sum of proficiency of latest taking of the exams in this category
         // let's create an array that'll contain only cat ID and cumulative proficiency
         // for easier sorting
         $cat_ids = array();
         foreach ($skills as $skill) {
             // NYI
         }
     }
     if (@file_exists(get_stylesheet_directory() . '/watupro/reports/skills.php')) {
         require get_stylesheet_directory() . '/watupro/reports/skills.php';
     } else {
         require WATUPRO_PATH . "/modules/reports/views/skills.php";
     }
 }