diff --git a/src/Entity/Supervision.php b/src/Entity/Supervision.php new file mode 100644 index 0000000..8912a6d --- /dev/null +++ b/src/Entity/Supervision.php @@ -0,0 +1,55 @@ +id; + } + + public function getSupervisor(): ?User + { + return $this->supervisor; + } + + public function setSupervisor(?User $supervisor): static + { + $this->supervisor = $supervisor; + + return $this; + } + + public function getWorker(): ?User + { + return $this->worker; + } + + public function setWorker(User $worker): static + { + $this->worker = $worker; + + return $this; + } +} diff --git a/src/Form/SupervisorFormType.php b/src/Form/SupervisorFormType.php new file mode 100644 index 0000000..a8123fe --- /dev/null +++ b/src/Form/SupervisorFormType.php @@ -0,0 +1,33 @@ +add('supervisor', EntityType::class, [ + 'class' => User::class, + 'choice_label' => 'name', + 'label' => 'Staff Supervisor', + ]) + ; + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => Supervision::class, + ]); + } +} diff --git a/src/Repository/SupervisionRepository.php b/src/Repository/SupervisionRepository.php new file mode 100644 index 0000000..0aef6e8 --- /dev/null +++ b/src/Repository/SupervisionRepository.php @@ -0,0 +1,59 @@ + + */ +class SupervisionRepository extends ServiceEntityRepository +{ + public function __construct(ManagerRegistry $registry) + { + parent::__construct($registry, Supervision::class); + } + + public function getSupervisorByWorker(User $worker): ?User + { + $qb = $this->createQueryBuilder('s') + ->andWhere('s.worker = :worker') + ->setParameter('worker', $worker->getId()->toBinary()) + ->getQuery() + ->getResult() + ; + + if (count($qb) > 0) { + return $qb[0]->getSupervisor(); + } + return null; + } + + // /** + // * @return Supervision[] Returns an array of Supervision objects + // */ + // public function findByExampleField($value): array + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->orderBy('s.id', 'ASC') + // ->setMaxResults(10) + // ->getQuery() + // ->getResult() + // ; + // } + + // public function findOneBySomeField($value): ?Supervision + // { + // return $this->createQueryBuilder('s') + // ->andWhere('s.exampleField = :val') + // ->setParameter('val', $value) + // ->getQuery() + // ->getOneOrNullResult() + // ; + // } +}