Files
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

199 lines
11 KiB
PHP

<?php
declare(strict_types=1);
use Unsupervised\Schedular\Policy\Policy;
use Unsupervised\Schedular\Policy\PolicyVersion;
if (! defined('ABSPATH')) {
exit;
}
/**
* @var list<\Unsupervised\Schedular\Policy\Policy> $policyList
* @var \Unsupervised\Schedular\Policy\Policy|null $selectedPolicy
* @var list<\Unsupervised\Schedular\Policy\PolicyVersion>|null $policyVersions
* @var \Unsupervised\Schedular\Policy\PolicyVersion|null $viewedVersion Version opened in the viewer, if any.
* @var string $notice Status message from the last save.
*/
?>
<div class="wrap">
<h1><?php esc_html_e('Policies', 'unsupervised-schedular'); ?></h1>
<?php if ('' !== $notice) : ?>
<div class="notice notice-success is-dismissible"><p><?php echo esc_html($notice); ?></p></div>
<?php endif; ?>
<h2><?php esc_html_e('Add Policy', 'unsupervised-schedular'); ?></h2>
<form method="post">
<?php wp_nonce_field('usc_policy_action'); ?>
<input type="hidden" name="usc_action" value="create_policy">
<table class="form-table">
<tr>
<th><label for="title"><?php esc_html_e('Title', 'unsupervised-schedular'); ?></label></th>
<td><input type="text" name="title" id="title" class="regular-text" maxlength="<?php echo esc_attr((string) Policy::MAX_TITLE_LENGTH); ?>" required></td>
</tr>
<tr>
<th><label for="slug"><?php esc_html_e('Slug', 'unsupervised-schedular'); ?></label></th>
<td>
<input type="text" name="slug" id="slug" class="regular-text" maxlength="<?php echo esc_attr((string) Policy::MAX_SLUG_LENGTH); ?>" placeholder="<?php esc_attr_e('e.g. cancellation (defaults from title)', 'unsupervised-schedular'); ?>">
</td>
</tr>
<tr>
<th><label for="acceptance_scope"><?php esc_html_e('Accept at', 'unsupervised-schedular'); ?></label></th>
<td>
<select name="acceptance_scope" id="acceptance_scope">
<option value="<?php echo esc_attr(Policy::SCOPE_BOOKING); ?>" selected><?php esc_html_e('Booking', 'unsupervised-schedular'); ?></option>
<option value="<?php echo esc_attr(Policy::SCOPE_SIGNUP); ?>"><?php esc_html_e('Account signup', 'unsupervised-schedular'); ?></option>
<option value="<?php echo esc_attr(Policy::SCOPE_BOTH); ?>"><?php esc_html_e('Both', 'unsupervised-schedular'); ?></option>
</select>
</td>
</tr>
</table>
<?php submit_button(esc_html__('Add Policy', 'unsupervised-schedular')); ?>
</form>
<hr>
<form method="get">
<input type="hidden" name="page" value="us-policies">
<label for="policy_id"><?php esc_html_e('Policy', 'unsupervised-schedular'); ?></label>
<select name="policy_id" id="policy_id" onchange="this.form.submit()">
<option value="0"><?php esc_html_e('— Select a policy —', 'unsupervised-schedular'); ?></option>
<?php foreach ($policyList as $policy) : ?>
<option value="<?php echo esc_attr((string) $policy->id); ?>" <?php selected($selectedPolicy && $selectedPolicy->id === $policy->id); ?>>
<?php echo esc_html($policy->title); ?>
</option>
<?php endforeach; ?>
</select>
</form>
<?php if (null !== $selectedPolicy) : ?>
<h2><?php echo esc_html(sprintf(/* translators: %s: policy title */ __('Versions of "%s"', 'unsupervised-schedular'), $selectedPolicy->title)); ?></h2>
<h3><?php esc_html_e('Rename', 'unsupervised-schedular'); ?></h3>
<p class="description">
<?php
/* translators: %s: the policy's slug. */
echo esc_html(sprintf(__('The title is what students see above the policy text. Its slug (%s) does not change, so every version already accepted stays attached to this policy.', 'unsupervised-schedular'), $selectedPolicy->slug));
?>
</p>
<form method="post">
<?php wp_nonce_field('usc_policy_action'); ?>
<input type="hidden" name="usc_action" value="rename_policy">
<input type="hidden" name="policy_id" value="<?php echo esc_attr((string) $selectedPolicy->id); ?>">
<label class="screen-reader-text" for="usc-policy-title"><?php esc_html_e('Title', 'unsupervised-schedular'); ?></label>
<input type="text" name="title" id="usc-policy-title" class="regular-text" maxlength="<?php echo esc_attr((string) Policy::MAX_TITLE_LENGTH); ?>" value="<?php echo esc_attr($selectedPolicy->title); ?>" required>
<?php submit_button(esc_html__('Save Title', 'unsupervised-schedular'), 'secondary', 'submit', false); ?>
</form>
<h3><?php esc_html_e('Add Draft Version', 'unsupervised-schedular'); ?></h3>
<form method="post">
<?php wp_nonce_field('usc_policy_action'); ?>
<input type="hidden" name="usc_action" value="add_version">
<input type="hidden" name="policy_id" value="<?php echo esc_attr((string) $selectedPolicy->id); ?>">
<textarea name="body" rows="8" class="large-text" placeholder="<?php esc_attr_e('Policy text (HTML allowed)', 'unsupervised-schedular'); ?>"></textarea>
<?php submit_button(esc_html__('Add Draft', 'unsupervised-schedular')); ?>
</form>
<h3><?php esc_html_e('Versions', 'unsupervised-schedular'); ?></h3>
<?php if (empty($policyVersions)) : ?>
<p><?php esc_html_e('No versions yet. Add a draft above.', 'unsupervised-schedular'); ?></p>
<?php else : ?>
<table class="wp-list-table widefat fixed striped">
<thead>
<tr>
<th><?php esc_html_e('Version', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Status', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Published', 'unsupervised-schedular'); ?></th>
<th><?php esc_html_e('Actions', 'unsupervised-schedular'); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($policyVersions as $version) : ?>
<tr>
<td>
<?php echo esc_html((string) $version->versionNumber); ?>
<?php if ($selectedPolicy->currentVersionId === $version->id) : ?>
<span class="dashicons dashicons-yes" title="<?php esc_attr_e('Current', 'unsupervised-schedular'); ?>"></span>
<?php endif; ?>
</td>
<td><?php echo esc_html($version->status); ?></td>
<td><?php echo $version->publishedAt ? esc_html($version->publishedAt) : '&mdash;'; ?></td>
<td>
<a href="<?php echo esc_url(
add_query_arg(
[
'page' => 'us-policies',
'policy_id' => (string) $selectedPolicy->id,
'version_id' => (string) $version->id,
],
admin_url('admin.php')
)
); ?>" class="button button-small">
<?php esc_html_e('View', 'unsupervised-schedular'); ?>
</a>
<?php if (PolicyVersion::STATUS_PUBLISHED !== $version->status) : ?>
<form method="post" style="display:inline;">
<?php wp_nonce_field('usc_policy_action'); ?>
<input type="hidden" name="usc_action" value="publish_version">
<input type="hidden" name="policy_id" value="<?php echo esc_attr((string) $selectedPolicy->id); ?>">
<input type="hidden" name="version_id" value="<?php echo esc_attr((string) $version->id); ?>">
<button type="submit" class="button button-small button-primary">
<?php esc_html_e('Publish', 'unsupervised-schedular'); ?>
</button>
</form>
<?php else : ?>
<em><?php esc_html_e('Current', 'unsupervised-schedular'); ?></em>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<?php if (null !== $viewedVersion) : ?>
<hr>
<h3>
<?php echo esc_html(sprintf(
/* translators: 1: version number, 2: version status. */
__('Version %1$d (%2$s)', 'unsupervised-schedular'),
$viewedVersion->versionNumber,
$viewedVersion->status
)); ?>
</h3>
<?php // Rendered exactly as the booking and signup gates render it, so this doubles as a preview. ?>
<div class="us-policy-version-body" style="background:#fff;border:1px solid #c3c4c7;padding:0 1em;max-width:50em;overflow-wrap:break-word;">
<?php echo wp_kses_post($viewedVersion->bodyHtml()); ?>
</div>
<?php $editingDraft = PolicyVersion::STATUS_DRAFT === $viewedVersion->status; ?>
<h4><?php esc_html_e('Edit', 'unsupervised-schedular'); ?></h4>
<p class="description">
<?php
echo esc_html(
$editingDraft
? __('This version is still a draft, so your changes are saved to it directly.', 'unsupervised-schedular')
: __('This version has been published, so saving an edit creates a new draft version from this text and leaves the published one untouched.', 'unsupervised-schedular')
);
?>
</p>
<form method="post">
<?php wp_nonce_field('usc_policy_action'); ?>
<input type="hidden" name="usc_action" value="edit_version">
<input type="hidden" name="policy_id" value="<?php echo esc_attr((string) $selectedPolicy->id); ?>">
<input type="hidden" name="version_id" value="<?php echo esc_attr((string) $viewedVersion->id); ?>">
<textarea name="body" rows="12" class="large-text"><?php echo esc_textarea((string) $viewedVersion->body); ?></textarea>
<?php
submit_button(
$editingDraft
? esc_html__('Save Draft', 'unsupervised-schedular')
: esc_html__('Save as New Draft', 'unsupervised-schedular')
);
?>
</form>
<?php endif; ?>
<?php endif; ?>
</div>