Compare commits
11
Commits
b0952ca06d
...
v1.2.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a25c397c5 | ||
|
|
264d9cba01
|
||
|
|
689ec833f3 | ||
|
|
0f30f28e92
|
||
|
|
9d11cc3b01
|
||
|
|
add6605141 | ||
|
|
edcacae816
|
||
|
|
17487cde46 | ||
|
|
13d6b3e14e
|
||
|
|
d866aa7295 | ||
|
|
c4acdb7ca4
|
@@ -13,6 +13,12 @@ each change under the current top section as you work.
|
|||||||
|
|
||||||
## [1.2.2]
|
## [1.2.2]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
- The **Lesson Booking** block gained three embedding options in its sidebar. **Lesson type** pins the block to a single private-lesson type — only the times bookable as that type are listed and it is the only thing bookable there, auto-selected on the registration form — so a page about one lesson type can carry its own calendar. **Show the lesson-type filter** turns the **Show Only** control on or off. **Sections** embeds just one half of the page: booking calendar only, or the student's upcoming lessons only, so the two can live on different pages. All three are available to the shortcode as `[us_booking lesson_type="…" show_filter="no" show="booking|upcoming"]`, and the block's editor preview follows the chosen sections.
|
||||||
|
- The booking calendar now has a **Show Only** button beside the List/Week toggle that opens a lesson-type filter, so a student browsing open times can narrow them to the types they actually want. Because not every open time can be booked as every private-lesson type — some times are tied to a specific type, others only take types of a matching length — the filter shows just the times bookable as the ticked types, and re-anchors the week view on the earliest one so it never opens on an empty week. Picking one of those times narrows the **Lesson type** picker on the registration form to the same list, and when only one type is left it is chosen automatically with its questions loaded. The type list starts collapsed and can be tucked away again without losing the filter; the button shows how many types are ticked. Tick nothing (or use **Show all types**) to see every open time as before. The filter is hidden when the studio only offers one private-lesson type.
|
||||||
|
- The **Group Classes** block can now be pinned to a single class, under **Classes shown → Class** in the block sidebar (shortcode: `[us_group_classes offering="…"]`). Pick a class and the block shows only that one, so it can be embedded on a page that describes the class. In this mode the class's own description is left out to avoid repeating the page copy — the card shows the schedule, instructor, price, enrolment deadline and the enrol/withdraw controls. Leaving it on **All classes** keeps the full browsable catalog with descriptions.
|
||||||
|
- The **Student Registration** block can now send students onward to a page of your choosing once they finish registering. Its **After email confirmation** panel is now **After registration**: the page you pick there is where the link shown to a newly registered student points — the "Sign in to your account" link after they confirm their email, and a "Continue to your account" link for an invited student, who is signed in immediately. A new **Redirect automatically** option takes them straight there instead of showing the link. Registration errors are never skipped — a failed sign-up and an expired confirmation link still show their message on the page, as does the "check your email to confirm your address" step. The redirect needs a page to be chosen; with none set, students see the link (or, for invited students, just the confirmation) as before.
|
||||||
|
|
||||||
## [1.2.1]
|
## [1.2.1]
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
+58
-1
@@ -117,10 +117,67 @@
|
|||||||
color: #8a6d1a;
|
color: #8a6d1a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.us-calendar-controls {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.us-filter-toggle {
|
||||||
|
padding: 6px 16px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
|
.us-filter-toggle.us-active {
|
||||||
|
background: #333;
|
||||||
|
border-color: #333;
|
||||||
|
color: #fff;
|
||||||
|
}
|
||||||
|
|
||||||
|
.us-type-filter {
|
||||||
|
margin-bottom: 12px;
|
||||||
|
padding: 8px 12px;
|
||||||
|
border: 1px solid #eee;
|
||||||
|
border-radius: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.us-type-filter-heading {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
font-weight: 600;
|
||||||
|
}
|
||||||
|
|
||||||
|
.us-type-filter-choices {
|
||||||
|
display: flex;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.us-type-filter-choice {
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.us-type-filter-clear {
|
||||||
|
margin-left: auto;
|
||||||
|
padding: 4px 12px;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 4px;
|
||||||
|
background: transparent;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.us-view-toggle {
|
.us-view-toggle {
|
||||||
display: flex;
|
display: flex;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
margin-bottom: 12px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.us-view-toggle button {
|
.us-view-toggle button {
|
||||||
|
|||||||
+89
-5
@@ -83,6 +83,47 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Dropdown of active private-lesson types fetched from the plugin's public
|
||||||
|
* offerings endpoint. Values are offering IDs; 0 means every type.
|
||||||
|
*/
|
||||||
|
function LessonTypeSelect(props) {
|
||||||
|
const [offerings, setOfferings] = useState(null);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
apiFetch({ path: '/us-scheduler/v1/offerings?kind=private_lesson' })
|
||||||
|
.then(setOfferings)
|
||||||
|
.catch(() => setOfferings([]));
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const options = [{ label: __('All lesson types', 'unsupervised-schedular'), value: '0' }].concat(
|
||||||
|
(offerings || []).map((o) => ({
|
||||||
|
label: o.duration_minutes
|
||||||
|
? `${o.title} (${o.duration_minutes} min)`
|
||||||
|
: (o.title || __('(no title)', 'unsupervised-schedular')),
|
||||||
|
value: String(o.id),
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
|
// A previously chosen type that is no longer offered keeps its stored
|
||||||
|
// id visible instead of silently pretending "All lesson types" is set.
|
||||||
|
const value = String(props.value || 0);
|
||||||
|
if (offerings !== null && !options.some((opt) => opt.value === value)) {
|
||||||
|
options.push({
|
||||||
|
label: __('Unavailable lesson type #', 'unsupervised-schedular') + value,
|
||||||
|
value: value,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return el(SelectControl, {
|
||||||
|
label: props.label,
|
||||||
|
help: props.help,
|
||||||
|
value: value,
|
||||||
|
options: options,
|
||||||
|
onChange: (newValue) => props.onChange(parseInt(newValue, 10) || 0),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const blocks = [
|
const blocks = [
|
||||||
{
|
{
|
||||||
name: 'us-scheduler/booking',
|
name: 'us-scheduler/booking',
|
||||||
@@ -94,10 +135,45 @@
|
|||||||
attributes: {
|
attributes: {
|
||||||
loginPageId: { type: 'number', default: 0 },
|
loginPageId: { type: 'number', default: 0 },
|
||||||
autoRedirect: { type: 'boolean', default: false },
|
autoRedirect: { type: 'boolean', default: false },
|
||||||
|
lessonTypeId: { type: 'number', default: 0 },
|
||||||
|
showTypeFilter: { type: 'boolean', default: true },
|
||||||
|
displayMode: { type: 'string', default: 'both' },
|
||||||
},
|
},
|
||||||
inspector: (attributes, setAttributes) => el(
|
inspector: (attributes, setAttributes) => [
|
||||||
|
el(
|
||||||
PanelBody,
|
PanelBody,
|
||||||
{ title: __('Logged-out visitors', 'unsupervised-schedular') },
|
{ title: __('What to show', 'unsupervised-schedular'), key: 'display' },
|
||||||
|
el(SelectControl, {
|
||||||
|
label: __('Sections', 'unsupervised-schedular'),
|
||||||
|
help: __('Split the page in two: a booking calendar here, the student’s upcoming lessons somewhere else.', 'unsupervised-schedular'),
|
||||||
|
value: attributes.displayMode || 'both',
|
||||||
|
options: [
|
||||||
|
{ label: __('Booking and upcoming lessons', 'unsupervised-schedular'), value: 'both' },
|
||||||
|
{ label: __('Booking only', 'unsupervised-schedular'), value: 'booking' },
|
||||||
|
{ label: __('Upcoming lessons only', 'unsupervised-schedular'), value: 'upcoming' },
|
||||||
|
],
|
||||||
|
onChange: (displayMode) => setAttributes({ displayMode }),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
el(
|
||||||
|
PanelBody,
|
||||||
|
{ title: __('Lesson types', 'unsupervised-schedular'), key: 'lesson-types' },
|
||||||
|
el(LessonTypeSelect, {
|
||||||
|
label: __('Lesson type', 'unsupervised-schedular'),
|
||||||
|
help: __('Show only the times bookable as one lesson type, for embedding on a page dedicated to it. That type is then the only one students can book here.', 'unsupervised-schedular'),
|
||||||
|
value: attributes.lessonTypeId,
|
||||||
|
onChange: (lessonTypeId) => setAttributes({ lessonTypeId }),
|
||||||
|
}),
|
||||||
|
el(ToggleControl, {
|
||||||
|
label: __('Show the lesson-type filter', 'unsupervised-schedular'),
|
||||||
|
help: __('Offer students the “Show Only” button that narrows the calendar to chosen lesson types. Not used when a single lesson type is set above.', 'unsupervised-schedular'),
|
||||||
|
checked: attributes.showTypeFilter !== false,
|
||||||
|
onChange: (showTypeFilter) => setAttributes({ showTypeFilter }),
|
||||||
|
})
|
||||||
|
),
|
||||||
|
el(
|
||||||
|
PanelBody,
|
||||||
|
{ title: __('Logged-out visitors', 'unsupervised-schedular'), key: 'logged-out' },
|
||||||
el(PageSelect, {
|
el(PageSelect, {
|
||||||
label: __('Login page', 'unsupervised-schedular'),
|
label: __('Login page', 'unsupervised-schedular'),
|
||||||
help: __('Where the log-in link sends visitors who are not logged in.', 'unsupervised-schedular'),
|
help: __('Where the log-in link sends visitors who are not logged in.', 'unsupervised-schedular'),
|
||||||
@@ -112,6 +188,7 @@
|
|||||||
onChange: (autoRedirect) => setAttributes({ autoRedirect }),
|
onChange: (autoRedirect) => setAttributes({ autoRedirect }),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
|
],
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'us-scheduler/student-login',
|
name: 'us-scheduler/student-login',
|
||||||
@@ -151,18 +228,25 @@
|
|||||||
shortcode: 'us_student_register',
|
shortcode: 'us_student_register',
|
||||||
attributes: {
|
attributes: {
|
||||||
loginPageId: { type: 'number', default: 0 },
|
loginPageId: { type: 'number', default: 0 },
|
||||||
|
autoRedirect: { type: 'boolean', default: false },
|
||||||
inviteOnlyMessage: { type: 'string', default: '' },
|
inviteOnlyMessage: { type: 'string', default: '' },
|
||||||
},
|
},
|
||||||
inspector: (attributes, setAttributes) => [
|
inspector: (attributes, setAttributes) => [
|
||||||
el(
|
el(
|
||||||
PanelBody,
|
PanelBody,
|
||||||
{ title: __('After email confirmation', 'unsupervised-schedular'), key: 'confirmation' },
|
{ title: __('After registration', 'unsupervised-schedular'), key: 'confirmation' },
|
||||||
el(PageSelect, {
|
el(PageSelect, {
|
||||||
label: __('Sign-in page', 'unsupervised-schedular'),
|
label: __('Sign-in page', 'unsupervised-schedular'),
|
||||||
help: __('Where the sign-in link shown after a student confirms their email address sends them.', 'unsupervised-schedular'),
|
help: __('Where students are sent once registration finishes — after they confirm their email address, or straight away for an invited student.', 'unsupervised-schedular'),
|
||||||
defaultLabel: __('WordPress login screen', 'unsupervised-schedular'),
|
defaultLabel: __('WordPress login screen', 'unsupervised-schedular'),
|
||||||
value: attributes.loginPageId,
|
value: attributes.loginPageId,
|
||||||
onChange: (loginPageId) => setAttributes({ loginPageId }),
|
onChange: (loginPageId) => setAttributes({ loginPageId }),
|
||||||
|
}),
|
||||||
|
el(ToggleControl, {
|
||||||
|
label: __('Redirect automatically', 'unsupervised-schedular'),
|
||||||
|
help: __('Send students straight to that page instead of showing the link. Requires a page to be chosen; errors and the "check your email" step are never skipped.', 'unsupervised-schedular'),
|
||||||
|
checked: !!attributes.autoRedirect,
|
||||||
|
onChange: (autoRedirect) => setAttributes({ autoRedirect }),
|
||||||
})
|
})
|
||||||
),
|
),
|
||||||
el(
|
el(
|
||||||
@@ -192,7 +276,7 @@
|
|||||||
{ title: __('Classes shown', 'unsupervised-schedular') },
|
{ title: __('Classes shown', 'unsupervised-schedular') },
|
||||||
el(GroupClassSelect, {
|
el(GroupClassSelect, {
|
||||||
label: __('Class', 'unsupervised-schedular'),
|
label: __('Class', 'unsupervised-schedular'),
|
||||||
help: __('Show only one group class, for embedding on a page dedicated to it.', 'unsupervised-schedular'),
|
help: __('Show only one group class, for embedding on a page dedicated to it. That class’s description is left out — the card shows just the schedule, price and enrolment controls.', 'unsupervised-schedular'),
|
||||||
value: attributes.offeringId,
|
value: attributes.offeringId,
|
||||||
onChange: (offeringId) => setAttributes({ offeringId }),
|
onChange: (offeringId) => setAttributes({ offeringId }),
|
||||||
})
|
})
|
||||||
|
|||||||
+212
-42
@@ -11,6 +11,11 @@
|
|||||||
const errorBox = document.getElementById('us-booking-error');
|
const errorBox = document.getElementById('us-booking-error');
|
||||||
const { restUrl, nonce } = usScheduler;
|
const { restUrl, nonce } = usScheduler;
|
||||||
|
|
||||||
|
// Per-instance options from the block/shortcode: pin the page to a single
|
||||||
|
// lesson type, and whether the "Show Only" filter is offered at all.
|
||||||
|
const pinnedTypeId = Number(app.dataset.lessonType) || 0;
|
||||||
|
const filterEnabled = app.dataset.typeFilter !== '0';
|
||||||
|
|
||||||
function apiFetch(path, options = {}) {
|
function apiFetch(path, options = {}) {
|
||||||
return fetch(restUrl + path, {
|
return fetch(restUrl + path, {
|
||||||
...options,
|
...options,
|
||||||
@@ -81,6 +86,45 @@
|
|||||||
let view = 'week';
|
let view = 'week';
|
||||||
let weekStart = null;
|
let weekStart = null;
|
||||||
|
|
||||||
|
// Every active private-lesson type the student may book, across instructors.
|
||||||
|
let catalog = [];
|
||||||
|
|
||||||
|
// Lesson types the student has filtered the calendar down to; empty means
|
||||||
|
// "no filter" — every open slot is shown. The list starts collapsed behind
|
||||||
|
// the "Show Only" button and stays open across re-renders once revealed.
|
||||||
|
const selectedTypeIds = new Set();
|
||||||
|
let filterOpen = false;
|
||||||
|
|
||||||
|
// Whether an offering can be booked into a slot — the client-side mirror of
|
||||||
|
// the rule `POST /bookings` enforces: a slot tied to an offering takes that
|
||||||
|
// offering only, and a generic slot takes any of its instructor's types
|
||||||
|
// whose length fits.
|
||||||
|
function offeringFitsSlot(offering, slot) {
|
||||||
|
if (Number(offering.instructor_id) !== Number(slot.instructor_id)) return false;
|
||||||
|
|
||||||
|
const tiedId = Number(slot.offering_id) || 0;
|
||||||
|
if (tiedId) return Number(offering.id) === tiedId;
|
||||||
|
|
||||||
|
return !offering.duration_minutes
|
||||||
|
|| Number(offering.duration_minutes) === Number(slot.duration_minutes);
|
||||||
|
}
|
||||||
|
|
||||||
|
const filterActive = () => selectedTypeIds.size > 0;
|
||||||
|
|
||||||
|
const typeSelected = (offering) => !filterActive() || selectedTypeIds.has(Number(offering.id));
|
||||||
|
|
||||||
|
// The lesson types this slot could be booked as, honouring the filter.
|
||||||
|
function slotChoices(slot) {
|
||||||
|
return catalog.filter((o) => offeringFitsSlot(o, slot) && typeSelected(o));
|
||||||
|
}
|
||||||
|
|
||||||
|
// With a filter set, a slot is only shown when one of the chosen lesson
|
||||||
|
// types can actually be booked into it.
|
||||||
|
function visibleSlots() {
|
||||||
|
if (!filterActive()) return allSlots;
|
||||||
|
return allSlots.filter((slot) => slotChoices(slot).length > 0);
|
||||||
|
}
|
||||||
|
|
||||||
const pad = (n) => String(n).padStart(2, '0');
|
const pad = (n) => String(n).padStart(2, '0');
|
||||||
const toKey = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
const toKey = (d) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`;
|
||||||
|
|
||||||
@@ -98,17 +142,67 @@
|
|||||||
return addDays(key, -((date.getDay() - startOfWeek + 7) % 7));
|
return addDays(key, -((date.getDay() - startOfWeek + 7) % 7));
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleHtml() {
|
// The calendar's control row: the view toggle, and the button that reveals
|
||||||
|
// the lesson-type filter beneath it.
|
||||||
|
function controlsHtml() {
|
||||||
return `
|
return `
|
||||||
|
<div class="us-calendar-controls">
|
||||||
<div class="us-view-toggle" role="group" aria-label="Calendar view">
|
<div class="us-view-toggle" role="group" aria-label="Calendar view">
|
||||||
<button type="button" id="us-view-list" class="${view === 'list' ? 'us-active' : ''}">List</button>
|
<button type="button" id="us-view-list" class="${view === 'list' ? 'us-active' : ''}">List</button>
|
||||||
<button type="button" id="us-view-week" class="${view === 'week' ? 'us-active' : ''}">Week</button>
|
<button type="button" id="us-view-week" class="${view === 'week' ? 'us-active' : ''}">Week</button>
|
||||||
|
</div>
|
||||||
|
${filterToggleHtml()}
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing to filter with a single bookable type, so the control only
|
||||||
|
// appears once there is a choice to make.
|
||||||
|
function filterToggleHtml() {
|
||||||
|
if (!filterEnabled || catalog.length < 2) return '';
|
||||||
|
|
||||||
|
const count = filterActive() ? ` (${selectedTypeIds.size})` : '';
|
||||||
|
|
||||||
|
return `
|
||||||
|
<button type="button" id="us-filter-toggle" class="us-filter-toggle${filterActive() ? ' us-active' : ''}"
|
||||||
|
aria-expanded="${filterOpen}" aria-controls="us-type-filter">Show Only${count}</button>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// "Piano Lesson (30 min)" — the instructor's name is only worth the space
|
||||||
|
// when the catalog spans more than one of them.
|
||||||
|
function filterLabel(offering) {
|
||||||
|
const duration = offering.duration_minutes ? ` (${offering.duration_minutes} min)` : '';
|
||||||
|
const instructors = new Set(catalog.map((o) => Number(o.instructor_id)));
|
||||||
|
const who = instructors.size > 1 && offering.instructor_name
|
||||||
|
? ` — ${offering.instructor_name}`
|
||||||
|
: '';
|
||||||
|
return `${offering.title}${duration}${who}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The lesson-type list itself — collapsed until the student opens it, and
|
||||||
|
// rendered between the control row and the calendar.
|
||||||
|
function filterHtml() {
|
||||||
|
if (!filterEnabled || catalog.length < 2 || !filterOpen) return '';
|
||||||
|
|
||||||
|
const choices = catalog.map((o) => `
|
||||||
|
<label class="us-type-filter-choice">
|
||||||
|
<input type="checkbox" class="us-type-filter-option" value="${o.id}" ${selectedTypeIds.has(Number(o.id)) ? 'checked' : ''}>
|
||||||
|
${escHtml(filterLabel(o))}
|
||||||
|
</label>
|
||||||
|
`).join('');
|
||||||
|
|
||||||
|
return `
|
||||||
|
<div class="us-type-filter" id="us-type-filter" role="group" aria-label="Filter by lesson type">
|
||||||
|
<span class="us-type-filter-heading">Lesson type</span>
|
||||||
|
<div class="us-type-filter-choices">
|
||||||
|
${choices}
|
||||||
|
${filterActive() ? '<button type="button" id="us-type-filter-clear" class="us-type-filter-clear">Show all types</button>' : ''}
|
||||||
|
</div>
|
||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Agenda-style calendar: available slots grouped by day.
|
// Agenda-style calendar: available slots grouped by day.
|
||||||
function listHtml() {
|
function listHtml(slots) {
|
||||||
return groupByDay(allSlots).map(([key, daySlots]) => `
|
return groupByDay(slots).map(([key, daySlots]) => `
|
||||||
<div class="us-day">
|
<div class="us-day">
|
||||||
<h3 class="us-day-heading">${escHtml(dayLabel(key))}</h3>
|
<h3 class="us-day-heading">${escHtml(dayLabel(key))}</h3>
|
||||||
${daySlots.map((slot) => `
|
${daySlots.map((slot) => `
|
||||||
@@ -122,8 +216,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Weekly calendar: seven day columns with a bookable button per slot.
|
// Weekly calendar: seven day columns with a bookable button per slot.
|
||||||
function weekHtml() {
|
function weekHtml(slots) {
|
||||||
const byDay = new Map(groupByDay(allSlots));
|
const byDay = new Map(groupByDay(slots));
|
||||||
const days = [...Array(7).keys()].map((i) => addDays(weekStart, i));
|
const days = [...Array(7).keys()].map((i) => addDays(weekStart, i));
|
||||||
|
|
||||||
const columns = days.map((key) => {
|
const columns = days.map((key) => {
|
||||||
@@ -151,20 +245,41 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function render() {
|
function render() {
|
||||||
|
const slots = visibleSlots();
|
||||||
|
|
||||||
|
// The pinned lesson type is no longer on offer (deactivated or
|
||||||
|
// deleted), so this page has nothing it is allowed to book.
|
||||||
|
if (pinnedTypeId && !catalog.length) {
|
||||||
|
slotList.innerHTML = '<p>This lesson type is not available for booking right now.</p>';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nothing open at all: there is nothing for the controls to act on.
|
||||||
if (!allSlots.length) {
|
if (!allSlots.length) {
|
||||||
slotList.innerHTML = '<p>No available lesson slots at this time.</p>';
|
slotList.innerHTML = '<p>No available lesson slots at this time.</p>';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Anchor the week view to the week of the earliest open slot (the API
|
if (!slots.length) {
|
||||||
// returns slots ordered by start), so the first look is never empty.
|
const message = pinnedTypeId
|
||||||
if (view === 'week' && !weekStart) weekStart = weekStartOf(dayKey(allSlots[0].start_dt));
|
? '<p>No open times for this lesson type right now.</p>'
|
||||||
|
: '<p>No open times match the selected lesson types.</p>';
|
||||||
|
|
||||||
slotList.innerHTML = toggleHtml() + (view === 'week' ? weekHtml() : listHtml());
|
slotList.innerHTML = controlsHtml() + filterHtml() + message;
|
||||||
|
wireControlEvents();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Anchor the week view to the week of the earliest matching slot (the
|
||||||
|
// API returns slots ordered by start), so the first look is never empty.
|
||||||
|
if (view === 'week' && !weekStart) weekStart = weekStartOf(dayKey(slots[0].start_dt));
|
||||||
|
|
||||||
|
slotList.innerHTML = controlsHtml() + filterHtml() + (view === 'week' ? weekHtml(slots) : listHtml(slots));
|
||||||
|
wireControlEvents();
|
||||||
wireCalendarEvents();
|
wireCalendarEvents();
|
||||||
}
|
}
|
||||||
|
|
||||||
function wireCalendarEvents() {
|
function wireControlEvents() {
|
||||||
document.getElementById('us-view-list').addEventListener('click', () => {
|
document.getElementById('us-view-list').addEventListener('click', () => {
|
||||||
view = 'list';
|
view = 'list';
|
||||||
render();
|
render();
|
||||||
@@ -174,6 +289,40 @@
|
|||||||
render();
|
render();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const toggle = document.getElementById('us-filter-toggle');
|
||||||
|
if (toggle) {
|
||||||
|
toggle.addEventListener('click', () => {
|
||||||
|
filterOpen = !filterOpen;
|
||||||
|
render();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
slotList.querySelectorAll('.us-type-filter-option').forEach((input) => {
|
||||||
|
input.addEventListener('change', () => {
|
||||||
|
const id = Number(input.value);
|
||||||
|
if (input.checked) {
|
||||||
|
selectedTypeIds.add(id);
|
||||||
|
} else {
|
||||||
|
selectedTypeIds.delete(id);
|
||||||
|
}
|
||||||
|
// The nearest matching time may be weeks away, so re-anchor the
|
||||||
|
// week view instead of leaving the student on an empty week.
|
||||||
|
weekStart = null;
|
||||||
|
render();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
const clear = document.getElementById('us-type-filter-clear');
|
||||||
|
if (clear) {
|
||||||
|
clear.addEventListener('click', () => {
|
||||||
|
selectedTypeIds.clear();
|
||||||
|
weekStart = null;
|
||||||
|
render();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function wireCalendarEvents() {
|
||||||
const prev = document.getElementById('us-week-prev');
|
const prev = document.getElementById('us-week-prev');
|
||||||
const next = document.getElementById('us-week-next');
|
const next = document.getElementById('us-week-next');
|
||||||
if (prev) prev.addEventListener('click', () => { weekStart = addDays(weekStart, -7); render(); });
|
if (prev) prev.addEventListener('click', () => { weekStart = addDays(weekStart, -7); render(); });
|
||||||
@@ -211,20 +360,6 @@
|
|||||||
</div>`;
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Active private-lesson offerings per instructor, so revisiting the
|
|
||||||
// registration form does not refetch the same catalog.
|
|
||||||
const offeringCache = new Map();
|
|
||||||
|
|
||||||
function instructorOfferings(instructorId) {
|
|
||||||
if (offeringCache.has(instructorId)) {
|
|
||||||
return Promise.resolve(offeringCache.get(instructorId));
|
|
||||||
}
|
|
||||||
return apiFetch(`offerings?instructor_id=${instructorId}&kind=private_lesson`).then((list) => {
|
|
||||||
offeringCache.set(instructorId, list);
|
|
||||||
return list;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// "Piano Lesson (60 min — $50.00 CAD)" / "Trial Lesson (Free)"
|
// "Piano Lesson (60 min — $50.00 CAD)" / "Trial Lesson (Free)"
|
||||||
function offeringLabel(o) {
|
function offeringLabel(o) {
|
||||||
const duration = o.duration_minutes ? `${o.duration_minutes} min — ` : '';
|
const duration = o.duration_minutes ? `${o.duration_minutes} min — ` : '';
|
||||||
@@ -237,13 +372,8 @@
|
|||||||
function openRegistration(slot) {
|
function openRegistration(slot) {
|
||||||
clearError();
|
clearError();
|
||||||
|
|
||||||
Promise.all([
|
apiFetch('policies?scope=booking')
|
||||||
instructorOfferings(Number(slot.instructor_id)),
|
.then((policies) => renderRegistration(slot, policies))
|
||||||
apiFetch('policies?scope=booking'),
|
|
||||||
])
|
|
||||||
.then(([offerings, policies]) => {
|
|
||||||
renderRegistration(slot, offerings, policies);
|
|
||||||
})
|
|
||||||
.catch((err) => showError(err.message));
|
.catch((err) => showError(err.message));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,6 +388,19 @@
|
|||||||
<select id="us-offering" disabled><option>${escHtml(label)}</option></select></label>
|
<select id="us-offering" disabled><option>${escHtml(label)}</option></select></label>
|
||||||
</p>`;
|
</p>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only one type is left to book this slot as — usually because the
|
||||||
|
// filter narrowed it down — so it is chosen for the student.
|
||||||
|
if (choices.length === 1) {
|
||||||
|
return `
|
||||||
|
<p class="us-offering">
|
||||||
|
<label>Lesson type<br>
|
||||||
|
<select id="us-offering" required>
|
||||||
|
<option value="${choices[0].id}" selected>${escHtml(offeringLabel(choices[0]))}</option>
|
||||||
|
</select></label>
|
||||||
|
</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<p class="us-offering">
|
<p class="us-offering">
|
||||||
<label>Lesson type<br>
|
<label>Lesson type<br>
|
||||||
@@ -268,14 +411,13 @@
|
|||||||
</p>`;
|
</p>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
function renderRegistration(slot, offerings, policies) {
|
function renderRegistration(slot, policies) {
|
||||||
const tiedId = Number(slot.offering_id) || 0;
|
const tiedId = Number(slot.offering_id) || 0;
|
||||||
const tied = tiedId ? offerings.find((o) => Number(o.id) === tiedId) : null;
|
const tied = tiedId ? catalog.find((o) => Number(o.id) === tiedId) : null;
|
||||||
|
|
||||||
// Generic slots offer every lesson type that fits the slot's length.
|
// Generic slots offer every lesson type that fits the slot — narrowed to
|
||||||
const choices = tiedId
|
// the filtered types when the student has set a filter.
|
||||||
? []
|
const choices = tiedId ? [] : slotChoices(slot);
|
||||||
: offerings.filter((o) => !o.duration_minutes || Number(o.duration_minutes) === Number(slot.duration_minutes));
|
|
||||||
|
|
||||||
if (!tiedId && !choices.length) {
|
if (!tiedId && !choices.length) {
|
||||||
// The server rejects offering-less bookings, so without a matching
|
// The server rejects offering-less bookings, so without a matching
|
||||||
@@ -309,8 +451,10 @@
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
// The intake questions belong to the selected offering, so they follow
|
// The intake questions belong to the selected offering, so they follow
|
||||||
// the picker instead of being fixed at render time.
|
// the picker instead of being fixed at render time. A tied slot — or a
|
||||||
let selectedId = tiedId;
|
// lone remaining type — is already decided, so its questions load
|
||||||
|
// straight away.
|
||||||
|
let selectedId = tiedId || (choices.length === 1 ? Number(choices[0].id) : 0);
|
||||||
let questions = [];
|
let questions = [];
|
||||||
|
|
||||||
const questionsBox = document.getElementById('us-questions');
|
const questionsBox = document.getElementById('us-questions');
|
||||||
@@ -467,13 +611,39 @@
|
|||||||
confirm.style.display = 'block';
|
confirm.style.display = 'block';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// The private-lesson catalog drives both the filter and the registration
|
||||||
|
// form's lesson-type picker, and it does not change while the student
|
||||||
|
// browses — so it is fetched once and kept.
|
||||||
|
let catalogLoaded = false;
|
||||||
|
|
||||||
|
function loadCatalog() {
|
||||||
|
if (catalogLoaded) return Promise.resolve(catalog);
|
||||||
|
return apiFetch('offerings?kind=private_lesson').then((list) => {
|
||||||
|
// A pinned lesson type is the only one this page may book, so the
|
||||||
|
// catalog is narrowed to it and the filter is fixed on it. With a
|
||||||
|
// single type left the "Show Only" control hides itself.
|
||||||
|
catalog = pinnedTypeId
|
||||||
|
? list.filter((o) => Number(o.id) === pinnedTypeId)
|
||||||
|
: list;
|
||||||
|
|
||||||
|
if (pinnedTypeId) selectedTypeIds.add(pinnedTypeId);
|
||||||
|
|
||||||
|
catalogLoaded = true;
|
||||||
|
return catalog;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function loadSlots() {
|
function loadSlots() {
|
||||||
clearError();
|
clearError();
|
||||||
|
loadMyLessons();
|
||||||
|
|
||||||
|
// An upcoming-lessons-only embed has no calendar to fill.
|
||||||
|
if (!slotList) return;
|
||||||
|
|
||||||
slotList.style.display = 'block';
|
slotList.style.display = 'block';
|
||||||
confirm.style.display = 'none';
|
confirm.style.display = 'none';
|
||||||
loadMyLessons();
|
Promise.all([apiFetch('availability'), loadCatalog()])
|
||||||
apiFetch('availability')
|
.then(([slots]) => {
|
||||||
.then((slots) => {
|
|
||||||
allSlots = slots;
|
allSlots = slots;
|
||||||
render();
|
render();
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -12,6 +12,9 @@
|
|||||||
|
|
||||||
// When the shortcode/block pins a single offering, only that class is
|
// When the shortcode/block pins a single offering, only that class is
|
||||||
// shown, so the page can be embedded alongside a full class description.
|
// shown, so the page can be embedded alongside a full class description.
|
||||||
|
// The class's own description is then omitted from the card — the page it
|
||||||
|
// sits on already describes the class — leaving the schedule, price and
|
||||||
|
// enrolment controls.
|
||||||
const singleOfferingId = Number(app.dataset.offering || 0);
|
const singleOfferingId = Number(app.dataset.offering || 0);
|
||||||
|
|
||||||
function apiFetch(path, options = {}) {
|
function apiFetch(path, options = {}) {
|
||||||
@@ -148,7 +151,7 @@
|
|||||||
${whenLabel(o) ? `<p class="us-class-when">${escHtml(whenLabel(o))}</p>` : ''}
|
${whenLabel(o) ? `<p class="us-class-when">${escHtml(whenLabel(o))}</p>` : ''}
|
||||||
${o.instructor_name ? `<p class="us-class-instructor">With ${escHtml(o.instructor_name)}</p>` : ''}
|
${o.instructor_name ? `<p class="us-class-instructor">With ${escHtml(o.instructor_name)}</p>` : ''}
|
||||||
${o.schedule_note ? `<p>${escHtml(o.schedule_note)}</p>` : ''}
|
${o.schedule_note ? `<p>${escHtml(o.schedule_note)}</p>` : ''}
|
||||||
${o.description ? `<p>${escHtml(o.description)}</p>` : ''}
|
${!singleOfferingId && o.description ? `<p>${escHtml(o.description)}</p>` : ''}
|
||||||
<p>${escHtml(Number(o.price).toFixed(2))} ${escHtml(o.currency)}</p>
|
<p>${escHtml(Number(o.price).toFixed(2))} ${escHtml(o.currency)}</p>
|
||||||
${!enrolledMap.has(Number(o.id)) && isEnrollmentOpen(o) && enrolmentDeadline(o)
|
${!enrolledMap.has(Number(o.id)) && isEnrollmentOpen(o) && enrolmentDeadline(o)
|
||||||
? `<p class="us-enrol-deadline">Enrol by ${escHtml(formatDate(enrolmentDeadline(o)))}</p>`
|
? `<p class="us-enrol-deadline">Enrol by ${escHtml(formatDate(enrolmentDeadline(o)))}</p>`
|
||||||
|
|||||||
@@ -128,6 +128,13 @@ recorded in `us_policy_acceptances` with `registration_type = account` and
|
|||||||
- `[us_student_register]` — the registration page. In `invite` mode: shows the form for a valid pending invite, else an "by invitation only" message. In `self_approval` mode: shows the form to anyone (editable email), and renders confirmation-result notices from `?us_confirmed=1|expired`.
|
- `[us_student_register]` — the registration page. In `invite` mode: shows the form for a valid pending invite, else an "by invitation only" message. In `self_approval` mode: shows the form to anyone (editable email), and renders confirmation-result notices from `?us_confirmed=1|expired`.
|
||||||
- The invitation-only message is customisable: block attribute `inviteOnlyMessage` (set under the block's **Invitation-only notice** panel) / shortcode attribute `invite_only_message`. Blank falls back to the default wording (`RegistrationPage::inviteOnlyMessage()`).
|
- The invitation-only message is customisable: block attribute `inviteOnlyMessage` (set under the block's **Invitation-only notice** panel) / shortcode attribute `invite_only_message`. Blank falls back to the default wording (`RegistrationPage::inviteOnlyMessage()`).
|
||||||
|
|
||||||
|
## Where Students Go Next
|
||||||
|
The block's **After registration** panel picks the page a student continues to once
|
||||||
|
registration finishes, and whether they get there by hand or automatically.
|
||||||
|
|
||||||
|
- **Sign-in page** (`loginPageId` / `login_page_id`) — the target of the "Sign in to your account" link shown after email confirmation (`?us_confirmed=1|ready`, falling back to the WordPress login screen) and of the "Continue to your account" link an invited student sees on the spot (`?us_registered=invite`; no link at all with no page chosen, since an already-signed-in student has no use for the login screen).
|
||||||
|
- **Redirect automatically** (`autoRedirect`, block only) — sends the student to that page instead of showing the link, via `BlockRegistrar::maybeAutoRedirect()` on `template_redirect`. It fires only on those two finished states (`RegistrationPage::isRegistrationComplete()`), so the "check your email" step, a validation error, and an `expired` confirmation link are always shown rather than redirected past. With no page chosen nothing happens — there is deliberately no login-screen fallback for the redirect. See `editor-blocks.md`.
|
||||||
|
|
||||||
## Token Redirect
|
## Token Redirect
|
||||||
A `template_redirect` handler (`RegistrationPage::maybeRedirectToRegistrationPage()`)
|
A `template_redirect` handler (`RegistrationPage::maybeRedirectToRegistrationPage()`)
|
||||||
sends any front-end request carrying a `us_invite` token to the configured
|
sends any front-end request carrying a `us_invite` token to the configured
|
||||||
|
|||||||
@@ -49,6 +49,8 @@ The front-end booking shortcode renders open slots from `GET /availability`
|
|||||||
either as an agenda-style list grouped by day or as a **weekly calendar** with
|
either as an agenda-style list grouped by day or as a **weekly calendar** with
|
||||||
previous/next-week navigation (toggle rendered by `assets/js/booking.js`; the
|
previous/next-week navigation (toggle rendered by `assets/js/booking.js`; the
|
||||||
site's `start_of_week` option is passed through the `usScheduler` JS config).
|
site's `start_of_week` option is passed through the `usScheduler` JS config).
|
||||||
|
Both views can be narrowed to the slots bookable as chosen private-lesson types
|
||||||
|
with the **Show Only** lesson-type filter — see `lesson-booking.md`.
|
||||||
|
|
||||||
## REST API
|
## REST API
|
||||||
| Method | Endpoint | Permission |
|
| Method | Endpoint | Permission |
|
||||||
|
|||||||
@@ -27,17 +27,29 @@ Four blocks have sidebar (inspector) options:
|
|||||||
|---|---|---|---|
|
|---|---|---|---|
|
||||||
| `us-scheduler/booking` | `loginPageId` (number) | `0` | Page the "log in to book a lesson" link points to for logged-out visitors. `0` = the WordPress login screen (with a redirect back to the current page). |
|
| `us-scheduler/booking` | `loginPageId` (number) | `0` | Page the "log in to book a lesson" link points to for logged-out visitors. `0` = the WordPress login screen (with a redirect back to the current page). |
|
||||||
| `us-scheduler/booking` | `autoRedirect` (boolean) | `false` | Send logged-out visitors straight to the login page instead of showing the link. |
|
| `us-scheduler/booking` | `autoRedirect` (boolean) | `false` | Send logged-out visitors straight to the login page instead of showing the link. |
|
||||||
|
| `us-scheduler/booking` | `lessonTypeId` (number) | `0` | Pin the calendar to a single private-lesson type: only the times bookable as that type are listed, and it is the only type students can book here (auto-selected on the registration form). `0` = every type. Shortcode equivalent: `[us_booking lesson_type="…"]`. |
|
||||||
|
| `us-scheduler/booking` | `showTypeFilter` (boolean) | `true` | Whether students get the **Show Only** button that narrows the calendar to chosen lesson types. Unused when a single type is pinned (there is nothing to choose). Shortcode equivalent: `[us_booking show_filter="no"]`. |
|
||||||
|
| `us-scheduler/booking` | `displayMode` (string) | `both` | Which halves of the page to embed: `both`, `booking` (calendar only, no upcoming-lessons panel) or `upcoming` (the student's lessons only, nothing bookable) — so the two halves can live on different pages. Anything unrecognised falls back to `both`. Shortcode equivalent: `[us_booking show="booking"]`. |
|
||||||
| `us-scheduler/student-login` | `bookingPageId` (number) | `0` | Page the "View available lessons" link points to for logged-in visitors, and the post-login redirect target. `0` = the current page. |
|
| `us-scheduler/student-login` | `bookingPageId` (number) | `0` | Page the "View available lessons" link points to for logged-in visitors, and the post-login redirect target. `0` = the current page. |
|
||||||
| `us-scheduler/student-login` | `autoRedirect` (boolean) | `false` | Send logged-in visitors straight to the booking page instead of showing the link. Does nothing until a booking page is chosen. |
|
| `us-scheduler/student-login` | `autoRedirect` (boolean) | `false` | Send logged-in visitors straight to the booking page instead of showing the link. Does nothing until a booking page is chosen. |
|
||||||
| `us-scheduler/student-register` | `loginPageId` (number) | `0` | Page the "Sign in to your account" link points to after a student confirms their email. `0` = the WordPress login screen. Shortcode equivalent: `[us_student_register login_page_id="…"]`. |
|
| `us-scheduler/student-register` | `loginPageId` (number) | `0` | Page students continue to once registration finishes — the "Sign in to your account" link after they confirm their email, and the "Continue to your account" link an invited student gets on the spot. `0` = the WordPress login screen for the confirmation link, and no link at all for the (already signed-in) invited student. Shortcode equivalent: `[us_student_register login_page_id="…"]`. |
|
||||||
| `us-scheduler/group-classes` | `offeringId` (number) | `0` | Restrict the page to a single group class, for embedding on a page dedicated to that class. `0` = browse all classes. Shortcode equivalent: `[us_group_classes offering="…"]`. |
|
| `us-scheduler/student-register` | `autoRedirect` (boolean) | `false` | Send students straight to that page instead of showing the link. Does nothing until a page is chosen — there is no login-screen fallback here. |
|
||||||
|
| `us-scheduler/group-classes` | `offeringId` (number) | `0` | Restrict the page to a single group class, for embedding on a page dedicated to that class. The class description is then omitted — only the schedule, instructor, price and enrolment controls are shown, so the surrounding page's own copy is not repeated. `0` = browse all classes, descriptions included. Shortcode equivalent: `[us_group_classes offering="…"]`. |
|
||||||
|
|
||||||
The page selects list all published pages; if a chosen page is later deleted,
|
The page selects list all published pages; if a chosen page is later deleted,
|
||||||
the blocks fall back to their defaults. The group-classes block's class
|
the blocks fall back to their defaults. The group-classes block's class
|
||||||
select is a dropdown of active group classes fetched from
|
select is a dropdown of active group classes fetched from
|
||||||
`GET /us-scheduler/v1/offerings?kind=group_class`; a stored class that is no
|
`GET /us-scheduler/v1/offerings?kind=group_class`; a stored class that is no
|
||||||
longer offered shows as "Unavailable class #N" rather than silently falling
|
longer offered shows as "Unavailable class #N" rather than silently falling
|
||||||
back to all classes. The link targets are also available
|
back to all classes. The booking block's lesson-type select works the same way
|
||||||
|
against `?kind=private_lesson` ("Unavailable lesson type #N"), and the live
|
||||||
|
page says so plainly when the pinned type has been withdrawn.
|
||||||
|
|
||||||
|
The booking block's options reach the front end as data attributes on
|
||||||
|
`#us-booking-app` (`data-lesson-type`, `data-type-filter`) or as omitted
|
||||||
|
containers (`displayMode`), which `assets/js/booking.js` reads on load — see
|
||||||
|
`lesson-booking.md`. Its editor preview follows `displayMode`, showing the
|
||||||
|
calendar, the upcoming-lessons panel, or both. The link targets are also available
|
||||||
to the shortcodes as `[us_booking login_page_id="…"]` and
|
to the shortcodes as `[us_booking login_page_id="…"]` and
|
||||||
`[us_student_login booking_page_id="…"]`; auto-redirect is block-only.
|
`[us_student_login booking_page_id="…"]`; auto-redirect is block-only.
|
||||||
|
|
||||||
@@ -48,6 +60,15 @@ queried singular post's content for the block (including inside nested
|
|||||||
blocks), and redirects when the block opts in. A block whose target is its
|
blocks), and redirects when the block opts in. A block whose target is its
|
||||||
own page is ignored to avoid a redirect loop.
|
own page is ignored to avoid a redirect loop.
|
||||||
|
|
||||||
|
The registration block's auto-redirect additionally only fires on a
|
||||||
|
**finished** registration — `RegistrationPage::isRegistrationComplete()`: an
|
||||||
|
invited student who is now logged in (`?us_registered=invite`), or a
|
||||||
|
self-signup back from the emailed confirmation link (`?us_confirmed=ready|1`).
|
||||||
|
The intermediate "check your email" step and every failure (a validation
|
||||||
|
error, `?us_confirmed=expired`) stay on the page so the student reads the
|
||||||
|
message. That check runs before the content is parsed, so an ordinary page
|
||||||
|
view does not pay for the extra block scan.
|
||||||
|
|
||||||
## How it works
|
## How it works
|
||||||
|
|
||||||
- **`BlockRegistrar`** (`src/BlockRegistrar.php`) hooks `init` and registers
|
- **`BlockRegistrar`** (`src/BlockRegistrar.php`) hooks `init` and registers
|
||||||
@@ -78,7 +99,9 @@ placeholder content:
|
|||||||
- **Booking** — `#us-booking-app` with sample `.us-day` / `.us-slot` rows and
|
- **Booking** — `#us-booking-app` with sample `.us-day` / `.us-slot` rows and
|
||||||
disabled Book buttons.
|
disabled Book buttons.
|
||||||
- **Group classes** — `#us-group-app` with a sample `.us-class` card and a
|
- **Group classes** — `#us-group-app` with a sample `.us-class` card and a
|
||||||
disabled Enrol button.
|
disabled Enrol button. When `offeringId` pins a single class the preview
|
||||||
|
drops the sample description, matching what the live page renders in that
|
||||||
|
mode.
|
||||||
- **Login** — the real `templates/frontend/login-page.php` template (it has
|
- **Login** — the real `templates/frontend/login-page.php` template (it has
|
||||||
no request-state dependencies).
|
no request-state dependencies).
|
||||||
- **Registration** — a disabled sample of the `.us-register-form` fields.
|
- **Registration** — a disabled sample of the `.us-register-form` fields.
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ class becomes enrollable for them — they choose whether to enrol.
|
|||||||
- Model: `Unsupervised\Schedular\GroupClass\Enrollment`
|
- Model: `Unsupervised\Schedular\GroupClass\Enrollment`
|
||||||
- Admin controller: `Unsupervised\Schedular\GroupClass\GroupClassController` — `renderPage` (studio admin per-class summary, `view_all_lessons`) and `renderInstructorPage` (instructor summary + `?class_id` roster detail, `view_own_lessons`)
|
- Admin controller: `Unsupervised\Schedular\GroupClass\GroupClassController` — `renderPage` (studio admin per-class summary, `view_all_lessons`) and `renderInstructorPage` (instructor summary + `?class_id` roster detail, `view_own_lessons`)
|
||||||
- REST endpoint: `Unsupervised\Schedular\GroupClass\EnrollmentEndpoint`
|
- REST endpoint: `Unsupervised\Schedular\GroupClass\EnrollmentEndpoint`
|
||||||
- Frontend: `Unsupervised\Schedular\GroupClass\GroupClassPage` (`[us_group_classes]` shortcode; `offering="…"` restricts it to a single class for embedding on a dedicated page — the block equivalent is the `offeringId` attribute)
|
- Frontend: `Unsupervised\Schedular\GroupClass\GroupClassPage` (`[us_group_classes]` shortcode; `offering="…"` restricts it to a single class for embedding on a dedicated page — the block equivalent is the `offeringId` attribute). In single-class mode `assets/js/group-classes.js` leaves the class description out of the card, since the page it is embedded on already describes the class; the schedule, instructor, schedule note, price and enrolment controls are still shown.
|
||||||
- Reuses `Registration\RegistrationGate` (intake answers + booking-scoped policy acceptance, type `enrollment`)
|
- Reuses `Registration\RegistrationGate` (intake answers + booking-scoped policy acceptance, type `enrollment`)
|
||||||
|
|
||||||
> **Payment:** a priced enrolment creates a payment via `Payment\PaymentService`
|
> **Payment:** a priced enrolment creates a payment via `Payment\PaymentService`
|
||||||
|
|||||||
@@ -20,8 +20,8 @@ Students register for a private lesson by choosing an offering, picking a time (
|
|||||||
| `created_at` | DATETIME | Insertion time |
|
| `created_at` | DATETIME | Insertion time |
|
||||||
|
|
||||||
## Registration Flow
|
## Registration Flow
|
||||||
1. Student opens the page with the `[us_booking]` shortcode and browses open slots as a weekly calendar (the default, anchored to the week of the earliest open slot) or an agenda list (view toggle with previous/next-week navigation; times shown in 12-hour AM/PM form).
|
1. Student opens the page with the `[us_booking]` shortcode and browses open slots as a weekly calendar (the default, anchored to the week of the earliest open slot) or an agenda list (view toggle with previous/next-week navigation; times shown in 12-hour AM/PM form). A **Show Only** button beside the view toggle opens a lesson-type filter that narrows the open times to those bookable as the chosen types (see **Lesson-Type Filter**).
|
||||||
2. Student picks a slot and an **offering** (a 30 or 60-minute private-lesson type). When the slot is tied to an offering the form shows it locked (the student sees exactly what they are booking); otherwise the form presents the instructor's active private-lesson offerings whose duration fits the slot. Every booking requires an offering — a generic slot with no fitting offering cannot be booked online.
|
2. Student picks a slot and an **offering** (a 30 or 60-minute private-lesson type). When the slot is tied to an offering the form shows it locked (the student sees exactly what they are booking); otherwise the form presents the instructor's active private-lesson offerings whose duration fits the slot, narrowed to the filtered types. When exactly one type remains it is pre-selected (its intake questions load immediately). Every booking requires an offering — a generic slot with no fitting offering cannot be booked online.
|
||||||
3. For a `weekly` reservation, the same weekday/time is held for the rest of the offering's term.
|
3. For a `weekly` reservation, the same weekday/time is held for the rest of the offering's term.
|
||||||
4. Student answers the offering's questions (`GET /offerings/{id}/questions`).
|
4. Student answers the offering's questions (`GET /offerings/{id}/questions`).
|
||||||
5. Student accepts the current published policy versions (`GET /policies`) — required to continue.
|
5. Student accepts the current published policy versions (`GET /policies`) — required to continue.
|
||||||
@@ -31,6 +31,55 @@ Students register for a private lesson by choosing an offering, picking a time (
|
|||||||
9. Instructor sees the booking under **My Lessons** and may update status via `PATCH /bookings/{id}/status`.
|
9. Instructor sees the booking under **My Lessons** and may update status via `PATCH /bookings/{id}/status`.
|
||||||
10. The booking page also shows the student their upcoming lessons (`GET /bookings`) — each with the booked offering's name and length, when it happens, a per-lesson status badge (pending payment / confirmed), and a **Cancel** button. Only the soonest five are shown; a **Show all** control reveals the rest. `GET /bookings` includes `offering_title` and `duration_minutes` for each lesson so the list needs no extra request.
|
10. The booking page also shows the student their upcoming lessons (`GET /bookings`) — each with the booked offering's name and length, when it happens, a per-lesson status badge (pending payment / confirmed), and a **Cancel** button. Only the soonest five are shown; a **Show all** control reveals the rest. `GET /bookings` includes `offering_title` and `duration_minutes` for each lesson so the list needs no extra request.
|
||||||
|
|
||||||
|
## Lesson-Type Filter
|
||||||
|
Not every open slot can be booked as every private-lesson type — a slot tied to
|
||||||
|
an offering takes that offering only, and a generic slot only takes types whose
|
||||||
|
length fits. The booking calendar therefore carries a lesson-type filter,
|
||||||
|
collapsed behind a **Show Only** button that sits in the calendar's control row
|
||||||
|
beside the List/Week toggle. Opening it reveals the type list between that row
|
||||||
|
and the calendar: a checkbox per active private-lesson type (from
|
||||||
|
`GET /offerings?kind=private_lesson`, fetched once per page load), showing the
|
||||||
|
instructor's name alongside the title when the catalog spans more than one
|
||||||
|
instructor. The button carries the number of ticked types and stays highlighted
|
||||||
|
while the filter is on, so a collapsed filter is never invisible. Both button and
|
||||||
|
list are hidden when there is only one bookable type.
|
||||||
|
|
||||||
|
Ticking one or more types narrows the calendar to the slots bookable as one of
|
||||||
|
them; no ticks means no filter, and collapsing the list leaves the filter
|
||||||
|
applied. Picking a filtered slot narrows the registration form's **Lesson type**
|
||||||
|
picker the same way, and when exactly one type remains it is pre-selected and its
|
||||||
|
intake questions load immediately. Changing the filter re-anchors the week view
|
||||||
|
on the earliest matching slot, so the student never lands on an empty week.
|
||||||
|
**Show all types** clears the filter.
|
||||||
|
|
||||||
|
Bookability is decided client-side by `offeringFitsSlot()` in
|
||||||
|
`assets/js/booking.js` — the mirror of the rule `POST /bookings` enforces (same
|
||||||
|
instructor, the tied offering when there is one, otherwise a matching
|
||||||
|
`duration_minutes`). The filter is a browsing aid only: the server re-checks
|
||||||
|
every booking regardless.
|
||||||
|
|
||||||
|
Two block/shortcode options change what the filter has to work with (see
|
||||||
|
`editor-blocks.md`), passed to the script as data attributes on
|
||||||
|
`#us-booking-app`:
|
||||||
|
|
||||||
|
- **A pinned lesson type** (`data-lesson-type`) narrows the catalog to that one
|
||||||
|
offering, so the page lists only the times bookable as it and books nothing
|
||||||
|
else — the filter control hides itself, there being one type left. A pinned
|
||||||
|
type that is no longer offered shows "This lesson type is not available for
|
||||||
|
booking right now" rather than an empty calendar.
|
||||||
|
- **Filter off** (`data-type-filter="0"`) drops the **Show Only** button
|
||||||
|
entirely; every open time is listed, as before the filter existed.
|
||||||
|
|
||||||
|
## Embedding Halves of the Page
|
||||||
|
The page has two halves — the booking calendar and the student's upcoming
|
||||||
|
lessons — and the block/shortcode can embed either on its own (`displayMode` /
|
||||||
|
`show`: `both` (default), `booking`, `upcoming`). The template simply omits the
|
||||||
|
containers of the half that is not wanted, and the script skips the work that
|
||||||
|
belongs to a missing container: an upcoming-only embed never requests
|
||||||
|
availability or the offering catalog, and a booking-only embed never requests
|
||||||
|
`GET /bookings`. An unrecognised value renders the whole page, so a typo cannot
|
||||||
|
silently hide half of it.
|
||||||
|
|
||||||
## Cancellation
|
## Cancellation
|
||||||
Students cancel their own lessons via `POST /bookings/{id}/cancel` (idempotent).
|
Students cancel their own lessons via `POST /bookings/{id}/cancel` (idempotent).
|
||||||
Cancelling marks the lesson `cancelled`, frees the availability slot for
|
Cancelling marks the lesson `cancelled`, frees the availability slot for
|
||||||
@@ -93,7 +142,7 @@ acceptance time and IP), and their intake-question answers. On **My Lessons** an
|
|||||||
instructor may only open their own lessons; the studio **Scheduler** may open any.
|
instructor may only open their own lessons; the studio **Scheduler** may open any.
|
||||||
|
|
||||||
## Frontend Shortcodes
|
## Frontend Shortcodes
|
||||||
- `[us_booking]` — student calendar + registration flow; requires `book_lesson` capability
|
- `[us_booking]` — student calendar + registration flow; requires `book_lesson` capability. Attributes: `login_page_id`, `lesson_type` (pin one private-lesson offering), `show_filter` (`no` hides the **Show Only** filter), `show` (`both` / `booking` / `upcoming`)
|
||||||
- `[us_student_login]` — front-end login form for students
|
- `[us_student_login]` — front-end login form for students
|
||||||
|
|
||||||
## Implementation
|
## Implementation
|
||||||
|
|||||||
@@ -107,7 +107,7 @@ Studio admin and instructors manage offerings under **Offerings** in wp-admin.
|
|||||||
## REST API
|
## REST API
|
||||||
| Method | Endpoint | Permission |
|
| Method | Endpoint | Permission |
|
||||||
|----------|---------------------------------------------|----------------------------------|
|
|----------|---------------------------------------------|----------------------------------|
|
||||||
| `GET` | `/wp-json/us-scheduler/v1/offerings` | Public (active offerings only) |
|
| `GET` | `/wp-json/us-scheduler/v1/offerings` | `book_lesson` or `manage_offerings` (active offerings only) |
|
||||||
| `POST` | `/wp-json/us-scheduler/v1/offerings` | `manage_offerings` |
|
| `POST` | `/wp-json/us-scheduler/v1/offerings` | `manage_offerings` |
|
||||||
| `PATCH` | `/wp-json/us-scheduler/v1/offerings/{id}` | `manage_offerings` + owner |
|
| `PATCH` | `/wp-json/us-scheduler/v1/offerings/{id}` | `manage_offerings` + owner |
|
||||||
| `DELETE` | `/wp-json/us-scheduler/v1/offerings/{id}` | `manage_offerings` + owner |
|
| `DELETE` | `/wp-json/us-scheduler/v1/offerings/{id}` | `manage_offerings` + owner |
|
||||||
|
|||||||
@@ -66,9 +66,20 @@ class RegistrationPage {
|
|||||||
|
|
||||||
if ( is_user_logged_in() ) {
|
if ( is_user_logged_in() ) {
|
||||||
if ( self::RESULT_INVITE === $registered ) {
|
if ( self::RESULT_INVITE === $registered ) {
|
||||||
|
// An invited student is done the moment they land here logged in,
|
||||||
|
// so this is where their "continue" link belongs. The sign-in-page
|
||||||
|
// fallback is deliberately not used: pointing someone who is
|
||||||
|
// already signed in at the login screen helps nobody.
|
||||||
|
$continue = $this->continueUrl( $this->successPageId( $atts ) );
|
||||||
|
$link = null === $continue
|
||||||
|
? ''
|
||||||
|
: '<p><a href="' . esc_url( $continue ) . '">'
|
||||||
|
. esc_html__( 'Continue to your account', 'unsupervised-schedular' )
|
||||||
|
. '</a></p>';
|
||||||
|
|
||||||
return '<div class="us-register-form"><p class="us-success">'
|
return '<div class="us-register-form"><p class="us-success">'
|
||||||
. esc_html__( 'Your account has been created and you are now logged in.', 'unsupervised-schedular' )
|
. esc_html__( 'Your account has been created and you are now logged in.', 'unsupervised-schedular' )
|
||||||
. '</p></div>';
|
. '</p>' . $link . '</div>';
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<p>' . esc_html__( 'You already have an account and are logged in.', 'unsupervised-schedular' ) . '</p>';
|
return '<p>' . esc_html__( 'You already have an account and are logged in.', 'unsupervised-schedular' ) . '</p>';
|
||||||
@@ -98,7 +109,7 @@ class RegistrationPage {
|
|||||||
$confirmResult = sanitize_key( Val::string( wp_unslash( $_GET['us_confirmed'] ?? '' ) ) );
|
$confirmResult = sanitize_key( Val::string( wp_unslash( $_GET['us_confirmed'] ?? '' ) ) );
|
||||||
|
|
||||||
// Where the post-confirmation prompt sends students to sign in.
|
// Where the post-confirmation prompt sends students to sign in.
|
||||||
$loginUrl = $this->loginUrl( Val::int( $atts['loginPageId'] ?? $atts['login_page_id'] ?? 0 ) );
|
$loginUrl = $this->loginUrl( $this->successPageId( $atts ) );
|
||||||
|
|
||||||
$policyForms = $this->signupPolicies();
|
$policyForms = $this->signupPolicies();
|
||||||
$accountQuestions = $this->questions->findByScope( Question::SCOPE_ACCOUNT, activeOnly: true );
|
$accountQuestions = $this->questions->findByScope( Question::SCOPE_ACCOUNT, activeOnly: true );
|
||||||
@@ -319,21 +330,68 @@ class RegistrationPage {
|
|||||||
return $autoApprove ? self::RESULT_CONFIRM_GROUP : self::RESULT_CONFIRM;
|
return $autoApprove ? self::RESULT_CONFIRM_GROUP : self::RESULT_CONFIRM;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The page id chosen for the post-registration destination, from either the
|
||||||
|
* block (`loginPageId`) or shortcode (`login_page_id`) attribute.
|
||||||
|
*
|
||||||
|
* @param array<int|string, mixed> $atts
|
||||||
|
*/
|
||||||
|
private function successPageId( array $atts ): int {
|
||||||
|
return Val::int( $atts['loginPageId'] ?? $atts['login_page_id'] ?? 0 );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL the post-confirmation sign-in link points to: the chosen login page
|
* URL the post-confirmation sign-in link points to: the chosen login page
|
||||||
* when one is configured (and still exists), otherwise the WordPress login
|
* when one is configured (and still exists), otherwise the WordPress login
|
||||||
* screen.
|
* screen.
|
||||||
*/
|
*/
|
||||||
private function loginUrl( int $loginPageId ): string {
|
private function loginUrl( int $loginPageId ): string {
|
||||||
if ( $loginPageId > 0 ) {
|
return $this->continueUrl( $loginPageId ) ?? wp_login_url();
|
||||||
$url = get_permalink( $loginPageId );
|
|
||||||
|
|
||||||
if ( is_string( $url ) ) {
|
|
||||||
return $url;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return wp_login_url();
|
/**
|
||||||
|
* The chosen post-registration page's URL, or null when none is configured
|
||||||
|
* (or it has since been deleted). Unlike {@see loginUrl()} this has no
|
||||||
|
* WordPress-login-screen fallback, so callers that need a page the student
|
||||||
|
* was actually sent to — the invited-student link and the block's
|
||||||
|
* auto-redirect — can tell "not configured" from "configured".
|
||||||
|
*/
|
||||||
|
public function continueUrl( int $pageId ): ?string {
|
||||||
|
if ( $pageId <= 0 ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = get_permalink( $pageId );
|
||||||
|
|
||||||
|
return is_string( $url ) ? $url : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether this request is a *finished* registration — the states the
|
||||||
|
* block's auto-redirect may act on:
|
||||||
|
*
|
||||||
|
* - an invited student who just signed up and is now logged in, and
|
||||||
|
* - a self-signup returning from the emailed confirmation link, whether
|
||||||
|
* their account is ready (`ready`) or awaiting studio approval (`1`).
|
||||||
|
*
|
||||||
|
* Deliberately excluded: the intermediate "check your email" step (the
|
||||||
|
* student would never see the instruction) and every failure — a validation
|
||||||
|
* error or an expired confirmation link (`expired`) — so the message always
|
||||||
|
* gets shown. The `us_confirmed` values are set by
|
||||||
|
* {@see EmailConfirmationHandler::maybeConfirm()}.
|
||||||
|
*/
|
||||||
|
public function isRegistrationComplete(): bool {
|
||||||
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only display flag; the submit that set it was nonce-checked.
|
||||||
|
$registered = sanitize_key( Val::string( wp_unslash( $_GET['us_registered'] ?? '' ) ) );
|
||||||
|
|
||||||
|
if ( self::RESULT_INVITE === $registered ) {
|
||||||
|
return is_user_logged_in();
|
||||||
|
}
|
||||||
|
|
||||||
|
// phpcs:ignore WordPress.Security.NonceVerification.Recommended -- read-only display flag set by EmailConfirmationHandler's redirect.
|
||||||
|
$confirmed = sanitize_key( Val::string( wp_unslash( $_GET['us_confirmed'] ?? '' ) ) );
|
||||||
|
|
||||||
|
return in_array( $confirmed, [ '1', 'ready' ], true );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
+65
-6
@@ -15,7 +15,23 @@ namespace Unsupervised\Schedular;
|
|||||||
*/
|
*/
|
||||||
class BlockPreview {
|
class BlockPreview {
|
||||||
|
|
||||||
public static function booking(): string {
|
/**
|
||||||
|
* Sample booking page.
|
||||||
|
*
|
||||||
|
* @param string $mode Which halves the block embeds — one of
|
||||||
|
* {@see Booking\BookingPage::MODE_BOTH},
|
||||||
|
* `MODE_BOOKING` or `MODE_UPCOMING`. The preview shows
|
||||||
|
* the same sections the published page would.
|
||||||
|
*/
|
||||||
|
public static function booking( string $mode = Booking\BookingPage::MODE_BOTH ): string {
|
||||||
|
if ( Booking\BookingPage::MODE_UPCOMING === $mode ) {
|
||||||
|
return sprintf(
|
||||||
|
'<div id="us-booking-app">%s<div id="us-my-lessons">%s</div></div>',
|
||||||
|
self::note( __( 'Editor preview — students see their own lessons on the published page.', 'unsupervised-schedular' ) ),
|
||||||
|
self::upcomingLessons()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
$days = [
|
$days = [
|
||||||
[
|
[
|
||||||
'label' => __( 'Monday', 'unsupervised-schedular' ),
|
'label' => __( 'Monday', 'unsupervised-schedular' ),
|
||||||
@@ -51,20 +67,63 @@ class BlockPreview {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$lessons = Booking\BookingPage::MODE_BOOKING === $mode
|
||||||
|
? ''
|
||||||
|
: sprintf( '<div id="us-my-lessons">%s</div>', self::upcomingLessons() );
|
||||||
|
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<div id="us-booking-app">%s<div id="us-slot-list">%s</div></div>',
|
'<div id="us-booking-app">%s%s<div id="us-slot-list">%s</div></div>',
|
||||||
self::note( __( 'Editor preview — students see live availability on the published page.', 'unsupervised-schedular' ) ),
|
self::note( __( 'Editor preview — students see live availability on the published page.', 'unsupervised-schedular' ) ),
|
||||||
|
$lessons,
|
||||||
$dayHtml
|
$dayHtml
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function groupClasses(): string {
|
/**
|
||||||
|
* Sample "your upcoming lessons" panel, shared by the booking preview's
|
||||||
|
* full and upcoming-only modes.
|
||||||
|
*/
|
||||||
|
private static function upcomingLessons(): string {
|
||||||
return sprintf(
|
return sprintf(
|
||||||
'<div id="us-group-app">%s<div id="us-group-list"><div class="us-class"><h3>%s</h3><p>%s</p><p>%s</p><p>25.00 CAD</p><button type="button" class="us-enrol-btn" disabled>%s</button></div></div></div>',
|
'<div class="us-my-lessons"><h3>%s</h3>'
|
||||||
self::note( __( 'Editor preview — students see live group classes on the published page.', 'unsupervised-schedular' ) ),
|
. '<div class="us-my-lesson"><span class="us-my-lesson-info">'
|
||||||
|
. '<strong class="us-my-lesson-title">%s <span class="us-my-lesson-duration">(30 min)</span></strong>'
|
||||||
|
. '<span class="us-my-lesson-when">%s</span></span>'
|
||||||
|
. '<span class="us-my-lesson-actions">'
|
||||||
|
. '<span class="us-lesson-status us-lesson-status-confirmed">%s</span>'
|
||||||
|
. '<button type="button" class="us-cancel-lesson" disabled>%s</button>'
|
||||||
|
. '</span></div></div>',
|
||||||
|
esc_html__( 'Your upcoming lessons', 'unsupervised-schedular' ),
|
||||||
|
esc_html__( 'Piano Lesson', 'unsupervised-schedular' ),
|
||||||
|
esc_html__( 'Monday · 4:00 PM–4:30 PM', 'unsupervised-schedular' ),
|
||||||
|
esc_html__( 'Confirmed', 'unsupervised-schedular' ),
|
||||||
|
esc_html__( 'Cancel', 'unsupervised-schedular' )
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sample group-class card.
|
||||||
|
*
|
||||||
|
* @param bool $singleClass Whether the block is pinned to one class, in
|
||||||
|
* which case the live page omits the class
|
||||||
|
* description and the preview does too.
|
||||||
|
*/
|
||||||
|
public static function groupClasses( bool $singleClass = false ): string {
|
||||||
|
$note = $singleClass
|
||||||
|
? __( 'Editor preview — the published page shows the chosen class with its live schedule and enrolment status.', 'unsupervised-schedular' )
|
||||||
|
: __( 'Editor preview — students see live group classes on the published page.', 'unsupervised-schedular' );
|
||||||
|
|
||||||
|
$description = $singleClass
|
||||||
|
? ''
|
||||||
|
: '<p>' . esc_html__( 'A sample class shown so the page can be styled.', 'unsupervised-schedular' ) . '</p>';
|
||||||
|
|
||||||
|
return sprintf(
|
||||||
|
'<div id="us-group-app">%s<div id="us-group-list"><div class="us-class"><h3>%s</h3><p class="us-class-when">%s</p>%s<p>25.00 CAD</p><p class="us-enrol-deadline">%s</p><button type="button" class="us-enrol-btn" disabled>%s</button></div></div></div>',
|
||||||
|
self::note( $note ),
|
||||||
esc_html__( 'Beginner Group Class', 'unsupervised-schedular' ),
|
esc_html__( 'Beginner Group Class', 'unsupervised-schedular' ),
|
||||||
esc_html__( 'Saturdays 10:00 AM–11:00 AM', 'unsupervised-schedular' ),
|
esc_html__( 'Saturdays 10:00 AM–11:00 AM', 'unsupervised-schedular' ),
|
||||||
esc_html__( 'A sample class shown so the page can be styled.', 'unsupervised-schedular' ),
|
$description,
|
||||||
|
esc_html__( 'Enrol by Sep 6, 2026', 'unsupervised-schedular' ),
|
||||||
esc_html__( 'Enrol', 'unsupervised-schedular' )
|
esc_html__( 'Enrol', 'unsupervised-schedular' )
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+71
-6
@@ -90,6 +90,18 @@ class BlockRegistrar {
|
|||||||
'default' => 0,
|
'default' => 0,
|
||||||
],
|
],
|
||||||
'autoRedirect' => $redirectToggle,
|
'autoRedirect' => $redirectToggle,
|
||||||
|
'lessonTypeId' => [
|
||||||
|
'type' => 'number',
|
||||||
|
'default' => 0,
|
||||||
|
],
|
||||||
|
'showTypeFilter' => [
|
||||||
|
'type' => 'boolean',
|
||||||
|
'default' => true,
|
||||||
|
],
|
||||||
|
'displayMode' => [
|
||||||
|
'type' => 'string',
|
||||||
|
'default' => BookingPage::MODE_BOTH,
|
||||||
|
],
|
||||||
],
|
],
|
||||||
],
|
],
|
||||||
'us-scheduler/student-login' => [
|
'us-scheduler/student-login' => [
|
||||||
@@ -109,6 +121,7 @@ class BlockRegistrar {
|
|||||||
'type' => 'number',
|
'type' => 'number',
|
||||||
'default' => 0,
|
'default' => 0,
|
||||||
],
|
],
|
||||||
|
'autoRedirect' => $redirectToggle,
|
||||||
'inviteOnlyMessage' => [
|
'inviteOnlyMessage' => [
|
||||||
'type' => 'string',
|
'type' => 'string',
|
||||||
'default' => '',
|
'default' => '',
|
||||||
@@ -133,7 +146,11 @@ class BlockRegistrar {
|
|||||||
* @param array<string, mixed> $attributes Block attributes.
|
* @param array<string, mixed> $attributes Block attributes.
|
||||||
*/
|
*/
|
||||||
public function renderBooking( array $attributes = [] ): string {
|
public function renderBooking( array $attributes = [] ): string {
|
||||||
return $this->isEditorPreview() ? BlockPreview::booking() : $this->bookingPage->render( $attributes );
|
if ( ! $this->isEditorPreview() ) {
|
||||||
|
return $this->bookingPage->render( $attributes );
|
||||||
|
}
|
||||||
|
|
||||||
|
return BlockPreview::booking( Val::string( $attributes['displayMode'] ?? BookingPage::MODE_BOTH ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -160,16 +177,21 @@ class BlockRegistrar {
|
|||||||
* @param array<string, mixed> $attributes Block attributes.
|
* @param array<string, mixed> $attributes Block attributes.
|
||||||
*/
|
*/
|
||||||
public function renderGroupClasses( array $attributes = [] ): string {
|
public function renderGroupClasses( array $attributes = [] ): string {
|
||||||
return $this->isEditorPreview() ? BlockPreview::groupClasses() : $this->groupClassPage->render( $attributes );
|
if ( ! $this->isEditorPreview() ) {
|
||||||
|
return $this->groupClassPage->render( $attributes );
|
||||||
|
}
|
||||||
|
|
||||||
|
return BlockPreview::groupClasses( Val::int( $attributes['offeringId'] ?? 0 ) > 0 );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server-side auto-redirect for blocks that opt in via their autoRedirect
|
* Server-side auto-redirect for blocks that opt in via their autoRedirect
|
||||||
* attribute: logged-out visitors on a page containing the booking block
|
* attribute: logged-out visitors on a page containing the booking block
|
||||||
* are sent to its login page, and logged-in visitors on a page containing
|
* are sent to its login page, logged-in visitors on a page containing the
|
||||||
* the student-login block are sent to its booking page. Hooked on
|
* student-login block are sent to its booking page, and a student who has
|
||||||
* `template_redirect` because block rendering happens after output has
|
* just finished registering is sent to the register block's chosen page.
|
||||||
* started, too late to send a Location header.
|
* Hooked on `template_redirect` because block rendering happens after
|
||||||
|
* output has started, too late to send a Location header.
|
||||||
*/
|
*/
|
||||||
public function maybeAutoRedirect(): void {
|
public function maybeAutoRedirect(): void {
|
||||||
if ( is_admin() || ! is_singular() ) {
|
if ( is_admin() || ! is_singular() ) {
|
||||||
@@ -181,6 +203,10 @@ class BlockRegistrar {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( $this->maybeRedirectAfterRegistration( $post ) ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if ( is_user_logged_in() ) {
|
if ( is_user_logged_in() ) {
|
||||||
$attrs = $this->firstBlockAttrs( $post->post_content, 'us-scheduler/student-login' );
|
$attrs = $this->firstBlockAttrs( $post->post_content, 'us-scheduler/student-login' );
|
||||||
if ( null === $attrs || ! Val::bool( $attrs['autoRedirect'] ?? false ) ) {
|
if ( null === $attrs || ! Val::bool( $attrs['autoRedirect'] ?? false ) ) {
|
||||||
@@ -213,6 +239,45 @@ class BlockRegistrar {
|
|||||||
$this->redirect( $this->bookingPage->loginUrl( $loginPageId ) );
|
$this->redirect( $this->bookingPage->loginUrl( $loginPageId ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends a student whose registration has just completed to the register
|
||||||
|
* block's chosen page, when the block opts in. Only the finished states
|
||||||
|
* qualify (see {@see RegistrationPage::isRegistrationComplete()}): a
|
||||||
|
* failure or the "check your email" step stays put so its message is read.
|
||||||
|
* Unlike the other blocks there is no login-screen fallback — with no page
|
||||||
|
* chosen there is nowhere to send them, so the link is shown instead.
|
||||||
|
*
|
||||||
|
* Returns whether the redirect was issued (it only ever returns in tests;
|
||||||
|
* {@see redirect()} exits in production).
|
||||||
|
*/
|
||||||
|
private function maybeRedirectAfterRegistration( \WP_Post $post ): bool {
|
||||||
|
// Checked before parsing the content because it is a couple of query
|
||||||
|
// args, whereas every front-end request would otherwise pay for a
|
||||||
|
// third block scan.
|
||||||
|
if ( ! $this->registrationPage->isRegistrationComplete() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$attrs = $this->firstBlockAttrs( $post->post_content, 'us-scheduler/student-register' );
|
||||||
|
if ( null === $attrs || ! Val::bool( $attrs['autoRedirect'] ?? false ) ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$pageId = Val::int( $attrs['loginPageId'] ?? 0 );
|
||||||
|
if ( $pageId === $post->ID ) {
|
||||||
|
return false; // Redirecting the page to itself would loop.
|
||||||
|
}
|
||||||
|
|
||||||
|
$url = $this->registrationPage->continueUrl( $pageId );
|
||||||
|
if ( null === $url ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->redirect( $url );
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attributes of the first occurrence of the named block in the content,
|
* Attributes of the first occurrence of the named block in the content,
|
||||||
* searching inner blocks so blocks nested inside groups or columns are
|
* searching inner blocks so blocks nested inside groups or columns are
|
||||||
|
|||||||
@@ -9,11 +9,30 @@ use Unsupervised\Schedular\Val;
|
|||||||
|
|
||||||
class BookingPage {
|
class BookingPage {
|
||||||
|
|
||||||
|
/** Booking calendar and the student's upcoming lessons (the default). */
|
||||||
|
public const MODE_BOTH = 'both';
|
||||||
|
|
||||||
|
/** Booking calendar only — no upcoming-lessons panel. */
|
||||||
|
public const MODE_BOOKING = 'booking';
|
||||||
|
|
||||||
|
/** The student's upcoming lessons only — nothing bookable. */
|
||||||
|
public const MODE_UPCOMING = 'upcoming';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the booking shortcode/block output.
|
* Renders the booking shortcode/block output.
|
||||||
*
|
*
|
||||||
* @param array<int|string, mixed> $atts Block attributes (`loginPageId`) or
|
* Supported attributes (block / shortcode form):
|
||||||
* shortcode attributes (`login_page_id`).
|
* - `loginPageId` / `login_page_id` — where logged-out visitors are sent.
|
||||||
|
* - `lessonTypeId` / `lesson_type` — a private-lesson offering id that pins
|
||||||
|
* the calendar to one lesson type: only the times bookable as that type
|
||||||
|
* are listed, and only it can be booked. 0 or absent shows every type.
|
||||||
|
* - `showTypeFilter` / `show_filter` — whether the "Show Only" lesson-type
|
||||||
|
* filter is offered (default true; irrelevant when a type is pinned).
|
||||||
|
* - `displayMode` / `show` — which halves of the page to embed:
|
||||||
|
* {@see self::MODE_BOTH} (default), {@see self::MODE_BOOKING} (calendar
|
||||||
|
* only) or {@see self::MODE_UPCOMING} (the student's lessons only).
|
||||||
|
*
|
||||||
|
* @param array<int|string, mixed> $atts Block or shortcode attributes.
|
||||||
*/
|
*/
|
||||||
public function render( array $atts ): string {
|
public function render( array $atts ): string {
|
||||||
if ( ! is_user_logged_in() ) {
|
if ( ! is_user_logged_in() ) {
|
||||||
@@ -38,11 +57,42 @@ class BookingPage {
|
|||||||
wp_enqueue_style( 'us-scheduler' );
|
wp_enqueue_style( 'us-scheduler' );
|
||||||
wp_enqueue_script( 'us-scheduler' );
|
wp_enqueue_script( 'us-scheduler' );
|
||||||
|
|
||||||
|
$lessonTypeId = absint( Val::int( $atts['lessonTypeId'] ?? $atts['lesson_type'] ?? 0 ) );
|
||||||
|
$showTypeFilter = self::toBool( $atts['showTypeFilter'] ?? $atts['show_filter'] ?? true );
|
||||||
|
|
||||||
|
$mode = self::mode( $atts['displayMode'] ?? $atts['show'] ?? self::MODE_BOTH );
|
||||||
|
$showBooking = self::MODE_UPCOMING !== $mode;
|
||||||
|
$showUpcoming = self::MODE_BOOKING !== $mode;
|
||||||
|
|
||||||
ob_start();
|
ob_start();
|
||||||
include USC_PLUGIN_DIR . 'templates/frontend/booking-page.php';
|
include USC_PLUGIN_DIR . 'templates/frontend/booking-page.php';
|
||||||
return (string) ob_get_clean();
|
return (string) ob_get_clean();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Normalises the display-mode attribute; anything unrecognised embeds the
|
||||||
|
* whole page, so a typo never silently hides half of it.
|
||||||
|
*/
|
||||||
|
private static function mode( mixed $value ): string {
|
||||||
|
$mode = strtolower( trim( Val::string( $value ) ) );
|
||||||
|
|
||||||
|
return in_array( $mode, [ self::MODE_BOOKING, self::MODE_UPCOMING ], true ) ? $mode : self::MODE_BOTH;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a boolean attribute. Block attributes arrive as real booleans,
|
||||||
|
* shortcode attributes as strings — where the words people actually write
|
||||||
|
* for "off" ("no", "false", "off") are all truthy to PHP, so they are
|
||||||
|
* matched explicitly rather than cast.
|
||||||
|
*/
|
||||||
|
private static function toBool( mixed $value ): bool {
|
||||||
|
if ( is_string( $value ) ) {
|
||||||
|
return ! in_array( strtolower( trim( $value ) ), [ '', '0', 'no', 'false', 'off' ], true );
|
||||||
|
}
|
||||||
|
|
||||||
|
return Val::bool( $value );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* URL the logged-out prompt sends visitors to: the chosen login page when
|
* URL the logged-out prompt sends visitors to: the chosen login page when
|
||||||
* one is configured (and still exists), otherwise the WordPress login
|
* one is configured (and still exists), otherwise the WordPress login
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ class OfferingEndpoint {
|
|||||||
[
|
[
|
||||||
'methods' => \WP_REST_Server::READABLE,
|
'methods' => \WP_REST_Server::READABLE,
|
||||||
'callback' => [ $this, 'index' ],
|
'callback' => [ $this, 'index' ],
|
||||||
'permission_callback' => [ $this, 'canBook' ],
|
'permission_callback' => [ $this, 'canRead' ],
|
||||||
'args' => [
|
'args' => [
|
||||||
'instructor_id' => [
|
'instructor_id' => [
|
||||||
'type' => 'integer',
|
'type' => 'integer',
|
||||||
@@ -262,12 +262,16 @@ class OfferingEndpoint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reading the offerings catalogue is only needed by the logged-in student
|
* Reading the offerings catalogue has no anonymous consumer, so it stays
|
||||||
* booking flow, so it requires the same capability as booking — there is no
|
* behind a login. Students reach it through the booking flow, and studio
|
||||||
* anonymous consumer.
|
* admins and instructors reach it from the block editor's group-class
|
||||||
|
* pickers — an administrator holds `manage_offerings` but not
|
||||||
|
* `book_lesson`, so both capabilities open the listing.
|
||||||
*/
|
*/
|
||||||
public function canBook(): bool {
|
public function canRead(): bool {
|
||||||
return is_user_logged_in() && current_user_can( RoleManager::CAP_BOOK_LESSON );
|
return is_user_logged_in()
|
||||||
|
&& ( current_user_can( RoleManager::CAP_BOOK_LESSON )
|
||||||
|
|| current_user_can( RoleManager::CAP_MANAGE_OFFERINGS ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,14 +4,23 @@ declare(strict_types=1);
|
|||||||
if (! defined('ABSPATH')) {
|
if (! defined('ABSPATH')) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @var int $lessonTypeId Offering id when the calendar is pinned to one lesson type; 0 for every type. */
|
||||||
|
/** @var bool $showTypeFilter Whether the "Show Only" lesson-type filter is offered. */
|
||||||
|
/** @var bool $showBooking Whether the booking calendar is part of this embed. */
|
||||||
|
/** @var bool $showUpcoming Whether the student's upcoming-lessons panel is part of this embed. */
|
||||||
?>
|
?>
|
||||||
<div id="us-booking-app" data-nonce="<?php echo esc_attr(wp_create_nonce('wp_rest')); ?>">
|
<div id="us-booking-app" data-nonce="<?php echo esc_attr(wp_create_nonce('wp_rest')); ?>"<?php echo $lessonTypeId > 0 ? ' data-lesson-type="' . esc_attr((string) $lessonTypeId) . '"' : ''; ?><?php echo $showTypeFilter ? '' : ' data-type-filter="0"'; ?>>
|
||||||
|
<?php if ($showUpcoming) : ?>
|
||||||
<div id="us-my-lessons"></div>
|
<div id="us-my-lessons"></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
<?php if ($showBooking) : ?>
|
||||||
<div id="us-slot-list">
|
<div id="us-slot-list">
|
||||||
<p><?php esc_html_e('Loading available slots…', 'unsupervised-schedular'); ?></p>
|
<p><?php esc_html_e('Loading available slots…', 'unsupervised-schedular'); ?></p>
|
||||||
</div>
|
</div>
|
||||||
<div id="us-booking-confirmation" style="display:none;">
|
<div id="us-booking-confirmation" style="display:none;">
|
||||||
<p><?php esc_html_e('Your lesson has been booked. The instructor will confirm shortly.', 'unsupervised-schedular'); ?></p>
|
<p><?php esc_html_e('Your lesson has been booked. The instructor will confirm shortly.', 'unsupervised-schedular'); ?></p>
|
||||||
</div>
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
<div id="us-booking-error" style="display:none;" role="alert"></div>
|
<div id="us-booking-error" style="display:none;" role="alert"></div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if (! defined('ABSPATH')) {
|
|||||||
* @var bool $canRegister
|
* @var bool $canRegister
|
||||||
* @var string $inviteOnlyMessage Text shown when registration is closed and no valid invite is present.
|
* @var string $inviteOnlyMessage Text shown when registration is closed and no valid invite is present.
|
||||||
* @var bool $open Whether open (self-approval) registration is enabled.
|
* @var bool $open Whether open (self-approval) registration is enabled.
|
||||||
* @var string $successType '' | 'invite' (created + logged in) | 'confirm' (check email) | 'confirm_group' (check email; auto-approved on confirm).
|
* @var string $successType '' | 'confirm' (check email) | 'confirm_group' (check email; auto-approved on confirm). The invited-student success is rendered by RegistrationPage::render() itself, which returns before this template for logged-in visitors.
|
||||||
* @var string $confirmResult '' | '1' (email confirmed, awaiting approval) | 'ready' (confirmed + auto-approved) | 'expired'.
|
* @var string $confirmResult '' | '1' (email confirmed, awaiting approval) | 'ready' (confirmed + auto-approved) | 'expired'.
|
||||||
* @var string $loginUrl Where the post-confirmation sign-in link points.
|
* @var string $loginUrl Where the post-confirmation sign-in link points.
|
||||||
* @var string $error
|
* @var string $error
|
||||||
@@ -57,9 +57,7 @@ $renderQuestionField = static function (Question $question): void {
|
|||||||
};
|
};
|
||||||
?>
|
?>
|
||||||
<div class="us-register-form">
|
<div class="us-register-form">
|
||||||
<?php if ($successType === 'invite') : ?>
|
<?php if ($successType === 'confirm') : ?>
|
||||||
<p class="us-success"><?php esc_html_e('Your account has been created and you are now logged in.', 'unsupervised-schedular'); ?></p>
|
|
||||||
<?php elseif ($successType === 'confirm') : ?>
|
|
||||||
<p class="us-success"><?php esc_html_e('Your account has been created. Check your email for a link to confirm your address — once you do, a studio admin will review and approve your account.', 'unsupervised-schedular'); ?></p>
|
<p class="us-success"><?php esc_html_e('Your account has been created. Check your email for a link to confirm your address — once you do, a studio admin will review and approve your account.', 'unsupervised-schedular'); ?></p>
|
||||||
<?php elseif ($successType === 'confirm_group') : ?>
|
<?php elseif ($successType === 'confirm_group') : ?>
|
||||||
<p class="us-success"><?php esc_html_e('Your account has been created. Check your email for a link to confirm your address — once you do, your account is ready to use.', 'unsupervised-schedular'); ?></p>
|
<p class="us-success"><?php esc_html_e('Your account has been created. Check your email for a link to confirm your address — once you do, your account is ready to use.', 'unsupervised-schedular'); ?></p>
|
||||||
|
|||||||
@@ -484,6 +484,54 @@ class RegistrationPageTest extends TestCase
|
|||||||
|
|
||||||
self::assertStringContainsString('us-success', $html);
|
self::assertStringContainsString('us-success', $html);
|
||||||
self::assertStringContainsString('now logged in', $html);
|
self::assertStringContainsString('now logged in', $html);
|
||||||
|
// No page chosen: the sign-in-screen fallback is useless to someone who
|
||||||
|
// is already signed in, so no link is offered at all.
|
||||||
|
self::assertStringNotContainsString('<a href', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testInviteSuccessLinksToTheChosenPage(): void
|
||||||
|
{
|
||||||
|
$_GET = [ 'us_registered' => 'invite' ];
|
||||||
|
Functions\when('is_user_logged_in')->justReturn(true);
|
||||||
|
Functions\when('sanitize_key')->alias(static fn ($v) => strtolower((string) $v));
|
||||||
|
Functions\expect('get_permalink')->once()->with(4)->andReturn('http://home.test/welcome/');
|
||||||
|
|
||||||
|
$html = $this->ctx['page']->render([ 'loginPageId' => 4 ]);
|
||||||
|
|
||||||
|
self::assertStringContainsString('now logged in', $html);
|
||||||
|
self::assertStringContainsString('href="http://home.test/welcome/"', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testContinueUrlIsNullWithoutAResolvablePage(): void
|
||||||
|
{
|
||||||
|
Functions\when('get_permalink')->justReturn(false);
|
||||||
|
|
||||||
|
self::assertNull($this->ctx['page']->continueUrl(0));
|
||||||
|
self::assertNull($this->ctx['page']->continueUrl(4));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testIsRegistrationCompleteOnlyForFinishedStates(): void
|
||||||
|
{
|
||||||
|
Functions\when('sanitize_key')->alias(static fn ($v) => strtolower((string) $v));
|
||||||
|
|
||||||
|
// [ query args, logged in, finished ]
|
||||||
|
$cases = [
|
||||||
|
'invited student, now logged in' => [['us_registered' => 'invite'], true, true],
|
||||||
|
'invited student, not logged in' => [['us_registered' => 'invite'], false, false],
|
||||||
|
'email confirmed, ready' => [['us_confirmed' => 'ready'], false, true],
|
||||||
|
'email confirmed, pending review' => [['us_confirmed' => '1'], false, true],
|
||||||
|
'confirmation link expired' => [['us_confirmed' => 'expired'], false, false],
|
||||||
|
'awaiting email confirmation' => [['us_registered' => 'confirm'], false, false],
|
||||||
|
'group signup awaiting confirm' => [['us_registered' => 'confirm_group'], false, false],
|
||||||
|
'plain page view' => [[], false, false],
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($cases as $label => [$get, $loggedIn, $expected]) {
|
||||||
|
$_GET = $get;
|
||||||
|
Functions\when('is_user_logged_in')->justReturn($loggedIn);
|
||||||
|
|
||||||
|
self::assertSame($expected, $this->ctx['page']->isRegistrationComplete(), $label);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testInviteOnlyMessageCanBeCustomised(): void
|
public function testInviteOnlyMessageCanBeCustomised(): void
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace Unsupervised\Schedular\Tests\Unit;
|
|||||||
|
|
||||||
use Brain\Monkey\Functions;
|
use Brain\Monkey\Functions;
|
||||||
use Unsupervised\Schedular\BlockPreview;
|
use Unsupervised\Schedular\BlockPreview;
|
||||||
|
use Unsupervised\Schedular\Booking\BookingPage;
|
||||||
|
|
||||||
class BlockPreviewTest extends TestCase
|
class BlockPreviewTest extends TestCase
|
||||||
{
|
{
|
||||||
@@ -18,6 +19,25 @@ class BlockPreviewTest extends TestCase
|
|||||||
self::assertStringContainsString('class="us-slot"', $html);
|
self::assertStringContainsString('class="us-slot"', $html);
|
||||||
self::assertStringContainsString('class="us-book-btn" disabled', $html);
|
self::assertStringContainsString('class="us-book-btn" disabled', $html);
|
||||||
self::assertStringContainsString('us-editor-note', $html);
|
self::assertStringContainsString('us-editor-note', $html);
|
||||||
|
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBookingOnlyPreviewLeavesOutTheUpcomingLessons(): void
|
||||||
|
{
|
||||||
|
$html = BlockPreview::booking(BookingPage::MODE_BOOKING);
|
||||||
|
|
||||||
|
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||||
|
self::assertStringNotContainsString('us-my-lessons', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpcomingOnlyPreviewLeavesOutTheCalendar(): void
|
||||||
|
{
|
||||||
|
$html = BlockPreview::booking(BookingPage::MODE_UPCOMING);
|
||||||
|
|
||||||
|
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||||
|
self::assertStringContainsString('Your upcoming lessons', $html);
|
||||||
|
self::assertStringNotContainsString('us-slot-list', $html);
|
||||||
|
self::assertStringNotContainsString('us-book-btn', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testGroupClassesPreviewMirrorsTheLiveMarkup(): void
|
public function testGroupClassesPreviewMirrorsTheLiveMarkup(): void
|
||||||
@@ -29,6 +49,17 @@ class BlockPreviewTest extends TestCase
|
|||||||
self::assertStringContainsString('class="us-class"', $html);
|
self::assertStringContainsString('class="us-class"', $html);
|
||||||
self::assertStringContainsString('class="us-enrol-btn" disabled', $html);
|
self::assertStringContainsString('class="us-enrol-btn" disabled', $html);
|
||||||
self::assertStringContainsString('us-editor-note', $html);
|
self::assertStringContainsString('us-editor-note', $html);
|
||||||
|
self::assertStringContainsString('A sample class shown so the page can be styled.', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testSingleClassGroupPreviewDropsTheDescriptionButKeepsScheduleAndEnrolment(): void
|
||||||
|
{
|
||||||
|
$html = BlockPreview::groupClasses(true);
|
||||||
|
|
||||||
|
self::assertStringNotContainsString('A sample class shown so the page can be styled.', $html);
|
||||||
|
self::assertStringContainsString('class="us-class-when"', $html);
|
||||||
|
self::assertStringContainsString('class="us-enrol-deadline"', $html);
|
||||||
|
self::assertStringContainsString('class="us-enrol-btn" disabled', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testLoginPreviewIncludesTheRealLoginTemplate(): void
|
public function testLoginPreviewIncludesTheRealLoginTemplate(): void
|
||||||
|
|||||||
@@ -52,6 +52,12 @@ class BlockRegistrarTest extends TestCase
|
|||||||
$this->registrationPage = Mockery::mock(RegistrationPage::class);
|
$this->registrationPage = Mockery::mock(RegistrationPage::class);
|
||||||
$this->groupClassPage = Mockery::mock(GroupClassPage::class);
|
$this->groupClassPage = Mockery::mock(GroupClassPage::class);
|
||||||
|
|
||||||
|
// Most requests are not a just-finished registration; the tests that
|
||||||
|
// exercise that path override this.
|
||||||
|
$this->registrationPage->shouldReceive('isRegistrationComplete')
|
||||||
|
->andReturn(false)
|
||||||
|
->byDefault();
|
||||||
|
|
||||||
$this->registrar = new TestableBlockRegistrar(
|
$this->registrar = new TestableBlockRegistrar(
|
||||||
$this->bookingPage,
|
$this->bookingPage,
|
||||||
$this->loginPage,
|
$this->loginPage,
|
||||||
@@ -118,7 +124,7 @@ class BlockRegistrarTest extends TestCase
|
|||||||
// The link-target and auto-redirect options must be declared
|
// The link-target and auto-redirect options must be declared
|
||||||
// server-side or the block-renderer preview rejects them.
|
// server-side or the block-renderer preview rejects them.
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
['loginPageId', 'autoRedirect'],
|
['loginPageId', 'autoRedirect', 'lessonTypeId', 'showTypeFilter', 'displayMode'],
|
||||||
array_keys($registered['us-scheduler/booking']['attributes'])
|
array_keys($registered['us-scheduler/booking']['attributes'])
|
||||||
);
|
);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
@@ -126,7 +132,7 @@ class BlockRegistrarTest extends TestCase
|
|||||||
array_keys($registered['us-scheduler/student-login']['attributes'])
|
array_keys($registered['us-scheduler/student-login']['attributes'])
|
||||||
);
|
);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
['loginPageId', 'inviteOnlyMessage'],
|
['loginPageId', 'autoRedirect', 'inviteOnlyMessage'],
|
||||||
array_keys($registered['us-scheduler/student-register']['attributes'])
|
array_keys($registered['us-scheduler/student-register']['attributes'])
|
||||||
);
|
);
|
||||||
self::assertSame(
|
self::assertSame(
|
||||||
@@ -179,6 +185,19 @@ class BlockRegistrarTest extends TestCase
|
|||||||
self::assertStringContainsString('us-group-app', $this->registrar->renderGroupClasses());
|
self::assertStringContainsString('us-group-app', $this->registrar->renderGroupClasses());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEditorPreviewOfAPinnedGroupClassOmitsTheDescription(): void
|
||||||
|
{
|
||||||
|
$this->registrar->preview = true;
|
||||||
|
$this->groupClassPage->shouldNotReceive('render');
|
||||||
|
|
||||||
|
$all = $this->registrar->renderGroupClasses();
|
||||||
|
$single = $this->registrar->renderGroupClasses(['offeringId' => 12]);
|
||||||
|
|
||||||
|
self::assertStringContainsString('A sample class shown so the page can be styled.', $all);
|
||||||
|
self::assertStringNotContainsString('A sample class shown so the page can be styled.', $single);
|
||||||
|
self::assertStringContainsString('us-enrol-deadline', $single);
|
||||||
|
}
|
||||||
|
|
||||||
public function testIsEditorPreviewIsFalseOutsideRestRequests(): void
|
public function testIsEditorPreviewIsFalseOutsideRestRequests(): void
|
||||||
{
|
{
|
||||||
// REST_REQUEST is undefined in the test process, so the real
|
// REST_REQUEST is undefined in the test process, so the real
|
||||||
@@ -384,6 +403,145 @@ class BlockRegistrarTest extends TestCase
|
|||||||
self::assertSame([], $this->registrar->redirects);
|
self::assertSame([], $this->registrar->redirects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testAutoRedirectSendsAFinishedRegistrationToTheChosenPage(): void
|
||||||
|
{
|
||||||
|
$this->stubSingularRequest(
|
||||||
|
30,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'blockName' => 'us-scheduler/student-register',
|
||||||
|
'attrs' => ['autoRedirect' => true, 'loginPageId' => 4],
|
||||||
|
'innerBlocks' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->registrationPage->shouldReceive('isRegistrationComplete')->andReturn(true);
|
||||||
|
$this->registrationPage->shouldReceive('continueUrl')
|
||||||
|
->once()->with(4)->andReturn('https://example.com/welcome/');
|
||||||
|
|
||||||
|
$this->registrar->maybeAutoRedirect();
|
||||||
|
|
||||||
|
self::assertSame(['https://example.com/welcome/'], $this->registrar->redirects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAutoRedirectSendsAJustLoggedInInvitedStudentToTheChosenPage(): void
|
||||||
|
{
|
||||||
|
// The invited-student branch completes logged in, so the logged-in
|
||||||
|
// student-login branch must not get first claim on the request.
|
||||||
|
$this->stubSingularRequest(
|
||||||
|
30,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'blockName' => 'us-scheduler/student-register',
|
||||||
|
'attrs' => ['autoRedirect' => true, 'loginPageId' => 4],
|
||||||
|
'innerBlocks' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->registrationPage->shouldReceive('isRegistrationComplete')->andReturn(true);
|
||||||
|
$this->registrationPage->shouldReceive('continueUrl')
|
||||||
|
->once()->with(4)->andReturn('https://example.com/welcome/');
|
||||||
|
|
||||||
|
$this->registrar->maybeAutoRedirect();
|
||||||
|
|
||||||
|
self::assertSame(['https://example.com/welcome/'], $this->registrar->redirects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoRedirectWhenTheRegistrationIsNotFinished(): void
|
||||||
|
{
|
||||||
|
// e.g. the "check your email" step, or a validation error — the
|
||||||
|
// message has to be read, so the block never redirects past it.
|
||||||
|
$this->stubSingularRequest(
|
||||||
|
30,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'blockName' => 'us-scheduler/student-register',
|
||||||
|
'attrs' => ['autoRedirect' => true, 'loginPageId' => 4],
|
||||||
|
'innerBlocks' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->registrationPage->shouldReceive('continueUrl')->never();
|
||||||
|
|
||||||
|
$this->registrar->maybeAutoRedirect();
|
||||||
|
|
||||||
|
self::assertSame([], $this->registrar->redirects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoRedirectWhenTheRegisterBlockDoesNotOptIn(): void
|
||||||
|
{
|
||||||
|
$this->stubSingularRequest(
|
||||||
|
30,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'blockName' => 'us-scheduler/student-register',
|
||||||
|
'attrs' => ['loginPageId' => 4],
|
||||||
|
'innerBlocks' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->registrationPage->shouldReceive('isRegistrationComplete')->andReturn(true);
|
||||||
|
$this->registrationPage->shouldReceive('continueUrl')->never();
|
||||||
|
|
||||||
|
$this->registrar->maybeAutoRedirect();
|
||||||
|
|
||||||
|
self::assertSame([], $this->registrar->redirects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoRedirectWhenTheRegisterBlockHasNoPageChosen(): void
|
||||||
|
{
|
||||||
|
$this->stubSingularRequest(
|
||||||
|
30,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'blockName' => 'us-scheduler/student-register',
|
||||||
|
'attrs' => ['autoRedirect' => true],
|
||||||
|
'innerBlocks' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->registrationPage->shouldReceive('isRegistrationComplete')->andReturn(true);
|
||||||
|
// No page chosen: there is no login-screen fallback to redirect to,
|
||||||
|
// so the student keeps the on-page confirmation instead.
|
||||||
|
$this->registrationPage->shouldReceive('continueUrl')->once()->with(0)->andReturnNull();
|
||||||
|
|
||||||
|
$this->registrar->maybeAutoRedirect();
|
||||||
|
|
||||||
|
self::assertSame([], $this->registrar->redirects);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testNoRedirectWhenTheRegisterBlockPointsAtItsOwnPage(): void
|
||||||
|
{
|
||||||
|
$this->stubSingularRequest(
|
||||||
|
4,
|
||||||
|
[
|
||||||
|
[
|
||||||
|
'blockName' => 'us-scheduler/student-register',
|
||||||
|
'attrs' => ['autoRedirect' => true, 'loginPageId' => 4],
|
||||||
|
'innerBlocks' => [],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->registrationPage->shouldReceive('isRegistrationComplete')->andReturn(true);
|
||||||
|
$this->registrationPage->shouldReceive('continueUrl')->never();
|
||||||
|
|
||||||
|
$this->registrar->maybeAutoRedirect();
|
||||||
|
|
||||||
|
self::assertSame([], $this->registrar->redirects);
|
||||||
|
}
|
||||||
|
|
||||||
public function testNoRedirectOutsideSingularFrontEndRequests(): void
|
public function testNoRedirectOutsideSingularFrontEndRequests(): void
|
||||||
{
|
{
|
||||||
Functions\when('is_admin')->justReturn(false);
|
Functions\when('is_admin')->justReturn(false);
|
||||||
|
|||||||
@@ -17,6 +17,26 @@ class BookingPageTest extends TestCase
|
|||||||
$this->page = new BookingPage();
|
$this->page = new BookingPage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Renders the page as a logged-in, approved student — the path that
|
||||||
|
* includes the template and its data attributes.
|
||||||
|
*
|
||||||
|
* @param array<int|string, mixed> $atts
|
||||||
|
*/
|
||||||
|
private function renderForStudent(array $atts): string
|
||||||
|
{
|
||||||
|
Functions\when('is_user_logged_in')->justReturn(true);
|
||||||
|
Functions\when('get_current_user_id')->justReturn(3);
|
||||||
|
Functions\when('get_user_meta')->justReturn('');
|
||||||
|
Functions\when('current_user_can')->justReturn(true);
|
||||||
|
Functions\when('wp_enqueue_style')->justReturn(null);
|
||||||
|
Functions\when('wp_enqueue_script')->justReturn(null);
|
||||||
|
Functions\when('wp_create_nonce')->justReturn('nonce123');
|
||||||
|
Functions\when('absint')->alias(static fn ($value) => abs((int) $value));
|
||||||
|
|
||||||
|
return $this->page->render($atts);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLoggedOutVisitorIsLinkedToTheWordPressLoginByDefault(): void
|
public function testLoggedOutVisitorIsLinkedToTheWordPressLoginByDefault(): void
|
||||||
{
|
{
|
||||||
Functions\when('is_user_logged_in')->justReturn(false);
|
Functions\when('is_user_logged_in')->justReturn(false);
|
||||||
@@ -59,6 +79,85 @@ class BookingPageTest extends TestCase
|
|||||||
self::assertStringContainsString('href="https://example.com/login/"', $html);
|
self::assertStringContainsString('href="https://example.com/login/"', $html);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testDefaultEmbedShowsBothHalvesWithTheFilterAndNoPinnedType(): void
|
||||||
|
{
|
||||||
|
$html = $this->renderForStudent([]);
|
||||||
|
|
||||||
|
self::assertStringContainsString('id="us-booking-app"', $html);
|
||||||
|
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||||
|
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||||
|
self::assertStringNotContainsString('data-lesson-type', $html);
|
||||||
|
self::assertStringNotContainsString('data-type-filter', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBlockLessonTypeAttributePinsASingleType(): void
|
||||||
|
{
|
||||||
|
self::assertStringContainsString(
|
||||||
|
'data-lesson-type="12"',
|
||||||
|
$this->renderForStudent(['lessonTypeId' => 12])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testShortcodeLessonTypeAttributePinsASingleType(): void
|
||||||
|
{
|
||||||
|
self::assertStringContainsString(
|
||||||
|
'data-lesson-type="7"',
|
||||||
|
$this->renderForStudent(['lesson_type' => '7'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testGarbageLessonTypeAttributeIsIgnored(): void
|
||||||
|
{
|
||||||
|
self::assertStringNotContainsString(
|
||||||
|
'data-lesson-type',
|
||||||
|
$this->renderForStudent(['lesson_type' => 'banana'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testFilterCanBeTurnedOffByBlockAndShortcodeAlike(): void
|
||||||
|
{
|
||||||
|
self::assertStringContainsString(
|
||||||
|
'data-type-filter="0"',
|
||||||
|
$this->renderForStudent(['showTypeFilter' => false])
|
||||||
|
);
|
||||||
|
|
||||||
|
// "no" is truthy to PHP, so the shortcode wording is matched explicitly.
|
||||||
|
self::assertStringContainsString(
|
||||||
|
'data-type-filter="0"',
|
||||||
|
$this->renderForStudent(['show_filter' => 'no'])
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertStringNotContainsString(
|
||||||
|
'data-type-filter',
|
||||||
|
$this->renderForStudent(['show_filter' => 'yes'])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testBookingOnlyEmbedLeavesOutTheUpcomingLessons(): void
|
||||||
|
{
|
||||||
|
$html = $this->renderForStudent(['displayMode' => 'booking']);
|
||||||
|
|
||||||
|
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||||
|
self::assertStringNotContainsString('us-my-lessons', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUpcomingOnlyEmbedLeavesOutTheBookingCalendar(): void
|
||||||
|
{
|
||||||
|
$html = $this->renderForStudent(['show' => 'upcoming']);
|
||||||
|
|
||||||
|
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||||
|
self::assertStringNotContainsString('us-slot-list', $html);
|
||||||
|
self::assertStringNotContainsString('us-booking-confirmation', $html);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testUnknownDisplayModeShowsTheWholePage(): void
|
||||||
|
{
|
||||||
|
$html = $this->renderForStudent(['displayMode' => 'sideways']);
|
||||||
|
|
||||||
|
self::assertStringContainsString('id="us-my-lessons"', $html);
|
||||||
|
self::assertStringContainsString('id="us-slot-list"', $html);
|
||||||
|
}
|
||||||
|
|
||||||
public function testLoginUrlFallsBackToWordPressLoginWhenThePageIsGone(): void
|
public function testLoginUrlFallsBackToWordPressLoginWhenThePageIsGone(): void
|
||||||
{
|
{
|
||||||
// The chosen page was deleted: get_permalink() returns false for it
|
// The chosen page was deleted: get_permalink() returns false for it
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ namespace Unsupervised\Schedular\Tests\Unit\Offering;
|
|||||||
|
|
||||||
use Brain\Monkey\Functions;
|
use Brain\Monkey\Functions;
|
||||||
use Mockery;
|
use Mockery;
|
||||||
|
use Unsupervised\Schedular\Auth\RoleManager;
|
||||||
use Unsupervised\Schedular\GroupClass\GroupAccessRepository;
|
use Unsupervised\Schedular\GroupClass\GroupAccessRepository;
|
||||||
use Unsupervised\Schedular\Offering\Offering;
|
use Unsupervised\Schedular\Offering\Offering;
|
||||||
use Unsupervised\Schedular\Offering\OfferingEndpoint;
|
use Unsupervised\Schedular\Offering\OfferingEndpoint;
|
||||||
@@ -119,6 +120,42 @@ class OfferingEndpointTest extends TestCase
|
|||||||
self::assertArrayNotHasKey('etransfer_email', $data[0]);
|
self::assertArrayNotHasKey('etransfer_email', $data[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanReadAllowsStudentsWhoMayBook(): void
|
||||||
|
{
|
||||||
|
Functions\when('is_user_logged_in')->justReturn(true);
|
||||||
|
Functions\when('current_user_can')->alias(
|
||||||
|
static fn (string $cap): bool => RoleManager::CAP_BOOK_LESSON === $cap
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertTrue($this->endpoint->canRead());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanReadAllowsOfferingManagersWhoCannotBook(): void
|
||||||
|
{
|
||||||
|
Functions\when('is_user_logged_in')->justReturn(true);
|
||||||
|
Functions\when('current_user_can')->alias(
|
||||||
|
static fn (string $cap): bool => RoleManager::CAP_MANAGE_OFFERINGS === $cap
|
||||||
|
);
|
||||||
|
|
||||||
|
self::assertTrue($this->endpoint->canRead());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanReadRejectsLoggedInUserWithNeitherCapability(): void
|
||||||
|
{
|
||||||
|
Functions\when('is_user_logged_in')->justReturn(true);
|
||||||
|
Functions\when('current_user_can')->justReturn(false);
|
||||||
|
|
||||||
|
self::assertFalse($this->endpoint->canRead());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanReadRejectsLoggedOutVisitors(): void
|
||||||
|
{
|
||||||
|
Functions\when('is_user_logged_in')->justReturn(false);
|
||||||
|
Functions\when('current_user_can')->justReturn(true);
|
||||||
|
|
||||||
|
self::assertFalse($this->endpoint->canRead());
|
||||||
|
}
|
||||||
|
|
||||||
public function testCreateRejectsTitleLongerThanColumnLimit(): void
|
public function testCreateRejectsTitleLongerThanColumnLimit(): void
|
||||||
{
|
{
|
||||||
Functions\when('sanitize_text_field')->returnArg();
|
Functions\when('sanitize_text_field')->returnArg();
|
||||||
|
|||||||
Reference in New Issue
Block a user