/** * Auto eval the result of the course and mark it as finished if the time is over */ function learn_press_auto_evaluation_course() { $user_id = get_current_user_id(); $courses = learn_press_get_user_courses($user_id); if (!$courses) { return; } $now = time(); foreach ($courses as $course_id) { if (learn_press_user_has_finished_course($course_id)) { continue; } $course_duration = intval(get_post_meta($course_id, '_lpr_course_duration', true)) * 7 * 24 * 3600; $course_time = get_user_meta($user_id, '_lpr_course_time', true); if (empty($course_time[$course_id])) { $course_time[$course_id] = array('start' => time(), 'end' => null); update_user_meta($user_id, '_lpr_course_time', $course_time); } $course_time = $course_time[$course_id]; $start_time = intval($course_time['start']); if ($course_duration && $start_time + $course_duration <= $now) { learn_press_finish_course($course_id, $user_id); } else { //echo "Time to finish: " . ( ( $start_time + $course_duration - $now ) / ( 7 * 24 * 3600 ) ); } } }
/** * Display the content of a lesson in a course content * @return int */ function learn_press_course_content_summary() { $lesson_id = isset($_GET['lesson']) ? $_GET['lesson'] : ''; global $post; // ensure that we are passing the lesson correctly if ($lesson_id && 'lpr_lesson' == get_post_type($lesson_id) && ($lesson = get_post($lesson_id))) { //check if user enrolled this course or not $course_id = get_the_ID(); $user_id = get_current_user_id(); $user_courses = learn_press_get_user_courses($user_id); $enrolled = false; if (isset($user_courses) && is_array($user_courses)) { $enrolled = in_array($course_id, $user_courses); } //if( !$enrolled && ! learn_press_is_lesson_preview( $lesson_id ) ) { if (!learn_press_user_can_view_lesson($lesson_id)) { echo "You have to enrolled to see lesson content"; do_action('learn_press_course_content_course'); return 0; } // setup lesson as global post so we can uses the template function as in the loop $post = $lesson; setup_postdata($post); do_action('learn_press_course_content_lesson', $post); // now reset the post to the course wp_reset_postdata(); } else { do_action('learn_press_course_content_course'); } }