Пример #1
0
 /**
  * Testing the is lesson pre-requisite completed function.
  *
  * @since 1.9.0
  */
 public function testIsPreRequisiteComplete()
 {
     // does this function add_user_data exist?
     $this->assertTrue(method_exists('WooThemes_Sensei_Lesson', 'is_prerequisite_complete'), 'The lesson class function `is_prerequisite_complete` does not exist ');
     // falsy state
     $user_id = 0;
     $lesson_id = 0;
     $this->assertFalse(WooThemes_Sensei_Lesson::is_prerequisite_complete($lesson_id, $user_id), 'None existing lesson or user should return false');
     $test_user_id = wp_create_user('studentPrerequisite', 'studentPrerequisite', '*****@*****.**');
     $test_lesson = $this->factory->get_lessons();
     $test_lesson_id = $test_lesson[0];
     // truthy state
     $course_id = $this->factory->get_random_course_id();
     $lessons = $this->factory->get_lessons();
     $test_lesson_prerequisite_id = $lessons[1];
     // add lesson to random course
     update_post_meta($test_lesson_prerequisite_id, '_lesson_course', $course_id);
     update_post_meta($test_lesson_id, '_lesson_course', $course_id);
     // setup prerequisite
     update_post_meta($test_lesson_id, '_lesson_prerequisite', $test_lesson_prerequisite_id);
     Sensei_Utils::user_start_lesson($test_user_id, $test_lesson_prerequisite_id);
     $this->assertFalse(WooThemes_Sensei_Lesson::is_prerequisite_complete($test_lesson_id, $test_user_id), 'Users that has NOT completeded prerequisite should return false.');
     Sensei_Utils::user_start_lesson($test_user_id, $test_lesson_prerequisite_id, true);
     $this->assertTrue(Sensei_Lesson::is_prerequisite_complete($test_lesson_id, $test_user_id), 'Users that has completeded prerequisite should return true.');
 }
    $html .= '<p class="lesson-meta">';
    if ('' != $lesson_length) {
        $html .= '<span class="lesson-length">' . apply_filters('sensei_length_text', __('Length: ', 'woothemes-sensei')) . $lesson_length . __(' minutes', 'woothemes-sensei') . '</span>';
    }
    if (isset($woothemes_sensei->settings->settings['lesson_author']) && $woothemes_sensei->settings->settings['lesson_author']) {
        $html .= '<span class="lesson-author">' . apply_filters('sensei_author_text', __('Author: ', 'woothemes-sensei')) . '<a href="' . get_author_posts_url(absint($lesson_item->post_author)) . '" title="' . esc_attr($user_info->display_name) . '">' . esc_html($user_info->display_name) . '</a></span>';
    }
    // End If Statement
    if ('' != $lesson_complexity) {
        $html .= '<span class="lesson-complexity">' . apply_filters('sensei_complexity_text', __('Complexity: ', 'woothemes-sensei')) . $lesson_complexity . '</span>';
    }
    if ($single_lesson_complete) {
        $html .= '<span class="lesson-status complete">' . apply_filters('sensei_complete_text', __('Complete', 'woothemes-sensei')) . '</span>';
    } elseif ($user_lesson_status) {
        $html .= '<span class="lesson-status in-progress">' . apply_filters('sensei_in_progress_text', __('In Progress', 'woothemes-sensei')) . '</span>';
    }
    // End If Statement
    $html .= '</p>';
    $html .= '</header>';
    // Image
    $html .= $woothemes_sensei->post_types->lesson->lesson_image($lesson_item->ID);
    $html .= '<section class="entry">';
    $html .= WooThemes_Sensei_Lesson::lesson_excerpt($lesson_item);
    $html .= '</section>';
    $html .= '</article>';
    $lesson_count++;
}
// End For Loop
$html .= '</section>';
// Output the HTML
echo $html;
Пример #3
0
 /**
  * Show a message telling the user to complete the previous message if they haven't done so yet
  *
  * @since 1.9.0
  */
 public static function prerequisite_complete_message()
 {
     $lesson_prerequisite = WooThemes_Sensei_Lesson::get_lesson_prerequisite_id(get_the_ID());
     $lesson_has_pre_requisite = $lesson_prerequisite > 0;
     if (!WooThemes_Sensei_Lesson::is_prerequisite_complete(get_the_ID(), get_current_user_id()) && $lesson_has_pre_requisite) {
         $prerequisite_lesson_link = '<a href="' . esc_url(get_permalink($lesson_prerequisite)) . '" title="' . esc_attr(sprintf(__('You must first complete: %1$s', 'woothemes-sensei'), get_the_title($lesson_prerequisite))) . '">' . get_the_title($lesson_prerequisite) . '</a>';
         echo sprintf(__('You must first complete %1$s before viewing this Lesson', 'woothemes-sensei'), $prerequisite_lesson_link);
     }
 }
 public function calculate_user_module_progress_custom($user_id, $module_id, $course_id)
 {
     $lessons = Sensei_Core_Modules::get_lessons($course_id, $module_id);
     //if (is_wp_error($lessons) || 0 >= count($lessons)) return 0;
     $completed = false;
     $lesson_count = 0;
     $completed_count = 0;
     $strcom = '';
     foreach ($lessons as $lesson) {
         $lesson_id = $lesson->ID;
         $lesson_id = (int) $lesson_id;
         $quiz_id = WooThemes_Sensei_Lesson::lesson_quizzes($lesson_id, $post_status = 'any');
         $quiz_id = (int) $quiz_id;
         $lesson_quiz_questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions($quiz_id);
         if (count($lesson_quiz_questions) > 0) {
             $lesson_status = WooThemes_Sensei_Utils::user_lesson_status($lesson_id, $user_id);
             $lesson_status = $lesson_status->comment_approved;
             ++$lesson_count;
             if ($lesson_status == 'passed') {
                 ++$completed_count;
             } else {
                 $question = $lesson_quiz_questions[0];
                 $question_title = $question->post_title;
                 if ($question_title == 'Offline Upload') {
                     ++$completed_count;
                 }
                 //$strcom = $strcom.' -- Lesson ID: '.$lesson_id.' '.print_r($lesson_quiz_questions, true);
             }
         }
         //$strcom = $strcom.' -- '.$user_id.' '.$lesson_id.' '.$lesson_status. ' '.print_r($lesson_quizzes, true);
     }
     $module_progress = $completed_count / $lesson_count * 100;
     return (double) $module_progress;
     //return $strcom;
 }
