Skip to content

Commit

Permalink
Merge branch '411-lesson-navigation' into release-1-6-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Johnson committed Jul 8, 2014
2 parents a2ad132 + 749123e commit 26568a3
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
2014.06.30 - version 1.6.1
* Fix - Making sure Learner Management page shows for users with 'manage_sensei_grades' capability
* Fix - Fixing bug that prevented all email notifications from being deactivated
* Fix - Fixing lesson order in single lesson next/previous lesson navigation
* Fix - Ensuring that modules display on single course page for courses with prerequisites
* Fix - Making sure learner management user search works without WooCommerce activated

Expand Down
77 changes: 70 additions & 7 deletions inc/woothemes-sensei-template.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,23 +502,86 @@ function sensei_get_prev_next_lessons( $lesson_id = 0 ) {
if ( 0 < $lesson_id ) {
// Get the List of Lessons in the Course
$lesson_course_id = get_post_meta( $lesson_id, '_lesson_course', true );
$course_lessons = $woothemes_sensei->frontend->course->course_lessons( $lesson_course_id );
// Index the Lessons
if ( 0 < count( $course_lessons ) ) {
$all_lessons = array();
if( class_exists( 'Sensei_Modules' ) ) {
global $sensei_modules;

$modules = $sensei_modules->get_course_modules( intval( $lesson_course_id ) );

foreach( $modules as $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_' . $module->term_id,
'orderby' => 'meta_value_num date',
'order' => 'ASC',
'suppress_filters' => 0
);

$lessons = get_posts( $args );
if ( 0 < count( $lessons ) ) {
foreach ($lessons as $lesson_item){
$all_lessons[] = $lesson_item->ID;
} // End For Loop
} // End If Statement
}
}

$args = array(
'post_type' => 'lesson',
'posts_per_page' => -1,
'suppress_filters' => 0,
'meta_key' => '_order_' . $lesson_course_id,
'orderby' => 'meta_value_num date',
'order' => 'ASC',
'meta_query' => array(
array(
'key' => '_lesson_course',
'value' => intval( $lesson_course_id ),
),
),
'post__not_in' => $all_lessons,
);

$other_lessons = get_posts( $args );
if ( 0 < count( $other_lessons ) ) {
foreach ($other_lessons as $lesson_item){
$all_lessons[] = $lesson_item->ID;
} // End For Loop
} // End If Statement

if ( 0 < count( $all_lessons ) ) {
$found_index = false;
foreach ($course_lessons as $lesson_item){
foreach ( $all_lessons as $lesson ){
if ( $found_index && $return_values['next_lesson'] == 0 ) {
$return_values['next_lesson'] = $lesson_item->ID;
$return_values['next_lesson'] = $lesson;
} // End If Statement
if ( $lesson_item->ID == $lesson_id ) {
if ( $lesson == $lesson_id ) {
// Is the current post
$found_index = true;
} // End If Statement
if ( !$found_index ) {
$return_values['prev_lesson'] = $lesson_item->ID;
$return_values['prev_lesson'] = $lesson;
} // End If Statement
} // End For Loop
} // End If Statement

} // End If Statement
return $return_values;
} // End sensei_get_prev_next_lessons()
Expand Down

0 comments on commit 26568a3

Please sign in to comment.