function avg_grade($course_id) { global $wpdb; $_rank = new NamasteRepRank(); $users = $wpdb->get_results($wpdb->prepare("SELECT tU.user_nicename as user_nicename, tU.ID as user_id, tSC.grade as grade\n\t\tFROM {$wpdb->users} tU JOIN " . NAMASTE_STUDENT_COURSES . " tSC ON tSC.user_id = tU.ID\n\t\tAND tSC.course_id=%d\n\t\tWHERE tSC.grade!='' ", $course_id)); $gradepoints = $_rank->get_gradepoints(); $total_points = 0; foreach ($users as $user) { if ($user->grade) { $points = @$gradepoints[$user->grade]; } if (empty($points)) { $points = 0; } $total_points += $points; } // avg points $avg_points = empty($total_points) ? 0 : round($total_points / sizeof($users)); $gradepoints = array_flip($gradepoints); $value = @$gradepoints[$avg_points]; if (!$value) { $value = __('n/a', 'namasterep'); } return $value; }
static function rank($atts) { $students = array(); $_rank = new NamasteRepRank(); if (empty($atts['num'])) { $atts['num'] = 10; } switch (@$atts['rank_by']) { case 'avg_grade': $students = $_rank->avg_grade($atts['num'], @$atts['course_id'], @$atts['lesson_id']); break; case 'points': $students = $_rank->points($atts['num']); break; case 'pageviews': $students = $_rank->pageviews($atts['num'], @$atts['course_id'], @$atts['lesson_id']); break; case 'lessons': $students = $_rank->lessons_completed($atts['num'], @$atts['course_id']); break; default: $students = $_rank->courses_completed($atts['num']); break; } // end switch return $students; }