CI / Tests (PHP 8.2) (pull_request) Successful in 44s
CI / Tests (PHP 8.1) (pull_request) Successful in 45s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 2m46s
CI / PHPStan (pull_request) Successful in 2m58s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m41s
CI / Build Plugin Zip (pull_request) Skipped
Studio admins can now define registration questions that every new student answers as a required second step during signup, with each student's answers shown under a "Registration Information" section in the admin. Extends the existing Registration domain: us_questions gains a scope column (offering | account) and a nullable offering_id, and account answers reuse us_question_answers with registration_type = 'account'. Authoring reuses the Offerings -> Questions page via an "Account signup" scope (studio-admin only). The registration form becomes two steps (progressive enhancement via assets/js/register.js; works without JS); required answers are validated before the account is created and apply to all signup paths (invite, group link, self-approval). StudentHistory::registrationInfo() powers the admin section. Bumps the plugin version to 1.1.0 so dbDelta runs the schema migration. Closes #90 Co-Authored-By: Claude Opus 4.8 <[email protected]>
125 lines
7.3 KiB
PHP
125 lines
7.3 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 bool $accountScope Whether the studio-wide account-signup questions are selected.
|
|
* @var bool $manageAll Whether the current user is a studio admin (may edit account questions).
|
|
* @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('Questions for', 'unsupervised-schedular'); ?></label>
|
|
<select name="offering_id" id="offering_id" onchange="this.form.submit()">
|
|
<option value="0"><?php esc_html_e('— Select —', 'unsupervised-schedular'); ?></option>
|
|
<?php if ($manageAll) : ?>
|
|
<option value="<?php echo esc_attr(Question::SCOPE_ACCOUNT); ?>" <?php selected($accountScope); ?>>
|
|
<?php esc_html_e('Account signup (all registrations)', 'unsupervised-schedular'); ?>
|
|
</option>
|
|
<?php endif; ?>
|
|
<?php foreach ($offeringList as $offering) : ?>
|
|
<option value="<?php echo esc_attr((string) $offering->id); ?>" <?php selected(! $accountScope && $selectedOffering && $selectedOffering->id === $offering->id); ?>>
|
|
<?php echo esc_html($offering->title); ?>
|
|
</option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</form>
|
|
|
|
<?php if (! $accountScope && null === $selectedOffering) : ?>
|
|
<p><?php esc_html_e('Choose an offering to manage its intake questions, or "Account signup" for the questions every new student answers when registering.', 'unsupervised-schedular'); ?></p>
|
|
<?php else : ?>
|
|
<?php if ($accountScope) : ?>
|
|
<h2><?php esc_html_e('Account signup questions', 'unsupervised-schedular'); ?></h2>
|
|
<p><?php esc_html_e('Every new student answers these required-if-marked questions as a second step after choosing their name and password.', 'unsupervised-schedular'); ?></p>
|
|
<?php else : ?>
|
|
<h2><?php echo esc_html(sprintf(/* translators: %s: offering title */ __('Questions for "%s"', 'unsupervised-schedular'), $selectedOffering->title)); ?></h2>
|
|
<?php endif; ?>
|
|
|
|
<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 yet.', '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>
|