Skip to content

Commit

Permalink
Merge pull request #137 from woothemes/release-1-4-2
Browse files Browse the repository at this point in the history
Release 1 4 2
  • Loading branch information
jeffikus committed Oct 16, 2013
2 parents 387fff1 + 3aecd72 commit 59a3fd1
Show file tree
Hide file tree
Showing 17 changed files with 267 additions and 197 deletions.
14 changes: 9 additions & 5 deletions assets/js/lesson-metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,9 @@ jQuery(document).ready( function($) {
} // End Switch Statement
// Handle Required Fields
jQuery( '#add-new-question' ).find( 'div.question_required_fields' ).children( 'input' ).each( function() {
dataToPost += '&' + jQuery( this ).attr( 'name' ) + '=' + encodeURIComponent( jQuery( this ).attr( 'value' ) );
if ( jQuery( this ).attr( 'type' ) != 'radio' ) {
dataToPost += '&' + jQuery( this ).attr( 'name' ) + '=' + encodeURIComponent( jQuery( this ).attr( 'value' ) );
} // End If Statement
});
// Handle Question Input Fields
var radioCount = 0;
Expand Down Expand Up @@ -636,7 +638,7 @@ jQuery(document).ready( function($) {
outputEditForm += '</div>';
break;
} // End Switch Statement
outputEditForm += '<input type="hidden" name="question_type" id="question_' + tableCount + '_question_type" value="' + questionType + '">';
outputEditForm += '<input type="hidden" class="question_type" name="question_type" id="question_' + tableCount + '_question_type" value="' + questionType + '">';
outputEditForm += '<input type="hidden" name="question_id" id="question_' + tableCount + '_id" value="' + questionId + '">';
outputEditForm += '<div class="update-question"><a title="Cancel" href="#question-edit-cancel" class="lesson_question_cancel">Cancel</a>';
outputEditForm += '<a title="Update Question" href="#add-question-metadata" class="question_table_save button button-highlighted">Update</a></div>';
Expand Down Expand Up @@ -703,7 +705,9 @@ jQuery(document).ready( function($) {
} // End Switch Statement
// Handle Required Fields
jQuery( this ).parent('div').parent().find( 'div.question_required_fields' ).children( 'input' ).each( function() {
dataToPost += '&' + jQuery( this ).attr( 'name' ) + '=' + encodeURIComponent( jQuery( this ).attr( 'value' ) );
if ( jQuery( this ).attr( 'type' ) != 'radio' ) {
dataToPost += '&' + jQuery( this ).attr( 'name' ) + '=' + encodeURIComponent( jQuery( this ).attr( 'value' ) );
} // End If Statement
});
// Handle Question Input Fields
var radioCount = 0;
Expand All @@ -723,12 +727,12 @@ jQuery(document).ready( function($) {
dataToPost += '&' + jQuery(this).parent('div').parent().find( 'div.' + divFieldsClass ).find( 'textarea' ).attr( 'name' ) + '=' + encodeURIComponent( jQuery(this).parent('div').parent().find( 'div.' + divFieldsClass ).find( 'textarea' ).val() );
} // End If Statement
if ( jQuery(this).parent('div').parent().find( 'div.' + divFieldsClass ).find( 'textarea' ).val() != '' && divFieldsClass == 'question_multiline_fields' ) {
dataToPost += '&' + jQuery(this).parent('div').parent('div').parent().find( 'div.' + divFieldsClass ).find( 'textarea' ).attr( 'name' ) + '=' + encodeURIComponent( jQuery(this).parent('div').parent().find( 'div.' + divFieldsClass ).find( 'textarea' ).val() );
dataToPost += '&' + jQuery(this).parent('div').parent().find( 'div.' + divFieldsClass ).find( 'textarea' ).attr( 'name' ) + '=' + encodeURIComponent( jQuery(this).parent('div').parent().find( 'div.' + divFieldsClass ).find( 'textarea' ).val() );
} // End If Statement
dataToPost += '&' + 'question_type' + '=' + questionType;
questionGrade = jQuery( this ).parent('div').parent().find( 'input.question_grade' ).val();
dataToPost += '&' + 'question_grade' + '=' + questionGrade;
// Perform the AJAX call.
// Perform the AJAX call.
jQuery.post(
ajaxurl,
{
Expand Down
16 changes: 16 additions & 0 deletions changelog.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
*** Sensei Changelog ***

2013.10.15 - version 1.4.2
* /assets/js/lesson-metadata.js - fixes post issues with multiline and boolean add and edit ajax functions.
* /templates/woocommerce/add-to-cart.php - fixes adding of variable subscription courses to cart.
* /templates/single-quiz/question_type-boolean.php,
/templates/single-quiz/question_type-essay-paste.php,
/templates/single-quiz/question_type-gap-fill.php,
/templates/single-quiz/question_type-multi-line.php,
/templates/single-quiz/question_type-multiple-choice.php,
/templates/single-quiz/question_type-single-line.php - sets default grade of 1 to every question for cases where no grade is set
* /classes/class-woothemes-sensei-admin.php - fixes issue where sensei comment types were visible to authors in the backend.
* /classes/class-woothemes-sensei-grading.php - fixes layout issue in the grading admin interface where the footer was misplaced.
* /classes/class-woothemes-sensei-updates.php - fixes array sort method error notices on the updates screen.
* /classes/class-woothemes-sensei-utils.php - fixes quiz submitted link translation string on single lesson page & auto grading issue when some questions are left unanswered.
* /classes/class-woothemes-sensei-frontend.php - fixes object instantiation PHP warning, and issue on quiz button incorrectly displaying on single lesson page.
* /classes/class-woothemes-sensei-lesson.php - fixes save function to handle changes made in lessons ajax.

2013.10.10 - version 1.4.1
* /templates/single-course/course-lessons.php - Fixing typo in lessons template
* /assets/css/frontend.less,
Expand Down
2 changes: 1 addition & 1 deletion classes/class-woothemes-sensei-admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function page_redirect() {
function comments_admin_filter( $pieces ) {

// Filter Admin Comments Area to not display Sensei's use of commenting system
if( is_admin() && current_user_can( 'moderate_comments' ) && !( isset($_GET['page']) && 'sensei_analysis' == $_GET['page'] ) ) {
if( is_admin() && !( isset($_GET['page']) && 'sensei_analysis' == $_GET['page'] ) ) {
$pieces['where'] .= " AND comment_type NOT LIKE 'sensei_%' ";
} // End If Statement

Expand Down
14 changes: 9 additions & 5 deletions classes/class-woothemes-sensei-frontend.php
Original file line number Diff line number Diff line change
Expand Up @@ -1102,14 +1102,17 @@ public function sensei_lesson_quiz_meta( $post_id = 0, $user_id = 0 ) {
if ( 0 < count($lesson_quizzes) && is_user_logged_in() && sensei_has_user_started_course( $lesson_course_id, $user_id ) ) { ?>
<?php $no_quiz_count = 0; ?>
<?php foreach ($lesson_quizzes as $quiz_item){
// Display lesson quiz status message
$status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $post_id, $user_id, true );
echo '<div class="woo-sc-box ' . $status['box_class'] . '">' . $status['message'] . '</div>';
echo $status['extra'];
$quiz_questions = $woothemes_sensei->frontend->lesson->lesson_quiz_questions( $quiz_item->ID );
if( 0 < count( $quiz_questions ) ) {
// Display lesson quiz status message
$status = WooThemes_Sensei_Utils::sensei_user_quiz_status_message( $post_id, $user_id, true );
echo '<div class="woo-sc-box ' . $status['box_class'] . '">' . $status['message'] . '</div>';
echo $status['extra'];
} // End If Statement
} // End For Loop ?>
<?php } elseif( 0 < count($lesson_quizzes) && $woothemes_sensei->access_settings() ) { ?>
<?php foreach ($lesson_quizzes as $quiz_item){
$quiz_questions = $woothemes_sensei->frontend->lesson->lesson_quiz_questions( $post_id );
$quiz_questions = $woothemes_sensei->frontend->lesson->lesson_quiz_questions( $quiz_item->ID );
if( 0 < count( $quiz_questions ) ) { ?>
<a class="button" href="<?php echo esc_url( get_permalink( $quiz_item->ID ) ); ?>" title="<?php echo esc_attr( apply_filters( 'sensei_view_lesson_quiz_text', __( 'View the Lesson Quiz', 'woothemes-sensei' ) ) ); ?>"><?php echo apply_filters( 'sensei_view_lesson_quiz_text', __( 'View the Lesson Quiz', 'woothemes-sensei' ) ); ?></a>
<?php } ?>
Expand Down Expand Up @@ -1300,6 +1303,7 @@ public function sensei_course_start() {
'user_id' => $current_user->ID
);
$activity_logged = WooThemes_Sensei_Utils::sensei_log_activity( $args );
$this->data = new stdClass();
$this->data->is_user_taking_course = false;
if ( $activity_logged ) {
$this->data->is_user_taking_course = true;
Expand Down
77 changes: 38 additions & 39 deletions classes/class-woothemes-sensei-grading.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,56 +253,55 @@ public function grading_default_nav() {
<li><a href="<?php echo add_query_arg( array( 'page' => 'sensei_grading', 'lesson_id' => -1 ), admin_url( 'admin.php' ) ); ?>" <?php if ( isset( $_GET['lesson_id'] ) ) { ?>class="current"<?php } ?>><?php _e( 'Lessons', 'woothemes-sensei' ); ?></a></li>
</ul> -->
<div class="grading-selects">
<?php
// Get the Course Posts
$post_args = array( 'post_type' => 'course',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'DESC',
'post_status' => 'any',
'suppress_filters' => 0
);
$posts_array = get_posts( $post_args );
<?php
// Get the Course Posts
$post_args = array( 'post_type' => 'course',
'numberposts' => -1,
'orderby' => 'title',
'order' => 'DESC',
'post_status' => 'any',
'suppress_filters' => 0
);
$posts_array = get_posts( $post_args );

$selected_course_id = 0;
if ( isset( $_GET['course_id'] ) ) {
$selected_course_id = intval( $_GET['course_id'] );
} // End If Statement
$selected_course_id = 0;
if ( isset( $_GET['course_id'] ) ) {
$selected_course_id = intval( $_GET['course_id'] );
} // End If Statement

echo '<div class="select-box">' . "\n";
echo '<div class="select-box">' . "\n";

echo '<label>' . __( 'Select a Course to Grade', 'woothemes-sensei' ) . '</label>';
echo '<label>' . __( 'Select a Course to Grade', 'woothemes-sensei' ) . '</label>';

echo '<select id="grading-course-options" name="grading_course" class="widefat">' . "\n";
echo '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
if ( count( $posts_array ) > 0 ) {
foreach ($posts_array as $post_item){
echo '<option value="' . esc_attr( absint( $post_item->ID ) ) . '" ' . selected( $post_item->ID, $selected_course_id, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n";
} // End For Loop
} // End If Statement
echo '</select>' . "\n";
echo '<select id="grading-course-options" name="grading_course" class="widefat">' . "\n";
echo '<option value="">' . __( 'None', 'woothemes-sensei' ) . '</option>';
if ( count( $posts_array ) > 0 ) {
foreach ($posts_array as $post_item){
echo '<option value="' . esc_attr( absint( $post_item->ID ) ) . '" ' . selected( $post_item->ID, $selected_course_id, false ) . '>' . esc_html( $post_item->post_title ) . '</option>' . "\n";
} // End For Loop
} // End If Statement
echo '</select>' . "\n";

echo '</div>' . "\n";
echo '</div>' . "\n";

echo '<div class="select-box">' . "\n";
echo '<div class="select-box">' . "\n";

echo '<label id="grading-lesson-options-label">' . __( 'Select a Lesson to Grade', 'woothemes-sensei' ) . '</label>';
echo '<label id="grading-lesson-options-label">' . __( 'Select a Lesson to Grade', 'woothemes-sensei' ) . '</label>';

echo '<select id="grading-lesson-options" name="grading_lesson" class="widefat">' . "\n";
echo '<select id="grading-lesson-options" name="grading_lesson" class="widefat">' . "\n";

if ( 0 < $selected_course_id ) {
$selected_lesson_id = 0;
if ( isset( $_GET['lesson_id'] ) ) {
$selected_lesson_id = intval( $_GET['lesson_id'] );
} // End If Statement
echo $this->lessons_drop_down_html( $selected_course_id, $selected_lesson_id );
} // End If Statement
if ( 0 < $selected_course_id ) {
$selected_lesson_id = 0;
if ( isset( $_GET['lesson_id'] ) ) {
$selected_lesson_id = intval( $_GET['lesson_id'] );
} // End If Statement
echo $this->lessons_drop_down_html( $selected_course_id, $selected_lesson_id );
} // End If Statement

echo '</select>' . "\n";
echo '</select>' . "\n";

echo '</div>' . "\n";
?>
</div>
echo '</div>' . "\n";
?>
</div><!-- /.grading-selects -->
<?php
} // End grading_default_nav()
Expand Down
12 changes: 7 additions & 5 deletions classes/class-woothemes-sensei-lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -1049,6 +1049,12 @@ private function lesson_save_question( $data = array() ) {
$question_right_answer = '';
$question_wrong_answers = array();
$question_type = 'multiple-choice';

// Handle Question Type
if ( isset( $data[ 'question_type' ] ) && ( '' != $data[ 'question_type' ] ) ) {
$question_type = $data[ 'question_type' ];
} // End If Statement

if ( isset( $data[ 'question_id' ] ) && ( 0 < absint( $data[ 'question_id' ] ) ) ) {
$question_id = absint( $data[ 'question_id' ] );
} // End If Statement
Expand Down Expand Up @@ -1087,10 +1093,6 @@ private function lesson_save_question( $data = array() ) {
if ( isset( $data[ 'add_question_right_answer_singleline' ] ) && ( '' != $data[ 'add_question_right_answer_singleline' ] ) ) {
$question_right_answer = $data[ 'add_question_right_answer_singleline' ];
} // End If Statement
// Handle Question Type
if ( isset( $data[ 'question_type' ] ) && ( '' != $data[ 'question_type' ] ) ) {
$question_type = $data[ 'question_type' ];
} // End If Statement
// Handle Question Grade
if ( isset( $data[ 'question_grade' ] ) && ( '' != $data[ 'question_grade' ] ) ) {
$question_grade = $data[ 'question_grade' ];
Expand Down Expand Up @@ -1130,7 +1132,7 @@ private function lesson_save_question( $data = array() ) {
update_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
} else {
$question_id = wp_insert_post($post_type_args);
add_post_meta( $question_id, '_quiz_id', $quiz_id );
add_post_meta( $question_id, '_quiz_id', $quiz_id );
add_post_meta( $question_id, '_question_grade', $question_grade );
add_post_meta( $question_id, '_question_right_answer', $question_right_answer );
add_post_meta( $question_id, '_question_wrong_answers', $question_wrong_answers );
Expand Down
3 changes: 2 additions & 1 deletion classes/class-woothemes-sensei-updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,8 @@ function sensei_nextpage() {
<tbody class="plugins">
<?php
// Sort updates with the latest at the top
uasort( $this->updates, array( $this, 'sort_updates' ) );
uksort( $this->updates, array( $this, 'sort_updates' ) );
$this->updates = array_reverse( $this->updates, true );
foreach( $this->updates as $version => $version_updates ) {
foreach( $version_updates as $type => $updates ) {
foreach( $updates as $update => $data ) {
Expand Down
64 changes: 49 additions & 15 deletions classes/class-woothemes-sensei-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -389,21 +389,15 @@ public function sensei_grade_quiz_auto( $quiz_id = 0, $submitted = false, $total
if( intval( $quiz_id ) > 0 && $submitted ) {

if( $quiz_grade_type == 'auto' ) {
$quiz_total = 0;
$grade_total = 0;
foreach( $submitted as $question_id => $answer ) {
// Get total question grade
$question_grade_total = (int) get_post_meta( $question_id, '_question_grade', true );
if( ! $question_grade_total || $question_grade_total == '' ) {
$question_grade_total = 1;
}
$quiz_total += $question_grade_total;

// Get user question grade
$question_grade = WooThemes_Sensei_Utils::sensei_grade_question_auto( $question_id, $answer );
$grade_total += $question_grade;
}

$quiz_total = WooThemes_Sensei_Utils::sensei_get_quiz_total( $quiz_id );

$grade = abs( round( ( doubleval( $grade_total ) * 100 ) / ( $quiz_total ), 2 ) );

$activity_logged = WooThemes_Sensei_Utils::sensei_grade_quiz( $quiz_id, $grade );
Expand Down Expand Up @@ -597,6 +591,22 @@ public function sensei_get_quiz_questions( $quiz_id = 0 ) {
return $questions;
}

public function sensei_get_quiz_total( $quiz_id = 0 ) {

$quiz_total = 0;

if( $quiz_id > 0 ) {
$questions = WooThemes_Sensei_Utils::sensei_get_quiz_questions( $quiz_id );
$question_grade = 0;
foreach( $questions as $question ) {
$question_grade = get_post_meta( $question->ID, '_question_grade', true );
$quiz_total += $question_grade;
}
}

return $quiz_total;
}

public function sensei_get_user_question_grade( $question_id = 0, $user_id = 0 ) {
if( intval( $user_id ) == 0 ) {
global $current_user;
Expand Down Expand Up @@ -887,7 +897,7 @@ public function sensei_user_course_status_message( $course_id = 0, $user_id = 0
* @param integer $user_id ID of user
* @return array Status code and message
*/
public function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) {
public static function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $is_lesson = false ) {
global $woothemes_sensei, $current_user;
if( intval( $user_id ) == 0 ) {
$user_id = $current_user->ID;
Expand Down Expand Up @@ -971,19 +981,43 @@ public function sensei_user_quiz_status_message( $lesson_id = 0, $user_id = 0, $
$status = 'complete';
$box_class = 'info';
if( $is_lesson ) {
$message = __( 'You have completed this lesson\'s quiz and it will be graded soon. %2$sView the lesson quiz%2$s', 'woothemes-sensei' );
$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$d%% to pass.', 'woothemes-sensei' ), round( $quiz_passmark ) );
}
}

} else {
$status = 'not_started';
$box_class = 'info';
if( $is_lesson ) {
$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ), round( $quiz_passmark ) );
if ( isset( $quiz_grade ) && $quiz_grade && abs( $quiz_grade ) >= 0 ) {
if ( $quiz_grade >= abs( round( $quiz_passmark_float, 2 ) ) ) {

$status = 'passed';
$box_class = 'tick';
if( $is_lesson ) {
$message = sprintf( __( 'Congratulations! You have passed this lesson\'s quiz achieving %d%%', 'woothemes-sensei' ), round( $quiz_grade ) );
} else {
$message = sprintf( __( 'Congratulations! You have passed this quiz achieving %d%%', 'woothemes-sensei' ), round( $quiz_grade ) );
}

} else {

$status = 'failed';
$box_class = 'alert';
if( $is_lesson ) {
$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz. Your grade is %2$d%%', 'woothemes-sensei' ), round( $quiz_passmark ), round( $quiz_grade ) );
} else {
$message = sprintf( __( 'You require %1$d%% to pass this quiz. Your grade is %2$d%%', 'woothemes-sensei' ), round( $quiz_passmark ), round( $quiz_grade ) );
}

}
} else {
$message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ), round( $quiz_passmark ) );
$status = 'not_started';
$box_class = 'info';
if( $is_lesson ) {
$message = sprintf( __( 'You require %1$d%% to pass this lesson\'s quiz.', 'woothemes-sensei' ), round( $quiz_passmark ) );
} else {
$message = sprintf( __( 'You require %1$d%% to pass this quiz.', 'woothemes-sensei' ), round( $quiz_passmark ) );
}
}
}

Expand Down
Loading

0 comments on commit 59a3fd1

Please sign in to comment.