Demo follow-ups: editable policy name, one-page signup, group classes in upcoming lessons, deletion cleanup
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
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
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]>
This commit is contained in:
+2
-1
@@ -23,6 +23,7 @@ use Unsupervised\Schedular\Booking\LessonDetail;
|
||||
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
||||
use Unsupervised\Schedular\GroupClass\GroupAccessRepository;
|
||||
use Unsupervised\Schedular\GroupClass\GroupClassController;
|
||||
use Unsupervised\Schedular\GroupClass\SessionSchedule;
|
||||
use Unsupervised\Schedular\Offering\ClassSlotReconciler;
|
||||
use Unsupervised\Schedular\Offering\OfferingController;
|
||||
use Unsupervised\Schedular\Offering\OfferingRepository;
|
||||
@@ -74,7 +75,7 @@ class AdminMenu {
|
||||
$this->registrationController = new RegistrationController( $invites );
|
||||
$this->registrationApprovalController = new RegistrationApprovalController( $registrationMailer );
|
||||
$this->groupClassController = new GroupClassController( $enrollments, $offerings, $payments, $groupAccess, $paymentService, $invites, $registrationMailer );
|
||||
$this->studentController = new StudentController( $bookings, $availability, $offerings, $enrollments, $resolver, new StudentHistory( $acceptances, $policies, $policyVersions, $answers, $questions, $payments, $credits ), new StudentActions( $bookings, $availability, $enrollments, $paymentService ), $guardians );
|
||||
$this->studentController = new StudentController( $bookings, $availability, $offerings, $enrollments, $resolver, new StudentHistory( $acceptances, $policies, $policyVersions, $answers, $questions, $payments, $credits ), new StudentActions( $bookings, $availability, $enrollments, $paymentService ), $guardians, new SessionSchedule( $enrollments, $offerings ) );
|
||||
$this->instructorController = new InstructorController();
|
||||
$this->settings = $settings;
|
||||
$this->accessSettings = new AccessSettings();
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\Auth;
|
||||
|
||||
use Unsupervised\Schedular\Availability\AvailabilityRepository;
|
||||
use Unsupervised\Schedular\Booking\BookingRepository;
|
||||
use Unsupervised\Schedular\Booking\Lesson;
|
||||
use Unsupervised\Schedular\GroupClass\Enrollment;
|
||||
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
||||
use Unsupervised\Schedular\Payment\PaymentService;
|
||||
|
||||
/**
|
||||
* Gives back what a deleted account was holding.
|
||||
*
|
||||
* WordPress deletes a user without knowing anything about lessons, so a student
|
||||
* removed from **Users → Delete** used to leave their bookings behind: the
|
||||
* availability slots stayed marked booked and unbookable by anyone else, the
|
||||
* lessons stayed on the instructor's schedule under a name that no longer
|
||||
* resolved, and a group class kept a seat filled by nobody.
|
||||
*
|
||||
* So each upcoming booking is cancelled the same way a real cancellation is —
|
||||
* marked cancelled, its slot released, its still-pending payment voided. Past
|
||||
* lessons are deliberately left alone: they happened, they may have been paid
|
||||
* for, and the payment report has to keep adding up.
|
||||
*
|
||||
* No account credit is issued for a paid lesson, unlike a cancellation the
|
||||
* student asks for. A credit only has value against future billing on the
|
||||
* account it belongs to, and that account is being deleted; a refund owed to
|
||||
* someone who has left is a decision for the studio to make and record, not one
|
||||
* to silently write into a table nobody will read again.
|
||||
*/
|
||||
class DeletedUserCleanup {
|
||||
|
||||
public function __construct(
|
||||
private BookingRepository $bookings,
|
||||
private AvailabilityRepository $availability,
|
||||
private EnrollmentRepository $enrollments,
|
||||
private PaymentService $payments,
|
||||
) {}
|
||||
|
||||
public function register(): void {
|
||||
// `delete_user` fires before the row goes, which is what lets the lookups
|
||||
// below still find the account's bookings. `wpmu_delete_user` is the
|
||||
// multisite equivalent for a user removed from the network entirely.
|
||||
add_action( 'delete_user', [ $this, 'releaseBookings' ] );
|
||||
add_action( 'wpmu_delete_user', [ $this, 'releaseBookings' ] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancel and release everything the account had booked ahead of it.
|
||||
*/
|
||||
public function releaseBookings( int $userId ): void {
|
||||
if ( $userId <= 0 ) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Upcoming and not already cancelled — the only bookings that are still
|
||||
// holding anything.
|
||||
foreach ( $this->bookings->findUpcomingForStudent( $userId ) as $lesson ) {
|
||||
$this->bookings->updateStatus( (int) $lesson->id, Lesson::STATUS_CANCELLED );
|
||||
$this->availability->release( $lesson->slotId );
|
||||
$this->payments->voidPending( $lesson->paymentId );
|
||||
}
|
||||
|
||||
foreach ( $this->enrollments->findByStudent( $userId ) as $enrollment ) {
|
||||
if ( Enrollment::STATUS_ACTIVE !== $enrollment->status ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->enrollments->updateStatus( (int) $enrollment->id, Enrollment::STATUS_CANCELLED );
|
||||
$this->payments->voidPending( $enrollment->paymentId );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -128,9 +128,10 @@ class RegistrationPage {
|
||||
// gate, so it needs the plugin stylesheet that formats it.
|
||||
wp_enqueue_style( 'us-scheduler' );
|
||||
|
||||
// The script drives both the second step and the parent/guardian section
|
||||
// (revealing it, and cloning the child block for "add another"), so it is
|
||||
// needed whenever the form itself is on screen.
|
||||
// The script drives the parent/guardian section (revealing it, taking the
|
||||
// account holder's own panel out of play, and cloning the child block for
|
||||
// "add another") and the password meter, so it is needed whenever the form
|
||||
// itself is on screen.
|
||||
if ( $canRegister && '' === $successType ) {
|
||||
wp_enqueue_script( 'us-scheduler-register' );
|
||||
|
||||
@@ -328,6 +329,9 @@ class RegistrationPage {
|
||||
$children = $isGuardian ? $this->submittedChildren() : [];
|
||||
$answers = $asksSelf ? $this->submittedAnswers() : [];
|
||||
|
||||
// phpcs:ignore WordPress.Security.NonceVerification.Missing -- verified by the caller.
|
||||
$birthYear = $asksSelf ? trim( sanitize_text_field( Val::string( wp_unslash( $_POST['birth_year'] ?? '' ) ) ) ) : '';
|
||||
|
||||
// Everything is validated before a single user is created, so a bad child
|
||||
// block never leaves a half-registered family behind.
|
||||
if ( $isGuardian && [] === $children ) {
|
||||
@@ -356,6 +360,15 @@ class RegistrationPage {
|
||||
}
|
||||
}
|
||||
|
||||
// The account holder is a student too under "self" and "both", so the same
|
||||
// birth year every other student gives is asked of them — and checked
|
||||
// here rather than left to the browser, for the same reason as the
|
||||
// children's: the panel is hidden for a pure guardian, so `required`
|
||||
// alone cannot be trusted to have applied.
|
||||
if ( $asksSelf && 0 === GuardianService::normaliseBirthYear( $birthYear ) ) {
|
||||
return esc_html( GuardianService::ownBirthYearError() );
|
||||
}
|
||||
|
||||
if ( $asksSelf && $this->hasUnansweredRequired( $accountQuestions, $answers ) ) {
|
||||
return esc_html__( 'Please answer all required registration questions.', 'unsupervised-schedular' );
|
||||
}
|
||||
@@ -384,6 +397,10 @@ class RegistrationPage {
|
||||
// "both" registers them alongside the people they book for.
|
||||
$this->guardians->setGuardianOnly( (int) $userId, self::FOR_STUDENTS === $registeringFor );
|
||||
|
||||
if ( $asksSelf ) {
|
||||
$this->guardians->setBirthYear( (int) $userId, $birthYear );
|
||||
}
|
||||
|
||||
if ( $isGuardian ) {
|
||||
$failure = $this->createChildren( $children, $accountQuestions, $policyForms, (int) $userId );
|
||||
if ( '' !== $failure ) {
|
||||
|
||||
@@ -8,6 +8,7 @@ use Unsupervised\Schedular\Booking\BookingRepository;
|
||||
use Unsupervised\Schedular\Booking\Lesson;
|
||||
use Unsupervised\Schedular\GroupClass\Enrollment;
|
||||
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
||||
use Unsupervised\Schedular\GroupClass\SessionSchedule;
|
||||
use Unsupervised\Schedular\Guardian\GuardianService;
|
||||
use Unsupervised\Schedular\Offering\OfferingRepository;
|
||||
use Unsupervised\Schedular\Payment\BillingMethodResolver;
|
||||
@@ -25,6 +26,7 @@ class StudentController {
|
||||
private StudentHistory $history,
|
||||
private StudentActions $actions,
|
||||
private GuardianService $guardians,
|
||||
private SessionSchedule $sessions,
|
||||
) {}
|
||||
|
||||
public function renderPage(): void {
|
||||
@@ -134,7 +136,15 @@ class StudentController {
|
||||
$this->bookings->findByStudent( (int) $student->ID )
|
||||
);
|
||||
|
||||
$schedule = StudentSchedule::partition( $rows, $now );
|
||||
// Group classes join the upcoming table so "what is this student booked
|
||||
// into next week?" has one answer instead of two. Only their upcoming
|
||||
// sessions are added: the enrolment table below already records the whole
|
||||
// history, and a term's worth of past dates would bury the lessons under
|
||||
// "Past lessons".
|
||||
$schedule = StudentSchedule::partition(
|
||||
array_merge( $rows, $this->groupSessionRows( (int) $student->ID, $now ) ),
|
||||
$now
|
||||
);
|
||||
$upcoming = $schedule['upcoming'];
|
||||
$past = $schedule['past'];
|
||||
|
||||
@@ -194,6 +204,7 @@ class StudentController {
|
||||
|
||||
return [
|
||||
'id' => (int) $lesson->id,
|
||||
'kind' => 'lesson',
|
||||
'start_dt' => $slot ? $slot->startDt : '',
|
||||
'end_dt' => $slot ? $slot->endDt : '',
|
||||
'offering' => $offering ? $offering->title : '—',
|
||||
@@ -201,4 +212,31 @@ class StudentController {
|
||||
'status' => $lesson->status,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* The student's upcoming group-class sessions, shaped like the lesson rows
|
||||
* they sit beside. `kind` is what keeps the table honest: a session is a date
|
||||
* in a term, not a booked slot, so the row offers no "Cancel" — withdrawing
|
||||
* is done from the enrolment table, which removes the whole class at once.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function groupSessionRows( int $studentId, string $now ): array {
|
||||
return array_map(
|
||||
static function ( array $session ): array {
|
||||
$instructor = get_userdata( $session['instructor_id'] );
|
||||
|
||||
return [
|
||||
'id' => $session['enrollment_id'],
|
||||
'kind' => SessionSchedule::KIND,
|
||||
'start_dt' => $session['start_dt'],
|
||||
'end_dt' => $session['end_dt'],
|
||||
'offering' => $session['offering_title'],
|
||||
'instructor' => $instructor ? $instructor->display_name : (string) $session['instructor_id'],
|
||||
'status' => $session['status'],
|
||||
];
|
||||
},
|
||||
$this->sessions->upcomingForStudent( $studentId, $now )
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ namespace Unsupervised\Schedular\Booking;
|
||||
|
||||
use Unsupervised\Schedular\Availability\AvailabilityRepository;
|
||||
use Unsupervised\Schedular\Auth\RoleManager;
|
||||
use Unsupervised\Schedular\GroupClass\SessionSchedule;
|
||||
use Unsupervised\Schedular\Guardian\GuardianService;
|
||||
use Unsupervised\Schedular\Offering\Offering;
|
||||
use Unsupervised\Schedular\Offering\OfferingRepository;
|
||||
@@ -30,6 +31,7 @@ class BookingEndpoint {
|
||||
private PaymentService $payments,
|
||||
private CancellationPolicy $cancellationPolicy,
|
||||
private GuardianService $guardians,
|
||||
private SessionSchedule $sessions,
|
||||
) {}
|
||||
|
||||
/**
|
||||
@@ -124,20 +126,35 @@ class BookingEndpoint {
|
||||
|
||||
public function myLessons( \WP_REST_Request $request ): \WP_REST_Response { // phpcs:ignore Generic.CodeAnalysis.UnusedFunctionParameter.Found
|
||||
$userId = get_current_user_id();
|
||||
$now = current_time( 'mysql' );
|
||||
|
||||
// Group classes are listed here too. A term-based class has no row in
|
||||
// us_availability, so nothing that only read lessons could show one, and a
|
||||
// student whose whole week was a group class saw an empty schedule.
|
||||
if ( current_user_can( RoleManager::CAP_MANAGE_AVAILABILITY ) ) {
|
||||
$lessons = $this->bookings->findUpcomingForInstructor( $userId );
|
||||
|
||||
// One row per session the instructor teaches, not per student in it.
|
||||
$sessions = array_map(
|
||||
static fn( array $session ): array => $session + [ 'kind' => SessionSchedule::KIND ],
|
||||
$this->sessions->upcomingForInstructor( $userId, $now )
|
||||
);
|
||||
} else {
|
||||
// A guardian's list covers the whole household — their own lessons and
|
||||
// every child's — merged and re-sorted so the soonest is first
|
||||
// regardless of whose it is.
|
||||
$lessons = [];
|
||||
$lessons = [];
|
||||
$sessions = [];
|
||||
foreach ( $this->guardians->householdIds( $userId ) as $studentId ) {
|
||||
$lessons = array_merge( $lessons, $this->bookings->findUpcomingForStudent( $studentId ) );
|
||||
$lessons = array_merge( $lessons, $this->bookings->findUpcomingForStudent( $studentId ) );
|
||||
$sessions = array_merge( $sessions, $this->sessionRows( $studentId, $now ) );
|
||||
}
|
||||
}
|
||||
|
||||
$rows = array_map( fn( Lesson $l ): array => $this->lessonWithTimes( $l ), $lessons );
|
||||
$rows = array_merge(
|
||||
array_map( fn( Lesson $l ): array => $this->lessonWithTimes( $l ), $lessons ),
|
||||
$sessions
|
||||
);
|
||||
|
||||
// usort reindexes in place, so the response is already a list.
|
||||
usort( $rows, static fn( array $a, array $b ): int => Val::string( $a['start_dt'] ?? '' ) <=> Val::string( $b['start_dt'] ?? '' ) );
|
||||
@@ -145,6 +162,23 @@ class BookingEndpoint {
|
||||
return new \WP_REST_Response( $rows, 200 );
|
||||
}
|
||||
|
||||
/**
|
||||
* One student's upcoming group-class sessions, shaped like the lesson rows
|
||||
* beside them so a single list renders both. `kind` is what tells them apart:
|
||||
* a session is not a booked slot, so it carries no cancel action.
|
||||
*
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function sessionRows( int $studentId, string $now ): array {
|
||||
return array_map(
|
||||
fn( array $session ): array => $session + [
|
||||
'kind' => SessionSchedule::KIND,
|
||||
'student_name' => $this->guardians->studentName( $studentId ),
|
||||
],
|
||||
$this->sessions->upcomingForStudent( $studentId, $now )
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A lesson's array form plus its slot's start/end times and the booked
|
||||
* offering's name, so front-end lists can show what the session is and when
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\GroupClass;
|
||||
|
||||
use Unsupervised\Schedular\Offering\Offering;
|
||||
use Unsupervised\Schedular\Offering\OfferingRepository;
|
||||
|
||||
/**
|
||||
* Turns group-class enrolments into dated sessions, so a class can appear
|
||||
* alongside one-to-one lessons in every "upcoming" view.
|
||||
*
|
||||
* A group class is stored as a term (`term_start`, `term_end`, `class_time`)
|
||||
* rather than as rows in `us_availability`, which is why an enrolment on its own
|
||||
* has no date on it and why nothing that listed lessons ever showed one. The
|
||||
* concrete windows come from {@see Offering::sessionWindows()} — the same
|
||||
* derivation the billing scan and the class-slot reconciler use, so a student's
|
||||
* list, an instructor's list and the invoice all agree on when the class meets.
|
||||
*
|
||||
* A class whose schedule is not fully specified yields no windows and so
|
||||
* contributes no rows: better to leave it out of a dated list than to invent a
|
||||
* time for it.
|
||||
*/
|
||||
class SessionSchedule {
|
||||
|
||||
/**
|
||||
* Marks a row as a group-class session rather than a one-to-one lesson.
|
||||
* Callers use it to withhold the per-lesson actions (cancel, detail links)
|
||||
* that only mean something for a booked slot.
|
||||
*/
|
||||
public const KIND = 'group_class';
|
||||
|
||||
public function __construct(
|
||||
private EnrollmentRepository $enrollments,
|
||||
private OfferingRepository $offerings,
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Upcoming sessions of every class a student is enrolled in, soonest first.
|
||||
*
|
||||
* A withdrawn (cancelled) enrolment contributes nothing; a completed one is
|
||||
* kept, since "completed" describes the enrolment's billing state and says
|
||||
* nothing about whether the class has met yet.
|
||||
*
|
||||
* @return list<array{enrollment_id: int, offering_id: int, offering_title: string, instructor_id: int, status: string, start_dt: string, end_dt: string, duration_minutes: int|null}>
|
||||
*/
|
||||
public function upcomingForStudent( int $studentId, string $now ): array {
|
||||
$rows = [];
|
||||
|
||||
foreach ( $this->enrollments->findByStudent( $studentId ) as $enrollment ) {
|
||||
if ( Enrollment::STATUS_CANCELLED === $enrollment->status ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$offering = $this->offerings->findById( $enrollment->offeringId );
|
||||
if ( null === $offering ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach ( $this->windowsFrom( $offering, $now ) as $window ) {
|
||||
$rows[] = [
|
||||
'enrollment_id' => (int) $enrollment->id,
|
||||
'offering_id' => (int) $offering->id,
|
||||
'offering_title' => $offering->title,
|
||||
'instructor_id' => $enrollment->instructorId,
|
||||
'status' => $enrollment->status,
|
||||
'start_dt' => $window['start'],
|
||||
'end_dt' => $window['end'],
|
||||
'duration_minutes' => $offering->durationMinutes,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return self::sortedByStart( $rows );
|
||||
}
|
||||
|
||||
/**
|
||||
* Upcoming sessions of every active group class an instructor teaches,
|
||||
* soonest first — one row per session, not per enrolled student. Enrolments
|
||||
* are not consulted at all: a class the instructor has to turn up and teach
|
||||
* belongs on their schedule whether or not anyone has signed up yet.
|
||||
*
|
||||
* @return list<array{enrollment_id: int, offering_id: int, offering_title: string, instructor_id: int, status: string, start_dt: string, end_dt: string, duration_minutes: int|null}>
|
||||
*/
|
||||
public function upcomingForInstructor( int $instructorId, string $now ): array {
|
||||
$rows = [];
|
||||
|
||||
$classes = $this->offerings->findAll( $instructorId, Offering::KIND_GROUP_CLASS, activeOnly: true );
|
||||
|
||||
foreach ( $classes as $offering ) {
|
||||
foreach ( $this->windowsFrom( $offering, $now ) as $window ) {
|
||||
$rows[] = [
|
||||
'enrollment_id' => 0,
|
||||
'offering_id' => (int) $offering->id,
|
||||
'offering_title' => $offering->title,
|
||||
'instructor_id' => $instructorId,
|
||||
'status' => Enrollment::STATUS_ACTIVE,
|
||||
'start_dt' => $window['start'],
|
||||
'end_dt' => $window['end'],
|
||||
'duration_minutes' => $offering->durationMinutes,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return self::sortedByStart( $rows );
|
||||
}
|
||||
|
||||
/**
|
||||
* The class's session windows that have not started yet.
|
||||
*
|
||||
* @return list<array{start: string, end: string}>
|
||||
*/
|
||||
private function windowsFrom( Offering $offering, string $now ): array {
|
||||
return array_values(
|
||||
array_filter(
|
||||
$offering->sessionWindows(),
|
||||
static fn( array $window ): bool => $window['start'] >= $now
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Soonest session first, so classes from separate enrolments interleave by
|
||||
* date rather than arriving grouped by class.
|
||||
*
|
||||
* @param list<array{enrollment_id: int, offering_id: int, offering_title: string, instructor_id: int, status: string, start_dt: string, end_dt: string, duration_minutes: int|null}> $rows
|
||||
* @return list<array{enrollment_id: int, offering_id: int, offering_title: string, instructor_id: int, status: string, start_dt: string, end_dt: string, duration_minutes: int|null}>
|
||||
*/
|
||||
private static function sortedByStart( array $rows ): array {
|
||||
usort( $rows, static fn( array $a, array $b ): int => strcmp( $a['start_dt'], $b['start_dt'] ) );
|
||||
|
||||
return $rows;
|
||||
}
|
||||
}
|
||||
@@ -392,14 +392,17 @@ class GuardianService {
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a child's birth year, or clear it when blank or out of range.
|
||||
* Store a student's birth year, or clear it when blank or out of range. Used
|
||||
* for a child added by their guardian and for an account holder who is a
|
||||
* student in their own right — the same fact about the same kind of person,
|
||||
* so the same meta key holds both.
|
||||
*
|
||||
* Either way the legacy full date of birth goes with it. That is what makes
|
||||
* the read fallback in {@see birthYear()} safe: without it, clearing the year
|
||||
* on a child who predates this change would leave the old date behind for the
|
||||
* fallback to resurrect on the very next read.
|
||||
*/
|
||||
private function setBirthYear( int $userId, string $birthYear ): void {
|
||||
public function setBirthYear( int $userId, string $birthYear ): void {
|
||||
delete_user_meta( $userId, self::META_DOB );
|
||||
|
||||
$year = self::normaliseBirthYear( $birthYear );
|
||||
@@ -449,6 +452,19 @@ class GuardianService {
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* The same message for the account holder's own birth year. Separate wording
|
||||
* because "each student" is nobody when the student in question is the person
|
||||
* reading it.
|
||||
*/
|
||||
public static function ownBirthYearError(): string {
|
||||
return sprintf(
|
||||
/* translators: %d: the earliest birth year the form accepts. */
|
||||
__( 'Please give your birth year, as four digits from %d onwards.', 'unsupervised-schedular' ),
|
||||
self::MIN_BIRTH_YEAR
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* A child's birth year, or an empty string when none is recorded.
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular;
|
||||
|
||||
use Unsupervised\Schedular\Auth\DeletedUserCleanup;
|
||||
use Unsupervised\Schedular\Auth\EmailConfirmationHandler;
|
||||
use Unsupervised\Schedular\Auth\InviteRepository;
|
||||
use Unsupervised\Schedular\Auth\AccountPage;
|
||||
@@ -109,6 +110,7 @@ class Plugin {
|
||||
( new RegistrationLoginGate() )->register();
|
||||
( new ChildLoginGate() )->register();
|
||||
( new StudentAdminGuard() )->register();
|
||||
( new DeletedUserCleanup( $bookings, $availability, $enrollments, $paymentService ) )->register();
|
||||
( new EmailConfirmationHandler( $settings, $registrationMailer ) )->register();
|
||||
( new AdminMenu( $availability, $bookings, $offerings, $questions, $answers, $policies, $policyVersions, $policyService, $acceptances, $invites, $enrollments, $groupAccess, $settings, $paymentRepo, $paymentService, $resolver, $registrationMailer, $creditRepo, $guardians ) )->register();
|
||||
( new RestRegistrar( $availability, $bookings, $offerings, $questions, $policies, $policyVersions, $policyService, $registrationGate, $enrollments, $groupAccess, $paymentService, $guardians ) )->register();
|
||||
|
||||
@@ -76,6 +76,25 @@ class PolicyController {
|
||||
return [ '', 0 ];
|
||||
}
|
||||
|
||||
if ( 'rename_policy' === $action ) {
|
||||
$title = trim( sanitize_text_field( Val::string( wp_unslash( $_POST['title'] ?? '' ) ) ) );
|
||||
|
||||
if ( '' === $title || mb_strlen( $title ) > Policy::MAX_TITLE_LENGTH ) {
|
||||
return [ '', 0 ];
|
||||
}
|
||||
|
||||
$this->policies->updateTitle( $policyId, $title );
|
||||
|
||||
return [
|
||||
sprintf(
|
||||
/* translators: %s: the policy's new title. */
|
||||
__( 'Policy renamed to "%s".', 'unsupervised-schedular' ),
|
||||
$title
|
||||
),
|
||||
0,
|
||||
];
|
||||
}
|
||||
|
||||
if ( 'add_version' === $action ) {
|
||||
$body = wp_kses_post( Val::string( wp_unslash( $_POST['body'] ?? '' ) ) );
|
||||
$this->service->addDraftVersion( $policyId, $body );
|
||||
|
||||
@@ -46,6 +46,22 @@ class PolicyRepository {
|
||||
return array_map( Policy::fromRow( ... ), $rows ?? [] );
|
||||
}
|
||||
|
||||
/**
|
||||
* Rename a policy. Only the title moves: the slug is the identifier the
|
||||
* booking and signup gates look policies up by, so renaming "Studio Policy"
|
||||
* to "Terms of Enrolment" must not quietly detach it from the versions
|
||||
* students have already accepted.
|
||||
*/
|
||||
public function updateTitle( int $policyId, string $title ): bool {
|
||||
return false !== $this->db->update(
|
||||
$this->table,
|
||||
[ 'title' => $title ],
|
||||
[ 'id' => $policyId ],
|
||||
[ '%s' ],
|
||||
[ '%d' ]
|
||||
);
|
||||
}
|
||||
|
||||
public function updateCurrentVersion( int $policyId, int $versionId ): bool {
|
||||
return false !== $this->db->update(
|
||||
$this->table,
|
||||
|
||||
@@ -12,6 +12,7 @@ use Unsupervised\Schedular\Booking\CancellationPolicy;
|
||||
use Unsupervised\Schedular\GroupClass\EnrollmentEndpoint;
|
||||
use Unsupervised\Schedular\GroupClass\GroupAccessRepository;
|
||||
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
||||
use Unsupervised\Schedular\GroupClass\SessionSchedule;
|
||||
use Unsupervised\Schedular\Guardian\GuardianService;
|
||||
use Unsupervised\Schedular\Offering\OfferingEndpoint;
|
||||
use Unsupervised\Schedular\Offering\OfferingRepository;
|
||||
@@ -40,7 +41,7 @@ class RestRegistrar {
|
||||
|
||||
public function __construct( AvailabilityRepository $availability, BookingRepository $bookings, OfferingRepository $offerings, QuestionRepository $questions, PolicyRepository $policies, PolicyVersionRepository $policyVersions, PolicyService $policyService, RegistrationGate $gate, EnrollmentRepository $enrollments, GroupAccessRepository $groupAccess, PaymentService $paymentService, GuardianService $guardians ) {
|
||||
$this->availabilityEndpoint = new AvailabilityEndpoint( $availability, new WindowValidator( $offerings ) );
|
||||
$this->bookingEndpoint = new BookingEndpoint( $availability, $bookings, $offerings, $gate, $paymentService, new CancellationPolicy( new StudioSettings() ), $guardians );
|
||||
$this->bookingEndpoint = new BookingEndpoint( $availability, $bookings, $offerings, $gate, $paymentService, new CancellationPolicy( new StudioSettings() ), $guardians, new SessionSchedule( $enrollments, $offerings ) );
|
||||
$this->offeringEndpoint = new OfferingEndpoint( $offerings, $groupAccess );
|
||||
$this->questionEndpoint = new QuestionEndpoint( $questions, $offerings );
|
||||
$this->policyEndpoint = new PolicyEndpoint( $policies, $policyVersions, $policyService );
|
||||
|
||||
@@ -92,7 +92,7 @@ class ShortcodeRegistrar {
|
||||
wp_register_script( 'us-scheduler-group', USC_PLUGIN_URL . 'assets/js/group-classes.js', [ 'us-scheduler-pricing', 'us-scheduler-guardian' ], USC_VERSION, true );
|
||||
|
||||
/*
|
||||
* Progressive enhancement for the two-step registration form.
|
||||
* Progressive enhancement for the registration form.
|
||||
*
|
||||
* `password-strength-meter` is WordPress's own wrapper around zxcvbn, so
|
||||
* the signup form scores a password exactly the way wp-admin does rather
|
||||
|
||||
Reference in New Issue
Block a user