Quiz::dozent_quiz_update_question()
Update quiz question
Source
File: classes/Quiz.php
public function dozent_quiz_update_question() { global $wpdb; $question_id = dozent_input_text( 'question_id' ); $question = dozent_get_question( $question_id ); $question_title = dozent_input_text( 'question_title' ); $score = dozent_input_text( 'score' ); $image_id = dozent_input_text( 'image_id' ); //For the question type true false $is_true = dozent_input_text( 'question_type_is_true' ); if ( empty( $question_title ) ) { $error_text = __( 'The question title field is required.', 'dozent' ); $error_message = "<p class='dozent-text-danger'> <i class='dicon-notification'></i> {$error_text} </p>"; wp_send_json_error( [ 'message' => $error_message ] ); } $user_id = get_current_user_id(); $data = apply_filters( 'dozent/quiz/update_question/data', [ 'user_id' => $user_id, 'title' => $question_title, 'image_id' => $image_id, 'score' => $score, ] ); if ( $question->question_type === 'true_false' ) { $data['mixed_value'] = $is_true; } do_action( 'dozent/quiz/update_question/before', $data ); $wpdb->update( $wpdb->dozent_quiz_questions, $data, [ 'question_id' => $question_id ] ); $question_options = (array) dozent_input_array_field( 'options' ); $question_options = dozent_array_except( $question_options, '{index}' ); if ( dozent_count( $question_options ) ) { $sort = 0; foreach ( $question_options as $option ) { $sort ++; $option_id = (int) dozent_array_get( 'option_id', $option ); $optionData = [ 'question_id' => $question_id, 'title' => dozent_array_get( 'title', $option ), 'image_id' => dozent_array_get( 'image_id', $option ), 'display_preference' => dozent_array_get( 'd_pref', $option ), 'is_correct' => (int) dozent_array_get( 'is_correct', $option ), 'sort_order' => $sort, ]; if ( $option_id ) { $wpdb->update( $wpdb->dozent_quiz_question_options, $optionData, [ 'option_id' => $option_id ] ); } else { $wpdb->insert( $wpdb->dozent_quiz_question_options, $optionData ); } } } do_action( 'dozent/quiz/update_question/after', $data, $question_id ); ob_start(); $quiz_id = $question->quiz_id; include DOZENT_ABSPATH . 'views/course_builder/quiz_questions.php'; $questions_html = ob_get_clean(); wp_send_json_success( [ 'questions_html' => $questions_html ] ); }
Changelog
Version | Description |
---|---|
DozentLMS 1.0.0 | Introduced. |