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]>
54 lines
1.7 KiB
PHP
54 lines
1.7 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
namespace Unsupervised\Schedular\GroupClass;
|
|
|
|
use Unsupervised\Schedular\Auth\RoleManager;
|
|
use Unsupervised\Schedular\Guardian\GuardianService;
|
|
use Unsupervised\Schedular\Val;
|
|
|
|
class GroupClassPage {
|
|
|
|
public function __construct( private GuardianService $guardians ) {}
|
|
|
|
/**
|
|
* Renders the group-class enrolment shortcode output.
|
|
*
|
|
* Supported attributes: `offering` (shortcode) / `offeringId` (block) — an
|
|
* offering id that restricts the page to a single class, so the shortcode
|
|
* can be embedded on a page dedicated to that class. 0 or absent shows the
|
|
* full browsable catalog.
|
|
*
|
|
* @param array<int|string, mixed> $atts Shortcode or block attributes.
|
|
*/
|
|
public function render( array $atts ): string {
|
|
if ( ! is_user_logged_in() ) {
|
|
$permalink = get_permalink();
|
|
|
|
return sprintf(
|
|
'<p>%s <a href="%s">%s</a>.</p>',
|
|
esc_html__( 'Please', 'unsupervised-schedular' ),
|
|
esc_url( wp_login_url( false === $permalink ? '' : $permalink ) ),
|
|
esc_html__( 'log in to enrol in a class', 'unsupervised-schedular' )
|
|
);
|
|
}
|
|
|
|
if ( ! current_user_can( RoleManager::CAP_BOOK_LESSON ) ) {
|
|
return '<p>' . esc_html__( 'This page is for students only.', 'unsupervised-schedular' ) . '</p>';
|
|
}
|
|
|
|
wp_enqueue_style( 'us-scheduler' );
|
|
wp_enqueue_script( 'us-scheduler-group' );
|
|
|
|
$offeringId = absint( Val::int( $atts['offering'] ?? $atts['offeringId'] ?? 0 ) );
|
|
|
|
// Who this account may enrol — children first, the account holder last, so
|
|
// a guardian's default choice is a child rather than themselves.
|
|
$students = $this->guardians->bookableStudents( get_current_user_id() );
|
|
|
|
ob_start();
|
|
include USC_PLUGIN_DIR . 'templates/frontend/group-classes-page.php';
|
|
return (string) ob_get_clean();
|
|
}
|
|
}
|