<?php

/**
 * Pagination - Lesson
 *
 * @author 		WooThemes
 * @package 	Sensei/Templates
 * @version     1.1.0
 */
if (!defined('ABSPATH')) {
    exit;
}
global $post;
$nav_id_array = sensei_get_prev_next_lessons($post->ID);
$previous_lesson_id = absint($nav_id_array['prev_lesson']);
$next_lesson_id = absint($nav_id_array['next_lesson']);
// Output HTML
if (0 < $previous_lesson_id || 0 < $next_lesson_id) {
    ?>
	<nav id="post-entries" class="post-entries fix">
        <?php 
    if (0 < $previous_lesson_id) {
        ?>
<div class="nav-prev fl"><a href="<?php 
        echo esc_url(get_permalink($previous_lesson_id));
        ?>
" rel="prev"><span class="meta-nav"></span> <?php 
        echo get_the_title($previous_lesson_id);
        ?>
</a></div><?php 
    }
<?php

/**
 * Pagination - Lesson
 *
 * @author 		WooThemes
 * @package 	Sensei/Templates
 * @version     1.1.0
 */
if (!defined('ABSPATH')) {
    exit;
}
global $post;
$quiz_lesson = absint(get_post_meta($post->ID, '_quiz_lesson', true));
$nav_id_array = sensei_get_prev_next_lessons($quiz_lesson);
$previous_lesson_id = absint($nav_id_array['prev_lesson']);
$next_lesson_id = absint($nav_id_array['next_lesson']);
// Output HTML
if (0 < $previous_lesson_id || 0 < $next_lesson_id) {
    ?>
	<nav id="post-entries" class="post-entries fix">
        <?php 
    if (0 < $previous_lesson_id) {
        ?>
<div class="nav-prev fl"><a href="<?php 
        echo esc_url(get_permalink($previous_lesson_id));
        ?>
" rel="prev"><span class="meta-nav"></span> <?php 
        echo get_the_title($previous_lesson_id);
        ?>
</a></div><?php 
Esempio n. 3
0
 /**
  * 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
  * @param  bool $is_lesson
  * @return array              Status code and message
  */
 public static function sensei_user_quiz_status_message($lesson_id = 0, $user_id = 0, $is_lesson = false)
 {
     global $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 = Sensei_Utils::user_started_course($course_id, $user_id);
         // Has user completed lesson
         $user_lesson_status = Sensei_Utils::user_lesson_status($lesson_id, $user_id);
         $lesson_complete = Sensei_Utils::user_completed_lesson($user_lesson_status);
         // Quiz ID
         $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
         // Quiz grade
         $quiz_grade = 0;
         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'), Sensei_Utils::round($quiz_grade));
                 } else {
                     $message = sprintf(__('Congratulations! You have passed this quiz achieving %s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_grade));
                 }
             }
             // add next lesson button
             $nav_id_array = sensei_get_prev_next_lessons($lesson_id);
             $next_lesson_id = absint($nav_id_array['next_lesson']);
             // Output HTML
             if (0 < $next_lesson_id) {
                 $message .= ' ' . '<a class="next-lesson" href="' . esc_url(get_permalink($next_lesson_id)) . '" rel="next"><span class="meta-nav"></span>' . __('Next Lesson', 'woothemes-sensei') . '</a>';
             }
         } 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'), 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'), Sensei_Utils::round($quiz_passmark), Sensei_Utils::round($quiz_grade));
                 } else {
                     $message = sprintf(__('You require %1$d%% to pass this quiz. Your grade is %2$s%%', 'woothemes-sensei'), Sensei_Utils::round($quiz_passmark), 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'), Sensei_Utils::round($quiz_passmark));
                 } else {
                     $message = sprintf(__('You require %1$d%% to pass this quiz.', 'woothemes-sensei'), 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'))) {
         $quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
         $extra = '<p><a class="button" href="' . esc_url(get_permalink($quiz_id)) . '" title="' . __('View the lesson quiz', 'woothemes-sensei') . '">' . __('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);
 }
    function widget($args, $instance)
    {
        global $woothemes_sensei, $post, $current_user, $view_lesson, $user_taking_course;
        $allmodules = 'off';
        if (isset($instance['allmodules'])) {
            $allmodules = $instance['allmodules'];
        }
        // If not viewing a lesson/quiz, don't display the widget
        if (!(is_singular('lesson') || is_singular('quiz'))) {
            return;
        }
        extract($args);
        if (is_singular('quiz')) {
            $current_lesson_id = absint(get_post_meta($post->ID, '_quiz_lesson', true));
        } else {
            $current_lesson_id = $post->ID;
        }
        // get the course for the current lesson/quiz
        $lesson_course_id = get_post_meta($current_lesson_id, '_lesson_course', true);
        // Check if the user is taking the course
        $is_user_taking_course = WooThemes_Sensei_Utils::user_started_course($lesson_course_id, $current_user->ID);
        //Check for preview lesson
        $is_preview = false;
        if (method_exists('WooThemes_Sensei_Utils', 'is_preview_lesson')) {
            $is_preview = WooThemes_Sensei_Utils::is_preview_lesson($post->ID);
        }
        $course_title = get_the_title($lesson_course_id);
        $course_url = get_the_permalink($lesson_course_id);
        $in_module = false;
        $lesson_module = '';
        $lesson_array = array();
        if (0 < $current_lesson_id) {
            // get an array of lessons in the module if there is one
            if (isset(Sensei()->modules) && has_term('', Sensei()->modules->taxonomy, $current_lesson_id)) {
                // Get all modules
                $course_modules = Sensei()->modules->get_course_modules($lesson_course_id);
                $lesson_module = Sensei()->modules->get_lesson_module($current_lesson_id);
                $in_module = true;
                $current_module_title = htmlspecialchars($lesson_module->name);
                // Display all modules
                if ('on' == $allmodules) {
                    foreach ($course_modules as $module) {
                        // get all lessons in the module
                        $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($lesson_course_id), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => intval($module->term_id))), 'meta_key' => '_order_module_' . intval($module->term_id), 'orderby' => 'meta_value_num date', 'order' => 'ASC');
                        $lesson_array = array_merge($lesson_array, get_posts($args));
                    }
                } else {
                    // Only display current module
                    // get all lessons in the current module
                    $args = array('post_type' => 'lesson', 'post_status' => 'publish', 'posts_per_page' => -1, 'meta_query' => array(array('key' => '_lesson_course', 'value' => intval($lesson_course_id), 'compare' => '=')), 'tax_query' => array(array('taxonomy' => Sensei()->modules->taxonomy, 'field' => 'id', 'terms' => $lesson_module)), 'meta_key' => '_order_module_' . intval($lesson_module->term_id), 'orderby' => 'meta_value_num date', 'order' => 'ASC');
                    $lesson_array = get_posts($args);
                }
            } else {
                // if there's no module, get all lessons in the course
                $lesson_array = Sensei()->course->course_lessons($lesson_course_id);
            }
        }
        echo $before_widget;
        ?>

		<header>
			<h2 class="course-title"><a href="<?php 
        echo $course_url;
        ?>
"><?php 
        echo $course_title;
        ?>
</a></h2>

			<?php 
        if ($in_module && 'on' != $allmodules) {
            ?>
				<h3 class="module-title"><?php 
            echo $current_module_title;
            ?>
</h3>
			<?php 
        }
        ?>

		</header>

		<?php 
        $nav_id_array = sensei_get_prev_next_lessons($current_lesson_id);
        $previous_lesson_id = absint($nav_id_array['prev_lesson']);
        $next_lesson_id = absint($nav_id_array['next_lesson']);
        if (0 < $previous_lesson_id || 0 < $next_lesson_id) {
            ?>

			<ul class="course-progress-navigation">
				<?php 
            if (0 < $previous_lesson_id) {
                ?>
<li class="prev"><a href="<?php 
                echo esc_url(get_permalink($previous_lesson_id));
                ?>
" title="<?php 
                echo get_the_title($previous_lesson_id);
                ?>
"><span><?php 
                _e('Previous', 'sensei-course-progress');
                ?>
</span></a></li><?php 
            }
            ?>
				<?php 
            if (0 < $next_lesson_id) {
                ?>
<li class="next"><a href="<?php 
                echo esc_url(get_permalink($next_lesson_id));
                ?>
" title="<?php 
                echo get_the_title($next_lesson_id);
                ?>
"><span><?php 
                _e('Next', 'sensei-course-progress');
                ?>
</span></a></li><?php 
            }
            ?>
			</ul>

		<?php 
        }
        ?>

		<ul class="course-progress-lessons">

			<?php 
        $old_module = '';
        foreach ($lesson_array as $lesson) {
            $lesson_id = $lesson->ID;
            $lesson_title = htmlspecialchars($lesson->post_title);
            $lesson_url = get_the_permalink($lesson_id);
            // add 'completed' class to completed lessons
            $classes = "not-completed";
            if (WooThemes_Sensei_Utils::user_completed_lesson($lesson->ID, $current_user->ID)) {
                $classes = "completed";
            }
            // Lesson Quiz Meta
            $lesson_quiz_id = Sensei()->lesson->lesson_quizzes($lesson_id);
            // add 'current' class on the current lesson/quiz
            if ($lesson_id == $post->ID || $lesson_quiz_id == $post->ID) {
                $classes .= " current";
            }
            if (isset(Sensei()->modules) && 'on' == $allmodules) {
                $new_module = Sensei()->modules->get_lesson_module($lesson_id);
                if ($old_module != $new_module) {
                    ?>
						<li class="course-progress-module"><h3><?php 
                    echo $new_module->name;
                    ?>
</h3></li>
						<?php 
                    $old_module = $new_module;
                }
            }
            ?>

				<li class="course-progress-lesson <?php 
            echo $classes;
            ?>
">
					<?php 
            if ($lesson->ID == $post->ID || $lesson_quiz_id == $post->ID) {
                echo '<span>' . $lesson_title . '</span>';
            } else {
                echo '<a href="' . $lesson_url . '">' . $lesson_title . '</a>';
            }
            ?>
				</li>

			<?php 
        }
        ?>

		</ul>

		<?php 
        echo $after_widget;
    }