本文整理汇总了PHP中WooThemes_Sensei_Utils::round方法的典型用法代码示例。如果您正苦于以下问题:PHP WooThemes_Sensei_Utils::round方法的具体用法?PHP WooThemes_Sensei_Utils::round怎么用?PHP WooThemes_Sensei_Utils::round使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WooThemes_Sensei_Utils
的用法示例。
在下文中一共展示了WooThemes_Sensei_Utils::round方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sensei_user_quiz_status_message
/**
* Set the status message displayed to the user for a quiz
* @param integer $lesson_id ID of quiz lesson
* @param integer $user_id ID of user
* @return array Status code and message
*/
public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false)
{
global $woothemes_sensei, $current_user;
if (intval($user_id) == 0) {
$user_id = $current_user->ID;
}
$status = 'not_started';
$box_class = 'info';
$message = __('You have not taken this lesson\'s quiz yet', 'woothemes-sensei');
$extra = '';
if ($lesson_id > 0 && $user_id > 0) {
// Prerequisite lesson
$prerequisite = get_post_meta($lesson_id, '_lesson_prerequisite', true);
// Course ID
$course_id = absint(get_post_meta($lesson_id, '_lesson_course', true));
// Has user started course
$started_course = WooThemes_Sensei_Utils::user_started_course($course_id, $user_id);
// Has user completed lesson
$user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
$lesson_complete = WooThemes_Sensei_Utils::user_completed_lesson($user_lesson_status);
// Quiz ID
$quiz_id = $woothemes_sensei->post_types->lesson->lesson_quizzes($lesson_id);
// Quiz grade
$quiz_grade = false;
if ($user_lesson_status) {
$quiz_grade = get_comment_meta($user_lesson_status->comment_ID, 'grade', true);
}
// Quiz passmark
$quiz_passmark = absint(get_post_meta($quiz_id, '_quiz_passmark', true));
$quiz_passmark_float = (double) $quiz_passmark;
// Pass required
$pass_required = get_post_meta($quiz_id, '_pass_required', true);
// Quiz questions
$has_quiz_questions = get_post_meta($lesson_id, '_quiz_has_questions', true);
if (!$started_course) {
$status = 'not_started_course';
$box_class = 'info';
$message = sprintf(__('Please sign up for %1$sthe course%2$s before taking this quiz', 'woothemes-sensei'), '<a href="' . esc_url(get_permalink($course_id)) . '" title="' . esc_attr(__('Sign Up', 'woothemes-sensei')) . '">', '</a>');
} elseif (!is_user_logged_in()) {
$status = 'login_required';
$box_class = 'info';
$message = __('You must be logged in to take this quiz', 'woothemes-sensei');
} elseif ($lesson_complete) {
$status = 'passed';
$box_class = 'tick';
// Lesson status will be "complete" (has no Quiz)
if (!$has_quiz_questions) {
$message = sprintf(__('Congratulations! You have passed this lesson.', 'woothemes-sensei'));
} elseif (empty($quiz_grade)) {
$message = sprintf(__('Congratulations! You have completed this lesson.', 'woothemes-sensei'));
} elseif (!empty($quiz_grade) && abs($quiz_grade) >= 0) {
if ($is_lesson) {
$message = sprintf(__('Congratulations! You have passed this lesson\'s quiz achieving %s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_grade));
} else {
$message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_grade));
}
}
} else {
// Lesson/Quiz isn't "complete" instead it's ungraded (previously this "state" meant that it *was* complete)
if (isset($user_lesson_status->comment_approved) && 'ungraded' == $user_lesson_status->comment_approved) {
$status = 'complete';
$box_class = 'info';
if ($is_lesson) {
$message = sprintf(__('You have completed this lesson\'s quiz and it will be graded soon. %1$sView the lesson quiz%2$s', 'woothemes-sensei'), '<a href="' . esc_url(get_permalink($quiz_id)) . '" title="' . esc_attr(get_the_title($quiz_id)) . '">', '</a>');
} else {
$message = sprintf(__('You have completed this quiz and it will be graded soon. You require %1$s%% to pass.', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark));
}
} elseif (isset($user_lesson_status->comment_approved) && 'failed' == $user_lesson_status->comment_approved) {
$status = 'failed';
$box_class = 'alert';
if ($is_lesson) {
$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark), WooThemes_Sensei_Utils::round($quiz_grade));
} else {
$message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark), WooThemes_Sensei_Utils::round($quiz_grade));
}
} elseif ($pass_required) {
$status = 'not_started';
$box_class = 'info';
if ($is_lesson) {
$message = sprintf(__('You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark));
} else {
$message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), WooThemes_Sensei_Utils::round($quiz_passmark));
}
}
}
}
// Legacy filter
$message = apply_filters('sensei_user_quiz_status_' . $status, $message);
if ($is_lesson && !in_array($status, array('login_required', 'not_started_course'))) {
$extra = '<p><a class="button" href="' . esc_url(get_permalink($quiz_id)) . '" title="' . esc_attr(apply_filters('sensei_view_lesson_quiz_text', __('View the lesson quiz', 'woothemes-sensei'))) . '">' . apply_filters('sensei_view_lesson_quiz_text', __('View the lesson quiz', 'woothemes-sensei')) . '</a></p>';
}
// Filter of all messages
return apply_filters('sensei_user_quiz_status', array('status' => $status, 'box_class' => $box_class, 'message' => $message, 'extra' => $extra), $lesson_id, $user_id, $is_lesson);
}
示例2: testRound
/**
* This tests Woothemes_Sensei_Utils::round
*/
public function testRound()
{
$this->assertTrue(2 == WooThemes_Sensei_Utils::round(2.12, 0), '2.12 rounded with 0 precision should be 2');
$this->assertTrue(3.3 == WooThemes_Sensei_Utils::round(3.3333, 1), '3.3333 rounded with 1 precision should be 3.3');
$this->assertTrue(doubleval(2.13) == WooThemes_Sensei_Utils::round(2.1256, 2), '2.1256 rounded with 2 precision should be 2.12');
$this->assertTrue(3 == WooThemes_Sensei_Utils::round(2.5, 0), '2.5 rounded with 0 precision should be 3');
}