+ */
+ private const COLUMN_FORMATS = [ '%d', '%s', '%s', '%s', '%d', '%f', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d' ];
+
public function insert( Offering $offering ): int {
$this->db->insert(
$this->table,
$this->columns( $offering ) + [ 'created_at' => current_time( 'mysql' ) ],
- [ '%d', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d', '%s' ]
+ [ ...self::COLUMN_FORMATS, '%s' ]
);
return $this->db->insert_id;
@@ -26,7 +35,7 @@ class OfferingRepository {
$this->table,
$this->columns( $offering ),
[ 'id' => $id ],
- [ '%d', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d' ],
+ self::COLUMN_FORMATS,
[ '%d' ]
);
}
@@ -43,7 +52,7 @@ class OfferingRepository {
'title' => $offering->title,
'description' => $offering->description,
'duration_minutes' => $offering->durationMinutes,
- 'price_cents' => $offering->priceCents,
+ 'price' => $offering->price,
'currency' => $offering->currency,
'billing_mode' => $offering->billingMode,
'allow_weekly' => $offering->allowWeekly ? 1 : 0,
diff --git a/src/Schema.php b/src/Schema.php
index 4a41888..009c069 100644
--- a/src/Schema.php
+++ b/src/Schema.php
@@ -13,15 +13,20 @@ class Schema {
public static function tables( string $prefix, string $charset ): array {
return [
"CREATE TABLE {$prefix}us_availability (
- id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
- instructor_id BIGINT UNSIGNED NOT NULL,
- start_dt DATETIME NOT NULL,
- end_dt DATETIME NOT NULL,
- is_booked TINYINT(1) NOT NULL DEFAULT 0,
- created_at DATETIME NOT NULL,
+ id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
+ instructor_id BIGINT UNSIGNED NOT NULL,
+ offering_id BIGINT UNSIGNED DEFAULT NULL,
+ start_dt DATETIME NOT NULL,
+ end_dt DATETIME NOT NULL,
+ duration_minutes SMALLINT UNSIGNED NOT NULL DEFAULT 60,
+ is_booked TINYINT(1) NOT NULL DEFAULT 0,
+ recurrence_group BIGINT UNSIGNED DEFAULT NULL,
+ created_at DATETIME NOT NULL,
PRIMARY KEY (id),
KEY instructor_id (instructor_id),
- KEY start_dt (start_dt)
+ KEY offering_id (offering_id),
+ KEY start_dt (start_dt),
+ KEY recurrence_group (recurrence_group)
) {$charset};",
"CREATE TABLE {$prefix}us_lessons (
@@ -45,7 +50,7 @@ class Schema {
title VARCHAR(191) NOT NULL,
description TEXT,
duration_minutes SMALLINT UNSIGNED DEFAULT NULL,
- price_cents INT UNSIGNED NOT NULL DEFAULT 0,
+ price DECIMAL(10,2) NOT NULL DEFAULT 0,
currency VARCHAR(3) NOT NULL DEFAULT 'CAD',
billing_mode VARCHAR(20) NOT NULL DEFAULT 'one_time',
allow_weekly TINYINT(1) NOT NULL DEFAULT 0,
diff --git a/templates/admin/availability.php b/templates/admin/availability.php
index 9686dc2..6921b8c 100644
--- a/templates/admin/availability.php
+++ b/templates/admin/availability.php
@@ -5,7 +5,10 @@ if (! defined('ABSPATH')) {
exit;
}
-/** @var list<\Unsupervised\Schedular\Model\AvailabilitySlot> $slots */
+/**
+ * @var list<\Unsupervised\Schedular\Availability\AvailabilitySlot> $slots
+ * @var list<\Unsupervised\Schedular\Offering\Offering> $offeringChoices
+ */
?>
@@ -23,6 +26,35 @@ if (! defined('ABSPATH')) {
|
|
+
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+ |
+
+
+
+
+
+ |
+
@@ -37,6 +69,7 @@ if (! defined('ABSPATH')) {
|
|
+ |
|
|
@@ -46,6 +79,7 @@ if (! defined('ABSPATH')) {
| startDt); ?> |
endDt); ?> |
+ durationMinutes . ' min'); ?> |
isBooked ? esc_html__('Booked', 'unsupervised-schedular') : esc_html__('Available', 'unsupervised-schedular'); ?> |
isBooked) : ?>
diff --git a/templates/admin/offerings.php b/templates/admin/offerings.php
index 1b12fd4..3e4f5f3 100644
--- a/templates/admin/offerings.php
+++ b/templates/admin/offerings.php
@@ -35,8 +35,8 @@ if (! defined('ABSPATH')) {
| |
- |
- |
+ |
+ |
|
@@ -86,7 +86,7 @@ if (! defined('ABSPATH')) {
title); ?> |
kind); ?> |
durationMinutes ? esc_html((string) $offering->durationMinutes . ' min') : '—'; ?> |
- priceCents / 100, 2) . ' ' . $offering->currency); ?> |
+ price, 2) . ' ' . $offering->currency); ?> |
billingMode); ?> |
isActive ? esc_html__('Yes', 'unsupervised-schedular') : esc_html__('No', 'unsupervised-schedular'); ?> |
diff --git a/tests/Unit/Availability/AvailabilityRepositoryTest.php b/tests/Unit/Availability/AvailabilityRepositoryTest.php
index 83c5232..99f0ae0 100644
--- a/tests/Unit/Availability/AvailabilityRepositoryTest.php
+++ b/tests/Unit/Availability/AvailabilityRepositoryTest.php
@@ -34,19 +34,50 @@ class AvailabilityRepositoryTest extends TestCase
Mockery::on(static function (array $data): bool {
return $data['instructor_id'] === 5
&& $data['start_dt'] === '2026-04-01 09:00:00'
+ && $data['duration_minutes'] === 30
+ && $data['offering_id'] === 8
&& $data['is_booked'] === 0;
}),
- ['%d', '%s', '%s', '%d', '%s']
+ ['%d', '%d', '%s', '%s', '%d', '%d', '%d', '%s']
);
$this->db->insert_id = 42;
- $slot = new AvailabilitySlot(5, '2026-04-01 09:00:00', '2026-04-01 10:00:00');
+ $slot = new AvailabilitySlot(5, '2026-04-01 09:00:00', '2026-04-01 10:00:00', 30, 8);
$result = $this->repo->insert($slot);
self::assertSame(42, $result);
}
+ public function testCreateWeeklySeriesInsertsWeeklyAndSharesGroup(): void
+ {
+ Functions\when('current_time')->justReturn('2026-04-07 12:00:00');
+
+ $captured = [];
+ $ids = [10, 11, 12];
+
+ $this->db->shouldReceive('insert')
+ ->times(3)
+ ->andReturnUsing(function (string $table, array $data) use (&$captured, &$ids): void {
+ $captured[] = $data['start_dt'];
+ $this->db->insert_id = array_shift($ids);
+ });
+
+ // The first row is back-filled with its own id as the recurrence group.
+ $this->db->shouldReceive('update')
+ ->once()
+ ->with('wp_us_availability', ['recurrence_group' => 10], ['id' => 10], ['%d'], ['%d']);
+
+ $first = new AvailabilitySlot(5, '2026-04-07 09:00:00', '2026-04-07 10:00:00', 60);
+ $result = $this->repo->createWeeklySeries($first, 3);
+
+ self::assertSame([10, 11, 12], $result);
+ self::assertSame(
+ ['2026-04-07 09:00:00', '2026-04-14 09:00:00', '2026-04-21 09:00:00'],
+ $captured
+ );
+ }
+
public function testFindByIdReturnsNullWhenNotFound(): void
{
$this->db->shouldReceive('prepare')
@@ -65,11 +96,14 @@ class AvailabilityRepositoryTest extends TestCase
public function testFindByIdReturnsSlotWhenFound(): void
{
$row = (object) [
- 'id' => '10',
- 'instructor_id' => '5',
- 'start_dt' => '2026-04-01 09:00:00',
- 'end_dt' => '2026-04-01 10:00:00',
- 'is_booked' => '0',
+ 'id' => '10',
+ 'instructor_id' => '5',
+ 'offering_id' => null,
+ 'start_dt' => '2026-04-01 09:00:00',
+ 'end_dt' => '2026-04-01 10:00:00',
+ 'duration_minutes' => '60',
+ 'is_booked' => '0',
+ 'recurrence_group' => null,
];
$this->db->shouldReceive('prepare')->andReturn('SELECT ...');
@@ -128,14 +162,32 @@ class AvailabilityRepositoryTest extends TestCase
$this->repo->findAvailable(instructorId: 3);
}
+ public function testFindAvailableWithOfferingAndDurationFilters(): void
+ {
+ $this->db->shouldReceive('prepare')
+ ->once()
+ ->with(
+ Mockery::pattern('/offering_id = %d AND duration_minutes = %d/'),
+ Mockery::on(static fn (array $p): bool => $p === [8, 30])
+ )
+ ->andReturn('SELECT ...');
+
+ $this->db->shouldReceive('get_results')->andReturn([]);
+
+ $this->repo->findAvailable(offeringId: 8, durationMinutes: 30);
+ }
+
public function testFindByInstructorReturnsSlots(): void
{
$row = (object) [
- 'id' => '5',
- 'instructor_id' => '3',
- 'start_dt' => '2026-04-01 09:00:00',
- 'end_dt' => '2026-04-01 10:00:00',
- 'is_booked' => '0',
+ 'id' => '5',
+ 'instructor_id' => '3',
+ 'offering_id' => null,
+ 'start_dt' => '2026-04-01 09:00:00',
+ 'end_dt' => '2026-04-01 10:00:00',
+ 'duration_minutes' => '60',
+ 'is_booked' => '0',
+ 'recurrence_group' => null,
];
$this->db->shouldReceive('prepare')->andReturn('SELECT ...');
diff --git a/tests/Unit/Availability/AvailabilitySlotTest.php b/tests/Unit/Availability/AvailabilitySlotTest.php
index 81b9487..71b15e5 100644
--- a/tests/Unit/Availability/AvailabilitySlotTest.php
+++ b/tests/Unit/Availability/AvailabilitySlotTest.php
@@ -11,58 +11,66 @@ class AvailabilitySlotTest extends TestCase
public function testConstructorAndProperties(): void
{
$slot = new AvailabilitySlot(
- instructorId: 5,
- startDt: '2026-04-01 09:00:00',
- endDt: '2026-04-01 10:00:00',
- isBooked: false,
- id: 42,
+ instructorId: 5,
+ startDt: '2026-04-01 09:00:00',
+ endDt: '2026-04-01 10:00:00',
+ durationMinutes: 30,
+ offeringId: 8,
+ isBooked: false,
+ recurrenceGroup: 100,
+ id: 42,
);
self::assertSame(5, $slot->instructorId);
self::assertSame('2026-04-01 09:00:00', $slot->startDt);
- self::assertSame('2026-04-01 10:00:00', $slot->endDt);
+ self::assertSame(30, $slot->durationMinutes);
+ self::assertSame(8, $slot->offeringId);
+ self::assertSame(100, $slot->recurrenceGroup);
self::assertFalse($slot->isBooked);
self::assertSame(42, $slot->id);
}
- public function testFromRowMapsCorrectly(): void
+ public function testDefaults(): void
+ {
+ $slot = new AvailabilitySlot(1, '2026-04-01 09:00:00', '2026-04-01 10:00:00');
+
+ self::assertSame(60, $slot->durationMinutes);
+ self::assertNull($slot->offeringId);
+ self::assertFalse($slot->isBooked);
+ self::assertNull($slot->recurrenceGroup);
+ self::assertNull($slot->id);
+ }
+
+ public function testFromRowMapsCorrectlyAndCastsNullables(): void
{
$row = (object) [
- 'id' => '7',
- 'instructor_id' => '3',
- 'start_dt' => '2026-05-10 14:00:00',
- 'end_dt' => '2026-05-10 15:00:00',
- 'is_booked' => '1',
+ 'id' => '7',
+ 'instructor_id' => '3',
+ 'offering_id' => null,
+ 'start_dt' => '2026-05-10 14:00:00',
+ 'end_dt' => '2026-05-10 15:00:00',
+ 'duration_minutes' => '60',
+ 'is_booked' => '1',
+ 'recurrence_group' => '7',
];
$slot = AvailabilitySlot::fromRow($row);
self::assertSame(7, $slot->id);
self::assertSame(3, $slot->instructorId);
+ self::assertNull($slot->offeringId);
+ self::assertSame(60, $slot->durationMinutes);
+ self::assertSame(7, $slot->recurrenceGroup);
self::assertTrue($slot->isBooked);
}
public function testToArrayContainsExpectedKeys(): void
{
- $slot = new AvailabilitySlot(1, '2026-04-01 09:00:00', '2026-04-01 10:00:00', false, 10);
+ $slot = new AvailabilitySlot(1, '2026-04-01 09:00:00', '2026-04-01 10:00:00', 30, 8, false, null, 10);
$arr = $slot->toArray();
- self::assertArrayHasKey('id', $arr);
- self::assertArrayHasKey('instructor_id', $arr);
- self::assertArrayHasKey('start_dt', $arr);
- self::assertArrayHasKey('end_dt', $arr);
- self::assertArrayHasKey('is_booked', $arr);
- }
-
- public function testDefaultIsBookedIsFalse(): void
- {
- $slot = new AvailabilitySlot(1, '2026-04-01 09:00:00', '2026-04-01 10:00:00');
- self::assertFalse($slot->isBooked);
- }
-
- public function testDefaultIdIsNull(): void
- {
- $slot = new AvailabilitySlot(1, '2026-04-01 09:00:00', '2026-04-01 10:00:00');
- self::assertNull($slot->id);
+ foreach (['id', 'instructor_id', 'offering_id', 'start_dt', 'end_dt', 'duration_minutes', 'is_booked', 'recurrence_group'] as $key) {
+ self::assertArrayHasKey($key, $arr);
+ }
}
}
diff --git a/tests/Unit/Offering/OfferingRepositoryTest.php b/tests/Unit/Offering/OfferingRepositoryTest.php
index 86f88dc..cf0a18b 100644
--- a/tests/Unit/Offering/OfferingRepositoryTest.php
+++ b/tests/Unit/Offering/OfferingRepositoryTest.php
@@ -35,7 +35,7 @@ class OfferingRepositoryTest extends TestCase
return $data['instructor_id'] === 5
&& $data['kind'] === Offering::KIND_PRIVATE_LESSON
&& $data['title'] === '30-min Piano'
- && $data['price_cents'] === 3500
+ && $data['price'] === 35.00
&& $data['allow_weekly'] === 0
&& $data['is_active'] === 1
&& $data['created_at'] === '2026-04-01 12:00:00';
@@ -49,7 +49,7 @@ class OfferingRepositoryTest extends TestCase
instructorId: 5,
kind: Offering::KIND_PRIVATE_LESSON,
title: '30-min Piano',
- priceCents: 3500,
+ price: 35.00,
durationMinutes: 30,
);
@@ -168,7 +168,7 @@ class OfferingRepositoryTest extends TestCase
'title' => '30-min Piano',
'description' => null,
'duration_minutes' => '30',
- 'price_cents' => '3500',
+ 'price' => '35.00',
'currency' => 'CAD',
'billing_mode' => Offering::BILLING_ONE_TIME,
'allow_weekly' => '0',
diff --git a/tests/Unit/Offering/OfferingTest.php b/tests/Unit/Offering/OfferingTest.php
index fc27e42..c90bfb2 100644
--- a/tests/Unit/Offering/OfferingTest.php
+++ b/tests/Unit/Offering/OfferingTest.php
@@ -14,7 +14,7 @@ class OfferingTest extends TestCase
instructorId: 5,
kind: Offering::KIND_PRIVATE_LESSON,
title: '30-min Piano',
- priceCents: 3500,
+ price: 35.00,
billingMode: Offering::BILLING_ONE_TIME,
durationMinutes: 30,
id: 42,
@@ -23,7 +23,7 @@ class OfferingTest extends TestCase
self::assertSame(5, $offering->instructorId);
self::assertSame(Offering::KIND_PRIVATE_LESSON, $offering->kind);
self::assertSame('30-min Piano', $offering->title);
- self::assertSame(3500, $offering->priceCents);
+ self::assertSame(35.00, $offering->price);
self::assertSame(30, $offering->durationMinutes);
self::assertSame(42, $offering->id);
}
@@ -32,7 +32,7 @@ class OfferingTest extends TestCase
{
$offering = new Offering(1, Offering::KIND_GROUP_CLASS, 'Choir');
- self::assertSame(0, $offering->priceCents);
+ self::assertSame(0.0, $offering->price);
self::assertSame('CAD', $offering->currency);
self::assertSame(Offering::BILLING_ONE_TIME, $offering->billingMode);
self::assertNull($offering->durationMinutes);
@@ -51,7 +51,7 @@ class OfferingTest extends TestCase
'title' => 'Year Choir',
'description' => 'Weekly choir',
'duration_minutes' => null,
- 'price_cents' => '12000',
+ 'price' => '120.00',
'currency' => 'CAD',
'billing_mode' => Offering::BILLING_FULL_TERM,
'allow_weekly' => '0',
@@ -67,7 +67,7 @@ class OfferingTest extends TestCase
self::assertSame(7, $offering->id);
self::assertSame(3, $offering->instructorId);
self::assertNull($offering->durationMinutes);
- self::assertSame(12000, $offering->priceCents);
+ self::assertSame(120.00, $offering->price);
self::assertSame(20, $offering->capacity);
self::assertSame(Offering::BILLING_FULL_TERM, $offering->billingMode);
self::assertTrue($offering->isActive);
@@ -78,7 +78,7 @@ class OfferingTest extends TestCase
$offering = new Offering(1, Offering::KIND_PRIVATE_LESSON, 'Lesson', id: 10);
$arr = $offering->toArray();
- foreach (['id', 'instructor_id', 'kind', 'title', 'price_cents', 'billing_mode', 'is_active'] as $key) {
+ foreach (['id', 'instructor_id', 'kind', 'title', 'price', 'billing_mode', 'is_active'] as $key) {
self::assertArrayHasKey($key, $arr);
}
}
|