Add Offerings domain and studio-admin capabilities
CI / Coding Standards (pull_request) Successful in 55s
CI / PHPStan (pull_request) Successful in 1m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 50s
CI / Tests (PHP 8.2) (pull_request) Successful in 46s
CI / Tests (PHP 8.3) (pull_request) Successful in 50s
CI / No Debug Code (pull_request) Successful in 2s
CI / Coding Standards (pull_request) Successful in 55s
CI / PHPStan (pull_request) Successful in 1m0s
CI / Tests (PHP 8.1) (pull_request) Successful in 50s
CI / Tests (PHP 8.2) (pull_request) Successful in 46s
CI / Tests (PHP 8.3) (pull_request) Successful in 50s
CI / No Debug Code (pull_request) Successful in 2s
Implements the offerings catalog (#1): private-lesson types and group classes carrying pricing, billing mode (one_time/full_term), duration, capacity, and term details. Adds the src/Offering/ domain (value object, repository, REST endpoint, admin controller + template), the us_offerings table, and an Offerings admin page. Also lands the capability slice of #9: registers the us_studio_admin role and the new capability strings (manage_instructors, manage_offerings, manage_questions, manage_policies, manage_billing, view_all_payments, view_own_payments, export_payments) so offering management gates correctly. Tests: tests/Unit/Offering/ (value object + repository) and a studio-admin case in RoleManagerTest. composer test, cs, and PHPStan level 6 all pass. Refs #1 #9 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Unsupervised\Schedular\Offering;
|
||||
|
||||
class OfferingRepository {
|
||||
|
||||
private string $table;
|
||||
|
||||
public function __construct( private \wpdb $db ) {
|
||||
$this->table = $db->prefix . 'us_offerings';
|
||||
}
|
||||
|
||||
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' ]
|
||||
);
|
||||
|
||||
return $this->db->insert_id;
|
||||
}
|
||||
|
||||
public function update( int $id, Offering $offering ): bool {
|
||||
return false !== $this->db->update(
|
||||
$this->table,
|
||||
$this->columns( $offering ),
|
||||
[ 'id' => $id ],
|
||||
[ '%d', '%s', '%s', '%s', '%d', '%s', '%s', '%d', '%d', '%s', '%s', '%s', '%d' ],
|
||||
[ '%d' ]
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Column values shared by insert and update (excludes created_at).
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
private function columns( Offering $offering ): array {
|
||||
return [
|
||||
'instructor_id' => $offering->instructorId,
|
||||
'kind' => $offering->kind,
|
||||
'title' => $offering->title,
|
||||
'description' => $offering->description,
|
||||
'duration_minutes' => $offering->durationMinutes,
|
||||
'price_cents' => $offering->priceCents,
|
||||
'currency' => $offering->currency,
|
||||
'billing_mode' => $offering->billingMode,
|
||||
'allow_weekly' => $offering->allowWeekly ? 1 : 0,
|
||||
'capacity' => $offering->capacity,
|
||||
'term_start' => $offering->termStart,
|
||||
'term_end' => $offering->termEnd,
|
||||
'schedule_note' => $offering->scheduleNote,
|
||||
'is_active' => $offering->isActive ? 1 : 0,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Find offerings, optionally filtered by instructor, kind, and active state.
|
||||
*
|
||||
* @return list<Offering>
|
||||
*/
|
||||
public function findAll( int $instructorId = 0, string $kind = '', ?bool $activeOnly = null ): array {
|
||||
$where = [ '1 = 1' ];
|
||||
$params = [];
|
||||
|
||||
if ( $instructorId > 0 ) {
|
||||
$where[] = 'instructor_id = %d';
|
||||
$params[] = $instructorId;
|
||||
}
|
||||
|
||||
if ( '' !== $kind ) {
|
||||
$where[] = 'kind = %s';
|
||||
$params[] = $kind;
|
||||
}
|
||||
|
||||
if ( null !== $activeOnly ) {
|
||||
$where[] = 'is_active = %d';
|
||||
$params[] = $activeOnly ? 1 : 0;
|
||||
}
|
||||
|
||||
$whereClause = implode( ' AND ', $where );
|
||||
$sql = "SELECT * FROM {$this->table} WHERE {$whereClause} ORDER BY title ASC";
|
||||
|
||||
$rows = $params
|
||||
? $this->db->get_results( $this->db->prepare( $sql, $params ) )
|
||||
: $this->db->get_results( $sql );
|
||||
|
||||
return array_map( Offering::fromRow( ... ), $rows ?? [] );
|
||||
}
|
||||
|
||||
public function findById( int $id ): ?Offering {
|
||||
$row = $this->db->get_row(
|
||||
$this->db->prepare( "SELECT * FROM {$this->table} WHERE id = %d", $id )
|
||||
);
|
||||
|
||||
return $row ? Offering::fromRow( $row ) : null;
|
||||
}
|
||||
|
||||
public function delete( int $id ): bool {
|
||||
return (bool) $this->db->delete(
|
||||
$this->table,
|
||||
[ 'id' => $id ],
|
||||
[ '%d' ]
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user