Skip to content

Commit

Permalink
Merge pull request #333 from woothemes/release-1-5-1
Browse files Browse the repository at this point in the history
Release 1 5 1
  • Loading branch information
Dan Johnson committed Mar 7, 2014
2 parents 7c405ab + 1debd74 commit e0ad8c6
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 2 deletions.
5 changes: 5 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
*** Sensei Changelog ***

2014.03.07 - version 1.5.1
* New - Adding utility function to check if a user has completed a lesson
* Fix - Fixing PHP errors on My Courses page
* Fix - Fixing course progress bars on My Courses page

2014.03.04 - version 1.5.0
* [QUIZZES] New - Completely refactored the quiz edit panel
* [QUIZZES] New - Adding 'File Upload' question type
Expand Down
10 changes: 10 additions & 0 deletions classes/class-woothemes-sensei-course.php
Original file line number Diff line number Diff line change
Expand Up @@ -1000,12 +1000,14 @@ public function load_user_courses_content( $user = false, $manage = false ) {

$active_count = $completed_count = 0;

$active_courses = array();
if ( 0 < intval( count( $active_ids ) ) ) {
$my_courses_section = 'active';
$active_courses = $woothemes_sensei->post_types->course->course_query( $per_page, 'usercourses', $active_ids );
$active_count = count( $active_ids );
} // End If Statement

$completed_courses = array();
if ( 0 < intval( count( $completed_ids ) ) ) {
$my_courses_section = 'completed';
$completed_courses = $woothemes_sensei->post_types->course->course_query( $per_page, 'usercourses', $completed_ids );
Expand All @@ -1025,6 +1027,14 @@ public function load_user_courses_content( $user = false, $manage = false ) {
foreach ( $active_courses as $course_item ) {
$course = $course_item;

$course_lessons = $woothemes_sensei->frontend->course->course_lessons( $course_item->ID );
$lessons_completed = 0;
foreach ( $course_lessons as $lesson ) {
if ( WooThemes_Sensei_Utils::user_completed_lesson( $lesson->ID, $user->ID ) ) {
++$lessons_completed;
}
}

// Get Course Categories
$category_output = get_the_term_list( $course_item->ID, 'course-category', '', ', ', '' );

Expand Down
41 changes: 41 additions & 0 deletions classes/class-woothemes-sensei-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -1229,5 +1229,46 @@ public function user_completed_course( $course_id = 0, $user_id = 0 ) {
return false;
}

public function user_completed_lesson( $lesson_id = 0, $user_id = 0 ) {
global $woothemes_sensei;

if( $lesson_id ) {
if( ! $user_id ) {
global $current_user;
wp_get_current_user();
$user = $current_user;
} else {
$user = get_userdata( $user_id );
}

$user_lesson_end = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $lesson_id, 'user_id' => $user->ID, 'type' => 'sensei_lesson_end', 'field' => 'comment_content' ) );
if ( '' != $user_lesson_end ) {
//Check for Passed or Completed Setting
$course_completion = $woothemes_sensei->settings->settings[ 'course_completion' ];
if ( 'passed' == $course_completion ) {
// If Setting is Passed -> Check for Quiz Grades
$lesson_quizzes = $woothemes_sensei->post_types->lesson->lesson_quizzes( $lesson_id );
// Get Quiz ID
if ( is_array( $lesson_quizzes ) || is_object( $lesson_quizzes ) ) {
foreach ($lesson_quizzes as $quiz_item) {
$lesson_quiz_id = $quiz_item->ID;
} // End For Loop
// Quiz Grade
$lesson_grade = WooThemes_Sensei_Utils::sensei_get_activity_value( array( 'post_id' => $lesson_quiz_id, 'user_id' => $user->ID, 'type' => 'sensei_quiz_grade', 'field' => 'comment_content' ) ); // Check for wrapper
// Check if Grade is bigger than pass percentage
$lesson_prerequisite = abs( round( doubleval( get_post_meta( $lesson_quiz_id, '_quiz_passmark', true ) ), 2 ) );
if ( $lesson_prerequisite <= intval( $lesson_grade ) ) {
return true;
} // End If Statement
} // End If Statement
} else {
return true;
} // End If Statement;
} // End If Statement
}

return false;
}

} // End Class
?>
4 changes: 2 additions & 2 deletions woothemes-sensei.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Plugin Name: Sensei
Plugin URI: http://www.woothemes.com/products/sensei/
Description: A course management plugin that offers the smoothest platform for helping you teach anything.
Version: 1.5.0
Version: 1.5.1
Author: WooThemes
Author URI: http://www.woothemes.com/
License: GPL version 2 or later - http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
Expand Down Expand Up @@ -31,7 +31,7 @@
if ( ! is_admin() ) require_once( 'inc/woothemes-sensei-template.php' );
global $woothemes_sensei;
$woothemes_sensei = new WooThemes_Sensei( __FILE__ );
$woothemes_sensei->version = '1.5.0';
$woothemes_sensei->version = '1.5.1';

/**
* Plugin updates
Expand Down

0 comments on commit e0ad8c6

Please sign in to comment.