A parent registers once and manages lessons for one or more children, who need no login of their own. A child is a real wp_users row with the student role but no usable login — so student_id keeps meaning "a WordPress user" on every table, and booking, credits, policies and enrolments work unchanged. A us_guardians link table maps guardian to child. The signup form gains a parent/guardian tick that reveals a block per child, with the account-signup questions asked per child rather than per guardian — they describe the student, not the account holder. Signup policies are recorded once per child with the guardian as the acceptor, which is the record that actually means something. A family that half-creates is rolled back entirely rather than leaving a guardian who cannot re-register. The booking and enrolment forms gain a "Who is this for?" picker listing children first, so the default selection is never the parent — booking for the wrong child is correctable, quietly billing a parent for their kid's lesson is not. POST /bookings and POST /enrollments take an optional student_id honoured only for that child's guardian; anything else is a 403. That check is the authorisation boundary of the feature. Payments and credits gain a payer: the charge names the child it was for and the guardian who owes it, so per-child reporting is unchanged while notices, receipts and the payment step reach the parent. Credit is held by the payer, so one child's cancellation can settle a sibling's charge, and the daily billing scan sends a guardian one notice covering every child. Closes #132 Co-Authored-By: Claude Opus 5 <[email protected]>
117 lines
6.0 KiB
PHP
117 lines
6.0 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular;
|
|
|
|
use Unsupervised\Schedular\Auth\EmailConfirmationHandler;
|
|
use Unsupervised\Schedular\Auth\InviteRepository;
|
|
use Unsupervised\Schedular\Auth\LoginPage;
|
|
use Unsupervised\Schedular\Auth\RegistrationLoginGate;
|
|
use Unsupervised\Schedular\Auth\RegistrationMailer;
|
|
use Unsupervised\Schedular\Auth\RegistrationPage;
|
|
use Unsupervised\Schedular\Auth\RoleManager;
|
|
use Unsupervised\Schedular\Auth\StudentAdminGuard;
|
|
use Unsupervised\Schedular\Booking\BookingPage;
|
|
use Unsupervised\Schedular\Availability\AvailabilityRepository;
|
|
use Unsupervised\Schedular\Booking\BookingRepository;
|
|
use Unsupervised\Schedular\GroupClass\EnrollmentRepository;
|
|
use Unsupervised\Schedular\GroupClass\GroupAccessRepository;
|
|
use Unsupervised\Schedular\GroupClass\GroupClassPage;
|
|
use Unsupervised\Schedular\Guardian\ChildLoginGate;
|
|
use Unsupervised\Schedular\Guardian\FamilyPage;
|
|
use Unsupervised\Schedular\Guardian\GuardianRepository;
|
|
use Unsupervised\Schedular\Guardian\GuardianService;
|
|
use Unsupervised\Schedular\Offering\OfferingRepository;
|
|
use Unsupervised\Schedular\Payment\BillingMethodResolver;
|
|
use Unsupervised\Schedular\Payment\CreditRepository;
|
|
use Unsupervised\Schedular\Payment\PaymentRepository;
|
|
use Unsupervised\Schedular\Payment\PaymentDueMailer;
|
|
use Unsupervised\Schedular\Payment\PaymentService;
|
|
use Unsupervised\Schedular\Payment\ReceiptMailer;
|
|
use Unsupervised\Schedular\Payment\ScheduledBillingRunner;
|
|
use Unsupervised\Schedular\Payment\StripeGateway;
|
|
use Unsupervised\Schedular\Payment\StudioSettings;
|
|
use Unsupervised\Schedular\Policy\AcceptanceRepository;
|
|
use Unsupervised\Schedular\Policy\PolicyRepository;
|
|
use Unsupervised\Schedular\Policy\PolicyService;
|
|
use Unsupervised\Schedular\Policy\PolicyVersionRepository;
|
|
use Unsupervised\Schedular\Registration\AnswerRepository;
|
|
use Unsupervised\Schedular\Registration\QuestionRepository;
|
|
use Unsupervised\Schedular\Registration\RegistrationGate;
|
|
use Unsupervised\Schedular\Update\UpdateChecker;
|
|
|
|
class Plugin {
|
|
|
|
public static function boot(): void {
|
|
load_plugin_textdomain( 'unsupervised-schedular', false, dirname( plugin_basename( USC_PLUGIN_FILE ) ) . '/languages' );
|
|
|
|
global $wpdb;
|
|
if ( ! $wpdb instanceof \wpdb ) {
|
|
return;
|
|
}
|
|
|
|
// Re-run install steps when the plugin files were updated without a fresh
|
|
// activation (e.g. a deploy), so schema and data migrations still apply.
|
|
if ( get_option( 'us_schedular_version' ) !== USC_VERSION ) {
|
|
( new Installer() )->run();
|
|
}
|
|
|
|
$availability = new AvailabilityRepository( $wpdb );
|
|
$bookings = new BookingRepository( $wpdb );
|
|
$offerings = new OfferingRepository( $wpdb );
|
|
$questions = new QuestionRepository( $wpdb );
|
|
|
|
// One-time repair for sites where dbDelta left us_questions.offering_id
|
|
// NOT NULL (it does not reliably relax NULL-ability), which breaks
|
|
// account-scope registration questions. Guarded by its own flag rather
|
|
// than the version gate, since affected sites may already be on the
|
|
// current version. The flag is only set once the ALTER succeeds.
|
|
if ( '1' !== get_option( 'us_questions_offering_nullable', '' ) && $questions->ensureOfferingNullable() ) {
|
|
update_option( 'us_questions_offering_nullable', '1' );
|
|
}
|
|
|
|
$answers = new AnswerRepository( $wpdb );
|
|
$policies = new PolicyRepository( $wpdb );
|
|
$policyVersions = new PolicyVersionRepository( $wpdb );
|
|
$policyService = new PolicyService( $policies, $policyVersions );
|
|
$acceptances = new AcceptanceRepository( $wpdb );
|
|
$invites = new InviteRepository( $wpdb );
|
|
$enrollments = new EnrollmentRepository( $wpdb );
|
|
$groupAccess = new GroupAccessRepository( $wpdb );
|
|
$registrationGate = new RegistrationGate( $questions, $answers, $policies, $policyVersions, $acceptances );
|
|
|
|
$guardianRepo = new GuardianRepository( $wpdb );
|
|
$guardians = new GuardianService( $guardianRepo, $bookings, $enrollments );
|
|
|
|
$paymentRepo = new PaymentRepository( $wpdb );
|
|
$creditRepo = new CreditRepository( $wpdb );
|
|
$settings = new StudioSettings();
|
|
$resolver = new BillingMethodResolver( $settings );
|
|
$stripe = new StripeGateway( $settings );
|
|
$paymentService = new PaymentService( $paymentRepo, $resolver, new ReceiptMailer(), $bookings, $enrollments, $settings, $stripe, $creditRepo );
|
|
|
|
// The shortcode and block wrappers share the same page objects so
|
|
// front-end output is identical whichever way a page embeds them.
|
|
$registrationMailer = new RegistrationMailer();
|
|
|
|
$bookingPage = new BookingPage( $guardians );
|
|
$loginPage = new LoginPage();
|
|
$registrationPage = new RegistrationPage( $invites, $policies, $policyVersions, $acceptances, $settings, $registrationMailer, $questions, $answers, $groupAccess, $guardians );
|
|
$groupClassPage = new GroupClassPage( $guardians );
|
|
$familyPage = new FamilyPage( $guardians, $questions, $answers );
|
|
|
|
( new ScheduledBillingRunner( $paymentService, $bookings, $enrollments, $offerings, new PaymentDueMailer(), $guardians ) )->register();
|
|
|
|
( new UpdateChecker() )->register();
|
|
( new RoleManager() )->register();
|
|
( new RegistrationLoginGate() )->register();
|
|
( new ChildLoginGate() )->register();
|
|
( new StudentAdminGuard() )->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();
|
|
( new ShortcodeRegistrar( $bookingPage, $loginPage, $registrationPage, $groupClassPage, $familyPage ) )->register();
|
|
( new BlockRegistrar( $bookingPage, $loginPage, $registrationPage, $groupClassPage, $familyPage ) )->register();
|
|
}
|
|
}
|