本文整理汇总了PHP中WooThemes_Sensei_Utils::sensei_grade_quiz方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::sensei_grade_quiz方法的具体用法?PHP WooThemes_Sensei_Utils::sensei_grade_quiz怎么用?PHP WooThemes_Sensei_Utils::sensei_grade_quiz使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WooThemes_Sensei_Utils
的用法示例。
在下文中一共展示了WooThemes_Sensei_Utils::sensei_grade_quiz方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: process_grading
public function process_grading()
{
// NEEDS REFACTOR/OPTIMISING, such as combining the various meta data stored against the sensei_user_answer entry
if (isset($_POST['sensei_manual_grade']) && isset($_GET['quiz_id'])) {
// error_log( __CLASS__ . ':' . __FUNCTION__ . ':' . print_r($_POST, true));
$quiz_id = $_GET['quiz_id'];
$user_id = $_GET['user'];
$verify_nonce = wp_verify_nonce($_POST['_wp_sensei_manual_grading_nonce'], 'sensei_manual_grading');
if ($verify_nonce && $quiz_id == $_POST['sensei_manual_grade']) {
$questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id);
$quiz_grade = 0;
$count = 0;
$quiz_grade_total = $_POST['quiz_grade_total'];
foreach ($questions as $question) {
++$count;
$question_id = $question->ID;
if (isset($_POST['question_' . $question_id])) {
$correct = false;
$question_grade = 0;
$question_total_grade = $_POST['question_total_grade'];
if ($_POST['question_' . $question_id] == 'right') {
$correct = true;
$question_grade = $_POST['question_' . $question_id . '_grade'];
}
$activity_logged = WooThemes_Sensei_Utils::sensei_grade_question($question_id, $question_grade, $user_id);
$quiz_grade += $question_grade;
} else {
WooThemes_Sensei_Utils::sensei_delete_question_grade($question_id);
}
// WP slashes all incoming data regardless of Magic Quotes setting (see wp_magic_quotes()), but
// as an answer note is not direct post_content it won't have slashes removed, so we need to do it
$answer_notes = wp_unslash($_POST['question_' . $question_id . '_notes']);
if (!$answer_notes || $answer_notes == '') {
$answer_notes = '';
}
WooThemes_Sensei_Utils::sensei_add_answer_notes($question_id, $user_id, $answer_notes);
}
if ($_POST['all_questions_graded'] == 'yes') {
$grade = abs(round(doubleval($quiz_grade) * 100 / $quiz_grade_total, 2));
$activity_logged = WooThemes_Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id);
// Duplicating what Frontend->sensei_complete_quiz() does
$quiz_lesson_id = absint(get_post_meta($quiz_id, '_quiz_lesson', true));
$pass_required = get_post_meta($quiz_id, '_pass_required', true);
$quiz_passmark = abs(round(doubleval(get_post_meta($quiz_id, '_quiz_passmark', true)), 2));
$lesson_metadata = array();
if ($pass_required) {
// Student has reached the pass mark and lesson is complete
if ($quiz_passmark <= $grade) {
$lesson_status = 'passed';
} else {
$lesson_status = 'failed';
}
// End If Statement
} else {
$lesson_status = 'graded';
}
$lesson_metadata['grade'] = $grade;
// Technically already set as part of "WooThemes_Sensei_Utils::sensei_grade_quiz()" above
WooThemes_Sensei_Utils::update_lesson_status($user_id, $quiz_lesson_id, $lesson_status, $lesson_metadata);
switch ($lesson_status) {
case 'passed':
case 'graded':
do_action('sensei_user_lesson_end', $user_id, $quiz_lesson_id);
break;
}
}
if (isset($_POST['sensei_grade_next_learner']) && strlen($_POST['sensei_grade_next_learner']) > 0) {
$load_url = add_query_arg(array('message' => 'graded'));
} elseif (isset($_POST['_wp_http_referer'])) {
$load_url = add_query_arg(array('message' => 'graded'), $_POST['_wp_http_referer']);
} else {
$load_url = add_query_arg(array('message' => 'graded'));
}
wp_safe_redirect($load_url);
exit;
}
}
}
示例2: grade_quiz_auto
/**
* Grade quiz automatically
*
* This function grades each question automatically if there all questions are auto gradable. If not
* the quiz will not be auto gradable.
*
* @since 1.7.4
*
* @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 grade_quiz_auto($quiz_id = 0, $submitted = array(), $total_questions = 0, $quiz_grade_type = 'auto')
{
if (!(intval($quiz_id) > 0) || !$submitted || $quiz_grade_type != 'auto') {
return false;
// exit early
}
global $woothemes_sensei;
$user_id = get_current_user_id();
$lesson_id = $woothemes_sensei->quiz->get_lesson_id($quiz_id);
$quiz_autogradable = true;
/**
* Filter the types of question types that can be automatically graded.
*
* This filter fires inside the auto grade quiz function and provides you with the default list.
*
* @param array {
* 'multiple-choice',
* 'boolean',
* 'gap-fill'.
* }
*/
$autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill'));
$grade_total = 0;
$all_question_grades = array();
foreach ($submitted as $question_id => $answer) {
// check if the question is autogradable, either by type, or because the grade is 0
$question_type = $woothemes_sensei->question->get_question_type($question_id);
$achievable_grade = $woothemes_sensei->question->get_question_grade($question_id);
// Question has a zero grade, so skip grading
if (0 == $achievable_grade) {
$all_question_grades[$question_id] = $achievable_grade;
} elseif (in_array($question_type, $autogradable_question_types)) {
// Get user question grade
$question_grade = WooThemes_Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id);
$all_question_grades[$question_id] = $question_grade;
$grade_total += $question_grade;
} else {
// There is a question that cannot be autograded
$quiz_autogradable = false;
}
// end if in_array( $question_type...
}
// end for each question
// Only if the whole quiz was autogradable do we set a grade
if ($quiz_autogradable) {
$quiz_total = WooThemes_Sensei_Utils::sensei_get_quiz_total($quiz_id);
// Check for zero total from grades
if (0 < $quiz_total) {
$grade = abs(round(doubleval($grade_total) * 100 / $quiz_total, 2));
} else {
$grade = 0;
}
WooThemes_Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type);
} else {
$grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei'));
}
// store the auto gradable grades. If the quiz is not auto gradable the grades can be use as the default
// when doing manual grading.
$woothemes_sensei->quiz->set_user_grades($all_question_grades, $lesson_id, $user_id);
return $grade;
}
示例3: sensei_grade_quiz_auto
/**
* Grade quiz automatically
* @param integer $quiz_id ID of quiz
* @param integer $lesson_id ID of lesson
* @param boolean $submitted Submitted answers
* @param integer $total_questions Total questions in quiz (not used)
* @return boolean Whether quiz was successfully graded or not
*/
public static function sensei_grade_quiz_auto($quiz_id = 0, $submitted = false, $total_questions = 0, $quiz_grade_type = 'auto')
{
if (intval($user_id) == 0) {
$user_id = get_current_user_id();
}
$grade = 0;
$correct_answers = 0;
$quiz_graded = false;
$quiz_autogradable = true;
if (intval($quiz_id) > 0 && $submitted) {
if ($quiz_grade_type == 'auto') {
// Can only autograde these question types
$autogradable_question_types = apply_filters('sensei_autogradable_question_types', array('multiple-choice', 'boolean', 'gap-fill'));
$grade_total = 0;
foreach ($submitted as $question_id => $answer) {
// check if the question is autogradable
$question_type = get_the_terms($question_id, 'question-type');
// Set default question type if one does not exist - prevents errors when grading
if (!$question_type || is_wp_error($question_type) || !is_array($question_type)) {
$question_type = 'multiple-choice';
} else {
$question_type = array_shift($question_type)->slug;
}
if (in_array($question_type, $autogradable_question_types)) {
// Get user question grade
$question_grade = WooThemes_Sensei_Utils::sensei_grade_question_auto($question_id, $question_type, $answer, $user_id);
$grade_total += $question_grade;
} else {
// There is a question that cannot be autograded
$quiz_autogradable = false;
}
}
// Only if the whole quiz was autogradable do we set a grade
if ($quiz_autogradable) {
$quiz_total = WooThemes_Sensei_Utils::sensei_get_quiz_total($quiz_id);
$grade = abs(round(doubleval($grade_total) * 100 / $quiz_total, 2));
$activity_logged = WooThemes_Sensei_Utils::sensei_grade_quiz($quiz_id, $grade, $user_id, $quiz_grade_type);
} else {
$grade = new WP_Error('autograde', __('This quiz is not able to be automatically graded.', 'woothemes-sensei'));
}
}
}
return $grade;
}