e61d99daed
CI / Coding Standards (pull_request) Successful in 51s
CI / PHPStan (pull_request) Successful in 1m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 46s
CI / Tests (PHP 8.2) (pull_request) Successful in 48s
CI / Tests (PHP 8.3) (pull_request) Successful in 47s
CI / No Debug Code (pull_request) Successful in 3s
Implements #5: studio admin / instructors author intake questions scoped per offering; answers are stored against a lesson or group enrolment via a polymorphic registration reference. - src/Registration/: Question + Answer value objects, QuestionRepository and AnswerRepository, QuestionEndpoint (REST), QuestionController + templates/admin/questions.php (Offerings -> Questions submenu) - us_questions and us_question_answers tables in Schema.php - REST: public GET /offerings/{id}/questions; POST/PATCH/DELETE /questions gated by manage_questions + offering ownership (owner or studio admin) - Field types text/textarea/select/checkbox; select options stored as JSON - Wiring in Plugin, RestRegistrar, AdminMenu AnswerRepository is built now and consumed by the booking/enrolment flow in #3/#4. Tests: tests/Unit/Registration/ (19 tests). composer test (63 total), cs, and PHPStan level 6 all pass. Refs #5 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
113 lines
6.4 KiB
PHP
113 lines
6.4 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use Unsupervised\Schedular\Registration\Question;
|
|
|
|
if (! defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
/**
|
|
* @var list<\Unsupervised\Schedular\Offering\Offering> $offeringList
|
|
* @var \Unsupervised\Schedular\Offering\Offering|null $selectedOffering
|
|
* @var list<\Unsupervised\Schedular\Registration\Question>|null $questions
|
|
*/
|
|
?>
|
|
<div class="wrap">
|
|
<h1><?php esc_html_e('Registration Questions', 'unsupervised-schedular'); ?></h1>
|
|
|
|
<form method="get">
|
|
<input type="hidden" name="page" value="us-questions">
|
|
<label for="offering_id"><?php esc_html_e('Offering', 'unsupervised-schedular'); ?></label>
|
|
<select name="offering_id" id="offering_id" onchange="this.form.submit()">
|
|
<option value="0"><?php esc_html_e('— Select an offering —', 'unsupervised-schedular'); ?></option>
|
|
<?php foreach ($offeringList as $offering) : ?>
|
|
<option value="<?php echo esc_attr((string) $offering->id); ?>" <?php selected($selectedOffering && $selectedOffering->id === $offering->id); ?>>
|
|
<?php echo esc_html($offering->title); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</form>
|
|
|
|
<?php if (null === $selectedOffering) : ?>
|
|
<p><?php esc_html_e('Choose an offering to manage its intake questions.', 'unsupervised-schedular'); ?></p>
|
|
<?php else : ?>
|
|
<h2><?php echo esc_html(sprintf(/* translators: %s: offering title */ __('Questions for "%s"', 'unsupervised-schedular'), $selectedOffering->title)); ?></h2>
|
|
|
|
<h3><?php esc_html_e('Add Question', 'unsupervised-schedular'); ?></h3>
|
|
<form method="post">
|
|
<?php wp_nonce_field('usc_question_action'); ?>
|
|
<input type="hidden" name="usc_action" value="add">
|
|
<table class="form-table">
|
|
<tr>
|
|
<th><label for="label"><?php esc_html_e('Question', 'unsupervised-schedular'); ?></label></th>
|
|
<td><input type="text" name="label" id="label" class="regular-text" required></td>
|
|
</tr>
|
|
<tr>
|
|
<th><label for="field_type"><?php esc_html_e('Field type', 'unsupervised-schedular'); ?></label></th>
|
|
<td>
|
|
<select name="field_type" id="field_type">
|
|
<option value="<?php echo esc_attr(Question::FIELD_TEXT); ?>"><?php esc_html_e('Text', 'unsupervised-schedular'); ?></option>
|
|
<option value="<?php echo esc_attr(Question::FIELD_TEXTAREA); ?>"><?php esc_html_e('Paragraph', 'unsupervised-schedular'); ?></option>
|
|
<option value="<?php echo esc_attr(Question::FIELD_SELECT); ?>"><?php esc_html_e('Dropdown', 'unsupervised-schedular'); ?></option>
|
|
<option value="<?php echo esc_attr(Question::FIELD_CHECKBOX); ?>"><?php esc_html_e('Checkbox', 'unsupervised-schedular'); ?></option>
|
|
</select>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th><label for="options"><?php esc_html_e('Options', 'unsupervised-schedular'); ?></label></th>
|
|
<td>
|
|
<textarea name="options" id="options" rows="4" class="large-text" placeholder="<?php esc_attr_e('One choice per line (dropdown only)', 'unsupervised-schedular'); ?>"></textarea>
|
|
</td>
|
|
</tr>
|
|
<tr>
|
|
<th><label for="sort_order"><?php esc_html_e('Sort order', 'unsupervised-schedular'); ?></label></th>
|
|
<td><input type="number" name="sort_order" id="sort_order" min="0" step="1" value="0"></td>
|
|
</tr>
|
|
<tr>
|
|
<th><?php esc_html_e('Required', 'unsupervised-schedular'); ?></th>
|
|
<td><label><input type="checkbox" name="is_required" value="1"> <?php esc_html_e('Registrant must answer', 'unsupervised-schedular'); ?></label></td>
|
|
</tr>
|
|
</table>
|
|
<?php submit_button(esc_html__('Add Question', 'unsupervised-schedular')); ?>
|
|
</form>
|
|
|
|
<h3><?php esc_html_e('Current Questions', 'unsupervised-schedular'); ?></h3>
|
|
<?php if (empty($questions)) : ?>
|
|
<p><?php esc_html_e('No questions configured for this offering.', 'unsupervised-schedular'); ?></p>
|
|
<?php else : ?>
|
|
<table class="wp-list-table widefat fixed striped">
|
|
<thead>
|
|
<tr>
|
|
<th><?php esc_html_e('Order', 'unsupervised-schedular'); ?></th>
|
|
<th><?php esc_html_e('Question', 'unsupervised-schedular'); ?></th>
|
|
<th><?php esc_html_e('Type', 'unsupervised-schedular'); ?></th>
|
|
<th><?php esc_html_e('Required', 'unsupervised-schedular'); ?></th>
|
|
<th><?php esc_html_e('Actions', 'unsupervised-schedular'); ?></th>
|
|
</tr>
|
|
</thead>
|
|
<tbody>
|
|
<?php foreach ($questions as $question) : ?>
|
|
<tr>
|
|
<td><?php echo esc_html((string) $question->sortOrder); ?></td>
|
|
<td><?php echo esc_html($question->label); ?></td>
|
|
<td><?php echo esc_html($question->fieldType); ?></td>
|
|
<td><?php echo $question->isRequired ? esc_html__('Yes', 'unsupervised-schedular') : esc_html__('No', 'unsupervised-schedular'); ?></td>
|
|
<td>
|
|
<form method="post" style="display:inline;">
|
|
<?php wp_nonce_field('usc_question_action'); ?>
|
|
<input type="hidden" name="usc_action" value="delete">
|
|
<input type="hidden" name="question_id" value="<?php echo esc_attr((string) $question->id); ?>">
|
|
<button type="submit" class="button button-small button-link-delete">
|
|
<?php esc_html_e('Delete', 'unsupervised-schedular'); ?>
|
|
</button>
|
|
</form>
|
|
</td>
|
|
</tr>
|
|
<?php endforeach; ?>
|
|
</tbody>
|
|
</table>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</div>
|