Пример #5
0
/**
 * Template function to determine if the current user can
 * access the current lesson content being viewed.
 *
 * This function checks in the folowing order
 * - if the current user has all access based on their permissions
 * - If the access permission setting is enabled for this site, if not the user has accces
 * - if the lesson has a pre-requisite and if the user has completed that
 * - If it is a preview the user has access as well
 *
 * @since 1.9.0
 *
 * @param string $lesson_id
 * @return bool
 */
function sensei_can_user_view_lesson($lesson_id = '', $user_id = '')
{
    if (empty($lesson_id)) {
        $lesson_id = get_the_ID();
    }
    if (empty($user_id)) {
        $user_id = get_current_user_id();
    }
    // Check for prerequisite lesson completions
    $pre_requisite_complete = WooThemes_Sensei_Lesson::is_prerequisite_complete($lesson_id, $user_id);
    $lesson_course_id = get_post_meta($lesson_id, '_lesson_course', true);
    $user_taking_course = Sensei_Utils::user_started_course($lesson_course_id, $user_id);
    $is_preview = false;
    if (Sensei_Utils::is_preview_lesson($lesson_id)) {
        $is_preview = true;
        $pre_requisite_complete = true;
    }
    $user_can_access_lesson = false;
    if (is_user_logged_in() && $user_taking_course) {
        $user_can_access_lesson = true;
    }
    $access_permission = false;
    if (!Sensei()->settings->get('access_permission') || sensei_all_access()) {
        $access_permission = true;
    }
    $can_user_view_lesson = $access_permission || $user_can_access_lesson && $pre_requisite_complete || $is_preview;
    /**
     * Filter the can user view lesson function
     *
     * @since 1.9.0
     *
     * @hooked Sensei_WC::alter_can_user_view_lesson
     *
     * @param bool $can_user_view_lesson
     * @param string $lesson_id
     * @param string $user_id
     */
    return apply_filters('sensei_can_user_view_lesson', $can_user_view_lesson, $lesson_id, $user_id);
}
Пример #6
0
 /**
  * @deprecated since 1.9.0 use WooThemes_Sensei_Lesson::course_signup_link instead
  */
 public function sensei_lesson_course_signup_link()
 {
     _deprecated_function('sensei_lesson_course_signup_link', '1.9.0', 'WooThemes_Sensei_Lesson::course_signup_link');
     WooThemes_Sensei_Lesson::course_signup_link();
 }