New SessionAuditLog (mirrors AppointmentEvent): session FK, field, operation (create/update/delete), old_value/new_value, actor id+name, note, created_at. Repository saves and lists a session's history (newest first, array hydration). Migration creates the table. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
32 lines
1.2 KiB
PHP
32 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace App\Patient\Repository;
|
|
|
|
use App\Patient\Entity\SessionAuditLog;
|
|
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
|
|
use Doctrine\Persistence\ManagerRegistry;
|
|
|
|
class SessionAuditLogRepository extends ServiceEntityRepository
|
|
{
|
|
public function __construct(ManagerRegistry $registry) { parent::__construct($registry, SessionAuditLog::class); }
|
|
|
|
public function save(SessionAuditLog $e, bool $flush = true): void
|
|
{
|
|
$this->getEntityManager()->persist($e);
|
|
if ($flush) {
|
|
$this->getEntityManager()->flush();
|
|
}
|
|
}
|
|
|
|
/** تاریخچهی یک مراجعه (جدید → قدیم)، آرایهای. */
|
|
public function findBySessionUuid(string $sessionUuid): array
|
|
{
|
|
return $this->createQueryBuilder('l')
|
|
->select('l.field AS field', 'l.operation AS operation', 'l.oldValue AS old_value', 'l.newValue AS new_value', 'l.actorName AS actor_name', 'l.note AS note', 'l.createdAt AS created_at')
|
|
->join('l.session', 's')
|
|
->where('s.uuid = :uuid')->setParameter('uuid', $sessionUuid)
|
|
->orderBy('l.createdAt', 'DESC')->addOrderBy('l.id', 'DESC')
|
|
->getQuery()->getArrayResult();
|
|
}
|
|
}
|