Files
unsupervised-scheduler/src/Policy/AcceptanceRepository.php
T
thatguygriffandClaude Fable 5 c49171695a
CI / Coding Standards (pull_request) Successful in 2m47s
CI / PHPStan (pull_request) Successful in 2m56s
CI / Tests (PHP 8.3) (pull_request) Successful in 2m39s
CI / Build Plugin Zip (pull_request) Skipped
CI / Tests (PHP 8.2) (pull_request) Successful in 43s
CI / Tests (PHP 8.1) (pull_request) Successful in 44s
CI / No Debug Code (pull_request) Successful in 2s
Add policy, intake, and payment history to the admin student detail view
The student-administration spec deferred three detail-view sections until
Payments landed. Adds them now: policy-acceptance history (title, version,
context, date), intake answers (label, answer, context), and — gated on
manage_billing — payment history with HST breakdown and receipt numbers.

New Auth\StudentHistory builds the display rows from per-student queries
added to AcceptanceRepository, AnswerRepository, and PaymentRepository;
the Payment model now carries created_at so unpaid rows still have a date.

Closes #69

Co-Authored-By: Claude Fable 5 <[email protected]>
2026-07-18 18:17:20 -03:00

76 lines
2.0 KiB
PHP

<?php
declare(strict_types=1);
namespace Unsupervised\Schedular\Policy;
class AcceptanceRepository {
private string $table;
public function __construct( private \wpdb $db ) {
$this->table = $db->prefix . 'us_policy_acceptances';
}
public function insert( PolicyAcceptance $acceptance ): int {
$this->db->insert(
$this->table,
[
'policy_version_id' => $acceptance->policyVersionId,
'student_id' => $acceptance->studentId,
'registration_type' => $acceptance->registrationType,
'registration_id' => $acceptance->registrationId,
'ip_address' => $acceptance->ipAddress,
'accepted_at' => current_time( 'mysql' ),
],
[ '%d', '%d', '%s', '%d', '%s', '%s' ]
);
return $this->db->insert_id;
}
/**
* Persist a batch of acceptances for a single registration.
*
* @param list<PolicyAcceptance> $acceptances
* @return list<int> Inserted acceptance IDs.
*/
public function insertMany( array $acceptances ): array {
return array_map( fn( PolicyAcceptance $a ): int => $this->insert( $a ), $acceptances );
}
/**
* Find all acceptances attached to a registration (lesson or enrolment).
*
* @return list<PolicyAcceptance>
*/
public function findByRegistration( string $registrationType, int $registrationId ): array {
$rows = $this->db->get_results(
$this->db->prepare(
'SELECT * FROM %i WHERE registration_type = %s AND registration_id = %d ORDER BY id ASC',
$this->table,
$registrationType,
$registrationId
)
);
return array_map( PolicyAcceptance::fromRow( ... ), $rows ?? [] );
}
/**
* Find every acceptance a student has recorded, newest first.
*
* @return list<PolicyAcceptance>
*/
public function findByStudent( int $studentId ): array {
$rows = $this->db->get_results(
$this->db->prepare(
'SELECT * FROM %i WHERE student_id = %d ORDER BY accepted_at DESC, id DESC',
$this->table,
$studentId
)
);
return array_map( PolicyAcceptance::fromRow( ... ), $rows ?? [] );
}
}