Skip to content

Commit

Permalink
= 4.2.6.4 =
Browse files Browse the repository at this point in the history
~ Fixed: error romove question_anwsermeta when create new post question.
  • Loading branch information
tungnxt89 committed Mar 29, 2024
1 parent d5be061 commit bc0c110
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 18 deletions.
2 changes: 1 addition & 1 deletion inc/admin/editor/class-lp-admin-editor-question.php
Expand Up @@ -151,7 +151,7 @@ public function change_question_type( $args = array() ) {
}

if ( isset( $question ) ) {
$question = $this->question_curd->change_question_type( $question, $type );
$this->question_curd->change_question_type( $question, $type );
$this->result = $this->get_question_data_to_question_editor( $question, true );

return true;
Expand Down
2 changes: 1 addition & 1 deletion inc/admin/editor/class-lp-admin-editor-quiz.php
Expand Up @@ -261,7 +261,7 @@ public function change_question_type( $args = array() ) {

$question = LP_Question::get_question( $question_id );

$question = $this->question_curd->change_question_type( $question, $type );
$this->question_curd->change_question_type( $question, $type );

$this->result = $this->get_question_data_to_quiz_editor( $question, true );

Expand Down
20 changes: 10 additions & 10 deletions inc/curds/class-lp-question-curd.php
Expand Up @@ -358,22 +358,24 @@ public function get_quiz( $question_id ) {
* @param $question LP_Question
* @param $new_type
*
* @return bool|int|LP_Question
* @return false|void
* @since 3.0.0
* @version 1.0.1
*/
public function change_question_type( $question, $new_type ) {
public function change_question_type( &$question, $new_type ) {
if ( learn_press_get_post_type( $question->get_id() ) != LP_QUESTION_CPT ) {
return false;
}

$question_id = $question->get_id();
$old_type = $question->get_type();

/*if ( $old_type == $new_type ) {
return false;
}*/
// If not new Question or not change type return
$old_type = get_post_meta( $question_id, '_lp_type', true );
if ( ! empty( $old_type ) && $old_type === $new_type ) {
return;
}

$answer_options = $question->get_data( 'answer_options' );

update_post_meta( $question_id, '_lp_type', $new_type );
$question->set_type( $new_type );

Expand Down Expand Up @@ -406,10 +408,8 @@ public function change_question_type( $question, $new_type ) {
LP_Object_Cache::set( 'answer-options-' . $question_id, $answer_options, 'learn-press/questions' );
$new_question->set_data( 'answer_options', $answer_options );

return $new_question;
$question = $new_question;
}

return false;
}

/**
Expand Down
29 changes: 23 additions & 6 deletions inc/question/class-lp-question-fill-in-blanks.php
Expand Up @@ -220,12 +220,29 @@ public function admin_editor_question_answers( $answers, $question_id, $quiz_id
return $answers;
}

/**
* Clear answer meta of the question
*
* @param $question_id
*
* @since 4.0.0
* @version 1.0.1
*/
public function clear_question_answer_meta( $question_id ) {
$question = LP_Question::get_question( $question_id );
$answers = $question->get_answers();

foreach ( $answers as $answer ) {
learn_press_delete_question_answer_meta( $answer->get_id(), '_blanks', '', true );
try {
$question = LP_Question::get_question( $question_id );
$answers = $question->get_answers();

foreach ( $answers as $answer ) {
$answer_id = $answer->get_id();
$lp_db = LP_Database::getInstance();
$filter = new LP_Question_Answermeta_Filter();
$filter->collection = $lp_db->tb_lp_question_answermeta;
$filter->where[] = $lp_db->wpdb->prepare( "AND learnpress_question_answer_id = %s", $answer_id );
$lp_db->delete_execute( $filter );
}
} catch ( Throwable $e ) {
error_log( __METHOD__ . ': ' . $e->getMessage() );
}
}

Expand Down Expand Up @@ -393,7 +410,7 @@ public function check( $user_answer = null ) {
/**
* Check answer fill in blank
*
* @param array $blank
* @param array $blank
* @param $user_fill
*
* @return bool
Expand Down

0 comments on commit bc0c110

Please sign in to comment.