Skip to content

Commit

Permalink
closes #978 for good by replacing all code that gets the question typ…
Browse files Browse the repository at this point in the history
…e to use the special function used for this
  • Loading branch information
dwainm committed Sep 7, 2015
1 parent aff011b commit 50537a3
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 75 deletions.
11 changes: 1 addition & 10 deletions classes/class-woothemes-sensei-grading-user-quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,10 @@ public function display() {
$type = false;
$type_name = '';

$types = wp_get_post_terms( $question_id, 'question-type' );
foreach( $types as $t ) {
$type = $t->name;
break;
}

if( ! $type ) {
$type = 'multiple-choice';
}
$type = Sensei()->question->get_question_type( $question_id );

$question_answer_notes = $woothemes_sensei->quiz->get_user_question_feedback( $lesson_id, $question_id, $user_id );


$question_grade_total = get_post_meta( $question_id, '_question_grade', true );
if( ! $question_grade_total || 0 == intval( $question_grade_total ) ) {
$question_grade_total = 1;
Expand Down
26 changes: 3 additions & 23 deletions classes/class-woothemes-sensei-lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -778,11 +778,7 @@ public function quiz_panel_questions( $questions = array() ) {

$question_id = $question->ID;

$question_type = '';
$question_types = wp_get_post_terms( $question_id, 'question-type', array( 'fields' => 'names' ) );
if ( isset( $question_types[0] ) && '' != $question_types[0] ) {
$question_type = $question_types[0];
} // End If Statement
$question_type = Sensei()->question->get_question_type( $question_id );

$multiple_data = array();
$question_increment = 1;
Expand Down Expand Up @@ -1937,16 +1933,7 @@ public function lesson_update_question () {
$current_user = wp_get_current_user();
$question_data['post_author'] = $current_user->ID;
$question_id = $this->lesson_save_question( $question_data );
$question_types = wp_get_post_terms( $question_id, 'question-type', array( 'fields' => 'names' ) );
$question_counter = 0;
$question_type = '';
if ( isset( $question_types[0] ) && '' != $question_types[0] ) {
$question_type = $question_types[0];
} // End If Statement

if( ! $question_type ) {
$question_type = 'multiple-choice';
}
$question_type = Sensei()->question->get_question_type( $question_id );

$question_count = intval( $question_data['question_count'] );
++$question_count;
Expand Down Expand Up @@ -2102,14 +2089,7 @@ public function lesson_add_existing_questions() {
}

add_post_meta( $question_id, '_quiz_question_order' . $quiz_id, $quiz_id . '000' . $question_count );

$question_types = wp_get_post_terms( $question_id, 'question-type', array( 'fields' => 'names' ) );
$question_type = '';
if ( isset( $question_types[0] ) && '' != $question_types[0] ) {
$question_type = $question_types[0];
} else {
$question_type = 'multiple-choice';
}
$question_type = Sensei()->question->get_question_type( $question_id );

$return .= $this->quiz_panel_question( $question_type, $question_count, $question_id );
}
Expand Down
17 changes: 3 additions & 14 deletions classes/class-woothemes-sensei-question.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,8 @@ public function question_edit_panel_metabox( $post_type, $post ) {
$metabox_title = __( 'Question', 'woothemes-sensei' );

if( isset( $post->ID ) ) {
$question_type = '';
$question_types = wp_get_post_terms( $post->ID, 'question-type', array( 'fields' => 'slugs' ) );
if ( isset( $question_types[0] ) && '' != $question_types[0] ) {
$question_type = $question_types[0];
} // End If Statement

$question_type = Sensei()->question->get_question_type( $post->ID );

if( $question_type ) {
$type = $this->question_types[ $question_type ];
Expand Down Expand Up @@ -166,15 +163,7 @@ public function question_edit_panel() {
} else {
$question_id = $post->ID;

$question_type = '';
$question_types = wp_get_post_terms( $question_id, 'question-type', array( 'fields' => 'slugs' ) );
if ( isset( $question_types[0] ) && '' != $question_types[0] ) {
$question_type = $question_types[0];
}

if( ! $question_type ) {
$question_type = 'multiple-choice';
}
$question_type = Sensei()->question->get_question_type( $post->ID );

$html .= '<div id="add-question-metadata"><table class="widefat">';
$html .= $woothemes_sensei->post_types->lesson->quiz_panel_question( $question_type, 0, $question_id, 'question' );
Expand Down
9 changes: 1 addition & 8 deletions classes/class-woothemes-sensei-utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -517,14 +517,7 @@ public static function sensei_save_quiz_answers( $submitted = false, $user_id =
foreach( $submitted as $question_id => $answer ) {

// Get question type
$question_types = wp_get_post_terms( $question_id, 'question-type' );
foreach( $question_types as $type ) {
$question_type = $type->slug;
}

if( ! $question_type ) {
$question_type = 'multiple-choice';
}
$question_type = Sensei()->question->get_question_type( $question_id );

// Sanitise answer
if( 0 == get_magic_quotes_gpc() ) {
Expand Down
13 changes: 2 additions & 11 deletions tests/factory/Sensei-Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,7 @@ public function generate_user_quiz_answers( $quiz_id ){
foreach( $quiz_question_posts as $question ){

// get the current question type
$question_types_array = wp_get_post_terms( $question->ID, 'question-type', array( 'fields' => 'slugs' ) );

if ( isset( $question_types_array[0] ) && '' != $question_types_array[0] ) {
$type = $question_types_array[0];
}else{
$type = 'multiple-choice';
}
$type = Sensei()->question->get_question_type( $question->ID );

// setup the demo data and store it in the respective array
if ('multiple-choice' == $type ) {
Expand Down Expand Up @@ -494,10 +488,7 @@ public function generate_test_files( $test_user_quiz_answers ){
foreach( $test_user_quiz_answers as $question_id => $answer ){

//Setup the question types
$question_types = wp_get_post_terms( $question_id, 'question-type' );
foreach( $question_types as $type ) {
$question_type = $type->slug;
}
$question_type = Sensei()->question->get_question_type( $question_id );

if( 'file-upload' == $question_type){
//setup the sample image file location within the test folders
Expand Down
10 changes: 1 addition & 9 deletions tests/test-class-quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -599,15 +599,7 @@ public function testGetUserQuestionAnswer(){
$question_id = $random_question_id;
$answer = $users_saved_answers[ $question_id ];
$old_data_user_id = wp_create_user( 'olddata', 'olddata', '[email protected]' );
$question_types = wp_get_post_terms( $question_id , 'question-type' );

foreach( $question_types as $type ) {
$question_type = $type->slug;
}

if( ! $question_type ) {
$question_type = 'multiple-choice';
}
$question_type = Sensei()->question->get_question_type( $question_id );

// Sanitise answer
if( 0 == get_magic_quotes_gpc() ) {
Expand Down

0 comments on commit 50537a3

Please sign in to comment.