Let parents register once and book for their children
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]>
This commit is contained in:
@@ -138,6 +138,7 @@ class Schema {
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
policy_version_id BIGINT UNSIGNED NOT NULL,
|
||||
student_id BIGINT UNSIGNED NOT NULL,
|
||||
accepted_by BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
registration_type VARCHAR(20) NOT NULL,
|
||||
registration_id BIGINT UNSIGNED NOT NULL,
|
||||
accepted_at DATETIME NOT NULL,
|
||||
@@ -145,12 +146,14 @@ class Schema {
|
||||
PRIMARY KEY (id),
|
||||
KEY policy_version_id (policy_version_id),
|
||||
KEY student_id (student_id),
|
||||
KEY accepted_by (accepted_by),
|
||||
KEY registration (registration_type, registration_id)
|
||||
) {$charset};",
|
||||
|
||||
"CREATE TABLE {$prefix}us_payments (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
student_id BIGINT UNSIGNED NOT NULL,
|
||||
payer_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
instructor_id BIGINT UNSIGNED NOT NULL,
|
||||
registration_type VARCHAR(20) NOT NULL,
|
||||
registration_id BIGINT UNSIGNED NOT NULL,
|
||||
@@ -172,6 +175,7 @@ class Schema {
|
||||
paid_at DATETIME DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY student_id (student_id),
|
||||
KEY payer_id (payer_id),
|
||||
KEY instructor_id (instructor_id),
|
||||
KEY registration (registration_type, registration_id),
|
||||
KEY status (status)
|
||||
@@ -180,6 +184,7 @@ class Schema {
|
||||
"CREATE TABLE {$prefix}us_credits (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
student_id BIGINT UNSIGNED NOT NULL,
|
||||
payer_id BIGINT UNSIGNED NOT NULL DEFAULT 0,
|
||||
amount DECIMAL(10,2) NOT NULL DEFAULT 0,
|
||||
remaining DECIMAL(10,2) NOT NULL DEFAULT 0,
|
||||
currency VARCHAR(3) NOT NULL DEFAULT 'CAD',
|
||||
@@ -191,6 +196,7 @@ class Schema {
|
||||
updated_at DATETIME DEFAULT NULL,
|
||||
PRIMARY KEY (id),
|
||||
KEY student_id (student_id),
|
||||
KEY payer_id (payer_id),
|
||||
KEY status (status),
|
||||
KEY source_lesson_id (source_lesson_id)
|
||||
) {$charset};",
|
||||
@@ -229,6 +235,21 @@ class Schema {
|
||||
KEY status (status)
|
||||
) {$charset};",
|
||||
|
||||
// Links a parent/guardian account to a child who books through it. The
|
||||
// child is a real (login-less) wp_users row, so student_id keeps meaning
|
||||
// "a WordPress user" on every other table.
|
||||
"CREATE TABLE {$prefix}us_guardians (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
guardian_id BIGINT UNSIGNED NOT NULL,
|
||||
student_id BIGINT UNSIGNED NOT NULL,
|
||||
relationship VARCHAR(50) NOT NULL DEFAULT '',
|
||||
created_at DATETIME NOT NULL,
|
||||
PRIMARY KEY (id),
|
||||
UNIQUE KEY guardian_student (guardian_id, student_id),
|
||||
KEY guardian_id (guardian_id),
|
||||
KEY student_id (student_id)
|
||||
) {$charset};",
|
||||
|
||||
"CREATE TABLE {$prefix}us_group_access (
|
||||
id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
offering_id BIGINT UNSIGNED NOT NULL,
|
||||
|
||||
Reference in New Issue
Block a user