/** * Sets the stats boxes to render * @since 1.2.0 * @return array $stats_to_render of stats boxes and values */ public function stats_boxes() { // Get the data required $user_count = count_users(); $user_count = apply_filters('sensei_analysis_total_users', $user_count['total_users'], $user_count); $total_courses = Sensei()->course->course_count(array('publish', 'private')); $total_lessons = Sensei()->lesson->lesson_count(array('publish', 'private')); /** * filter the analysis tot grades query args */ $grade_args = apply_filters('sensei_analysis_total_quiz_grades', array('type' => 'sensei_lesson_status', 'status' => 'any', 'meta_key' => 'grade')); $total_grade_count = Sensei_Grading::get_graded_lessons_count(); $total_grade_total = Sensei_Grading::get_graded_lessons_sum(); $total_average_grade = 0; if ($total_grade_total > 0 && $total_grade_count > 0) { $total_average_grade = abs(round(doubleval($total_grade_total / $total_grade_count), 2)); } $course_args = array('type' => 'sensei_course_status', 'status' => 'any'); $total_courses_started = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_started', $course_args)); $course_args = array('type' => 'sensei_course_status', 'status' => 'complete'); $total_courses_ended = Sensei_Utils::sensei_check_for_activity(apply_filters('sensei_analysis_total_courses_ended', $course_args)); $average_courses_per_learner = abs(round(doubleval($total_courses_started / $user_count), 2)); // Setup the boxes to render $stats_to_render = array(__('Total Courses', 'woothemes-sensei') => $total_courses, __('Total Lessons', 'woothemes-sensei') => $total_lessons, __('Total Learners', 'woothemes-sensei') => $user_count, __('Average Courses per Learner', 'woothemes-sensei') => $average_courses_per_learner, __('Average Grade', 'woothemes-sensei') => $total_average_grade . '%', __('Total Completed Courses', 'woothemes-sensei') => $total_courses_ended); return apply_filters('sensei_analysis_stats_boxes', $stats_to_render); }
/** * Grade quiz automatically * * This function grades each question automatically if the are auto gradable. * It store all question grades. * * @deprecated since 1.7.4 use WooThemes_Sensei_Grading::grade_quiz_auto instead * * @param integer $quiz_id ID of quiz * @param array $submitted questions id ans answers { * @type int $question_id * @type mixed $answer * } * @param integer $total_questions Total questions in quiz (not used) * @param string $quiz_grade_type Optional defaults to auto * * @return int $quiz_grade total sum of all question grades */ public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto') { return Sensei_Grading::grade_quiz_auto($quiz_id, $submitted, $total_questions, $quiz_grade_type); }
/** * Submit the users quiz answers for grading * * This function accepts users answers and stores it but also initiates the grading * if a quiz can be graded automatically it will, if not the answers can be graded by the teacher. * * @since 1.7.4 * @access public * * @param array $quiz_answers * @param array $files from $_FILES * @param int $user_id * @param int $lesson_id * * @return bool $answers_submitted */ public static function submit_answers_for_grading($quiz_answers, $files = array(), $lesson_id, $user_id = 0) { $answers_submitted = false; // get the user_id if none was passed in use the current logged in user if (!intval($user_id) > 0) { $user_id = get_current_user_id(); } // make sure the parameters are valid before continuing if (empty($lesson_id) || empty($user_id) || 'lesson' != get_post_type($lesson_id) || !get_userdata($user_id) || !is_array($quiz_answers)) { return false; } // Default grade $grade = 0; // Get Quiz ID $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id); // Get quiz grade type $quiz_grade_type = get_post_meta($quiz_id, '_quiz_grade_type', true); // Get quiz pass setting $pass_required = get_post_meta($quiz_id, '_pass_required', true); // Get the minimum percentage need to pass this quiz $quiz_pass_percentage = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2)); // Handle Quiz Questions asked // This is to ensure we save the questions that we've asked this user and that this can't be change unless // the quiz is reset by admin or user( user: only if the setting is enabled ). // get the questions asked when when the quiz questions were generated for the user : Sensei_Lesson::lesson_quiz_questions $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id); $questions_asked = get_comment_meta($user_lesson_status->comment_ID, 'questions_asked', true); if (empty($questions_asked)) { $questions_asked = array_keys($quiz_answers); $questions_asked_string = implode(',', $questions_asked); // Save questions that were asked in this quiz update_comment_meta($user_lesson_status->comment_ID, 'questions_asked', $questions_asked_string); } // Save Quiz Answers for grading, the save function also calls the sensei_start_lesson self::save_user_answers($quiz_answers, $files, $lesson_id, $user_id); // Grade quiz $grade = Sensei_Grading::grade_quiz_auto($quiz_id, $quiz_answers, 0, $quiz_grade_type); // Get Lesson Grading Setting $lesson_metadata = array(); $lesson_status = 'ungraded'; // Default when completing a quiz // At this point the answers have been submitted $answers_submitted = true; // if this condition is false the quiz should manually be graded by admin if ('auto' == $quiz_grade_type && !is_wp_error($grade)) { // Quiz has been automatically Graded if ('on' == $pass_required) { // Student has reached the pass mark and lesson is complete if ($quiz_pass_percentage <= $grade) { $lesson_status = 'passed'; } else { $lesson_status = 'failed'; } // End If Statement } else { // Student only has to partake the quiz $lesson_status = 'graded'; } $lesson_metadata['grade'] = $grade; // Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz_auto()" above } // end if ! is_wp_error( $grade ... Sensei_Utils::update_lesson_status($user_id, $lesson_id, $lesson_status, $lesson_metadata); if ('passed' == $lesson_status || 'graded' == $lesson_status) { /** * Lesson end action hook * * This hook is fired after a lesson quiz has been graded and the lesson status is 'passed' OR 'graded' * * @param int $user_id * @param int $lesson_id */ do_action('sensei_user_lesson_end', $user_id, $lesson_id); } /** * User quiz has been submitted * * Fires the end of the submit_answers_for_grading function. It will fire irrespective of the submission * results. * * @param int $user_id * @param int $quiz_id * @param string $grade * @param string $quiz_pass_percentage * @param string $quiz_grade_type */ do_action('sensei_user_quiz_submitted', $user_id, $quiz_id, $grade, $quiz_pass_percentage, $quiz_grade_type); return $answers_submitted; }