feat: Add points field and credit cost to Question Management UI
This commit is contained in:
parent
a5c03e53fc
commit
278b820b00
2 changed files with 19 additions and 0 deletions
|
|
@ -312,6 +312,7 @@ function quiztech_ajax_get_question() {
|
|||
'type' => $question_type,
|
||||
'options' => $options_string,
|
||||
'category' => $category_id,
|
||||
'points' => get_post_meta( $question_id, '_quiztech_question_points', true ), // Add points
|
||||
] );
|
||||
}
|
||||
add_action( 'wp_ajax_quiztech_get_question', 'quiztech_ajax_get_question' );
|
||||
|
|
@ -400,6 +401,13 @@ function quiztech_ajax_save_question() {
|
|||
wp_set_post_terms( $new_or_updated_post_id, [], 'quiztech_category', false ); // Remove terms if none selected
|
||||
}
|
||||
|
||||
// Update Question Points meta
|
||||
$points = isset( $_POST['question_points'] ) ? absint( $_POST['question_points'] ) : 1; // Default to 1 if not set or invalid
|
||||
update_post_meta( $new_or_updated_post_id, '_quiztech_question_points', $points );
|
||||
|
||||
// Set Credit Cost meta (always 3 for user-generated questions as per requirement)
|
||||
update_post_meta( $new_or_updated_post_id, '_quiztech_credit_cost', 3 );
|
||||
|
||||
// --- Prepare Success Response ---
|
||||
// Optionally, generate HTML for the updated/new table row to send back
|
||||
// For simplicity now, just send success and let JS reload or handle update
|
||||
|
|
|
|||
|
|
@ -43,6 +43,8 @@ get_header(); ?>
|
|||
|
||||
<div id="quiztech-add-edit-question-form" style="display: none; border: 1px solid #ccc; padding: 15px; margin-bottom: 20px;">
|
||||
<h3><?php esc_html_e( 'Add/Edit Question', 'quiztech' ); ?></h3>
|
||||
<p style="font-weight: bold;"><?php esc_html_e( 'Credits:', 'quiztech' ); ?> 3</p>
|
||||
|
||||
<form id="question-form">
|
||||
<?php wp_nonce_field( 'quiztech_save_question_action', 'quiztech_question_nonce' ); ?>
|
||||
<input type="hidden" id="quiztech-question-id" name="question_id" value="">
|
||||
|
|
@ -85,6 +87,13 @@ get_header(); ?>
|
|||
'hierarchical' => 1,
|
||||
) );
|
||||
?>
|
||||
|
||||
<p>
|
||||
<label for="quiztech-question-points"><?php esc_html_e( 'Question Points:', 'quiztech' ); ?></label><br>
|
||||
<input type="number" id="quiztech-question-points" name="question_points" class="small-text" min="0" step="1" value="1">
|
||||
<small><?php esc_html_e('Points awarded for a correct answer.', 'quiztech'); ?></small>
|
||||
</p>
|
||||
|
||||
</p>
|
||||
|
||||
<p>
|
||||
|
|
@ -158,6 +167,7 @@ get_header(); ?>
|
|||
// --- Helper: Reset and Hide Form ---
|
||||
function resetAndHideForm() {
|
||||
formElement[0].reset();
|
||||
$('#quiztech-question-points').val('1'); // Reset points to default
|
||||
questionIdField.val('');
|
||||
cancelButton.hide();
|
||||
formTitle.text('<?php echo esc_js( __( 'Add New Question', 'quiztech' ) ); ?>');
|
||||
|
|
@ -228,6 +238,7 @@ get_header(); ?>
|
|||
$('#quiztech-question-type').val(data.type).trigger('change'); // Trigger change to show/hide options
|
||||
$('#quiztech-question-options').val(data.options);
|
||||
$('#quiztech-question-category').val(data.category);
|
||||
$('#quiztech-question-points').val(data.points || 1); // Populate points, default to 1 if not set
|
||||
|
||||
formTitle.text('<?php echo esc_js( __( 'Edit Question', 'quiztech' ) ); ?>');
|
||||
cancelButton.show();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue