findOneBy(['uuid' => $uuid]); } public function findByEntity(string $entityType, int $entityId, bool $activeOnly = false): array { $qb = $this->createQueryBuilder('s') ->where('s.entityType = :type') ->andWhere('s.entityId = :id') ->setParameter('type', $entityType) ->setParameter('id', $entityId) ->orderBy('s.fullName', 'ASC'); if ($activeOnly) { $qb->andWhere('s.active = true'); } return $qb->getQuery()->getResult(); } /** * ردیف‌های فعالِ این کاربر در همهٔ محیط‌ها — یک نفر می‌تواند پرسنل چند کلینیک/مطب باشد. * * @return ClinicStaff[] */ public function findActiveByUser(User $user): array { return $this->createQueryBuilder('s') ->where('s.user = :user') ->andWhere('s.active = true') ->setParameter('user', $user) ->orderBy('s.fullName', 'ASC') ->getQuery() ->getResult(); } public function findActiveByUserAndEntity(User $user, string $entityType, int $entityId): ?ClinicStaff { return $this->findOneBy([ 'user' => $user, 'entityType' => $entityType, 'entityId' => $entityId, 'active' => true, ]); } /** برای جلوگیری از ثبت دو پرسنل با یک شماره در یک محیط. */ public function findByEntityAndPhone(string $entityType, int $entityId, string $phone): ?ClinicStaff { return $this->findOneBy([ 'entityType' => $entityType, 'entityId' => $entityId, 'phone' => $phone, ]); } public function save(ClinicStaff $staff): void { $this->getEntityManager()->persist($staff); $this->getEntityManager()->flush(); } }