|
- <?php
-
- declare(strict_types=1);
-
- namespace App\Repositories;
-
- use Core\Repository;
-
- /**
- * Action codes: I Insert · U Update · D Delete · R Restore
- */
- class JobAuditRepository extends Repository
- {
- protected string $table = 'job_audit';
- protected string $primaryKey = 'audit_id';
-
- /** @param array<string, mixed> $fields */
- public function log(int $jobId, string $action, array $fields, string $username): void
- {
- $this->database->execute(
- "INSERT INTO job_audit (id, action, fields, username)
- VALUES (:id, :action, :fields, :username)",
- [
- 'id' => $jobId,
- 'action' => $action,
- 'fields' => json_encode($fields, JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES),
- 'username' => $username,
- ]
- );
- }
-
- /** @return list<array<string, mixed>> */
- public function forRecord(int $jobId): array
- {
- return $this->database->query(
- 'SELECT audit_id, id, action, fields, username, created_at
- FROM job_audit WHERE id = :id ORDER BY audit_id ASC',
- ['id' => $jobId]
- );
- }
- }
|