Files
unsupervised-scheduler/templates/admin/questions.php
T
thatguygriffandClaude Opus 5 cb347ffca0
CI / Tests (PHP 8.1) (pull_request) Successful in 1m0s
CI / Tests (PHP 8.2) (pull_request) Successful in 1m0s
CI / No Debug Code (pull_request) Successful in 3s
CI / Coding Standards (pull_request) Successful in 3m8s
CI / Build Plugin Zip (pull_request) Skipped
CI / PHPStan (pull_request) Successful in 2m49s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m44s
Demo follow-ups: editable policy name, one-page signup, group classes in upcoming lessons, deletion cleanup
Five items from the latest demo pass:

- A policy's title can be edited from the Policies screen. Only the title
  moves; the slug is what the gates resolve policies by, so a rename can
  never detach a policy from acceptances already recorded against it.
- Signup is one page again. The studio's registration questions move from
  a second step behind "Next" onto the main form, in an "About you" panel
  above the students being added, and that panel also asks an adult
  student for their birth year (the same us_birth_year meta a child's
  uses). register.js disables and hides the whole panel for a pure
  guardian, since the questions describe a student.
- The password is re-scored on submit, not only as it is typed. zxcvbn's
  dictionary arrives after page load, so a password typed straight away
  was never scored at all and the first the student heard of it was the
  server rejecting the whole form.
- Group-class sessions appear alongside lessons wherever upcoming lessons
  are listed: the [us_scheduler] panel (students and instructors) and the
  admin student detail page. GroupClass\SessionSchedule derives them from
  Offering::sessionWindows(), the same derivation the billing scan uses.
  They carry kind = 'group_class' and no Cancel action - a session is one
  date in a term, not a booked slot.
- Deleting a user releases what the account was holding: each upcoming
  lesson is cancelled, its slot freed for rebooking, its pending payment
  voided, and active class enrolments cancelled. Past lessons and paid
  history are left alone.

Tests: composer test (851), composer lint, composer cs all pass.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-07-30 11:45:04 -03:00

125 lines
7.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 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 when they register — the account holder on the signup form itself, and once per student they are registering on behalf of.', '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" maxlength="<?php echo esc_attr((string) Question::MAX_LABEL_LENGTH); ?>" 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>