Add supervision classes to support assigning staff supervisors

This commit is contained in:
Ryan Prather 2024-11-30 20:04:24 -05:00
parent 97de984456
commit 481a2c2f40
3 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,55 @@
<?php
namespace App\Entity;
use App\Repository\SupervisionRepository;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Bridge\Doctrine\Types\UuidType;
use Symfony\Component\Uid\Uuid;
#[ORM\Entity(repositoryClass: SupervisionRepository::class)]
class Supervision
{
#[ORM\Id]
#[ORM\Column(type: UuidType::NAME, unique: true)]
#[ORM\GeneratedValue(strategy: 'CUSTOM')]
#[ORM\CustomIdGenerator(class: 'doctrine.uuid_generator')]
private ?Uuid $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?User $supervisor = null;
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: false)]
private ?User $worker = null;
public function getId(): ?Uuid
{
return $this->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;
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace App\Form;
use App\Entity\Supervision;
use App\Entity\User;
use Doctrine\ORM\Mapping\Entity;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class SupervisorFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->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,
]);
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace App\Repository;
use App\Entity\Supervision;
use App\Entity\User;
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
use Doctrine\Persistence\ManagerRegistry;
/**
* @extends ServiceEntityRepository<Supervision>
*/
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()
// ;
// }
}