diff --git a/src/Entity/User.php b/src/Entity/User.php index 84d5f54..1f8067c 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -63,20 +63,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(enumType: CaseLevel::class)] private ?CaseLevel $level = null; - private ?User $supervisor = null; - - #[ORM\Column] - private ?bool $caseWorker = null; - - #[ORM\Column] - private ?bool $caseManager = null; - - #[ORM\Column] - private ?bool $therapist = null; - - #[ORM\Column] - private ?bool $su = null; - /** * @var Collection */ @@ -107,6 +93,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] private ?\DateTimeInterface $lastLogin = null; + private ?User $supervisor = null; + public function __construct() { $this->userCases = new ArrayCollection(); @@ -267,36 +255,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } - public function retrieveUnreadNotifications(): array - { - return [ - [ - 'id' => 1, - 'title' => 'Welcome', - 'from' => 'Admin', - 'type' => 'info', - 'message' => 'Welcome to the dashboard.', - 'timestamp' => new \DateTime('2024-11-12 10:00:00'), - ], - [ - 'id' => 2, - 'title' => 'New Case', - 'from' => 'Admin', - 'type' => 'info', - 'message' => 'You have a new case.', - 'timestamp' => new \DateTime('2024-11-13 10:19:56'), - ], - [ - 'id' => 3, - 'title' => 'New Message', - 'from' => 'Admin', - 'type' => 'warning', - 'message' => 'You have a new message.', - 'timestamp' => new \DateTime('2024-11-16 11:13:25'), - ], - ]; - } - public function getSupervisor(): ?User { return $this->supervisor; @@ -311,68 +269,40 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface public function isCaseWorker(): ?bool { - return $this->caseWorker; - } - - public function setCaseWorker(bool $caseWorker): static - { - $this->caseWorker = $caseWorker; - - return $this; + return in_array('ROLE_CASE_WORKER', $this->roles); } public function isCaseManager(): ?bool { - return $this->caseManager; - } - - public function setCaseManager(bool $caseManager): static - { - $this->caseManager = $caseManager; - - return $this; + return in_array('ROLE_CASE_MANAGER', $this->roles); } public function isTherapist(): ?bool { - return $this->therapist; + return in_array('ROLE_THERAPIST', $this->roles); } - public function setTherapist(bool $therapist): static + public function isAdmin(): ?bool { - $this->therapist = $therapist; - - return $this; - } - - public function isSu(): ?bool - { - return $this->su; - } - - public function setSu(bool $su): static - { - $this->su = $su; - - return $this; + return in_array('ROLE_ADMIN', $this->roles); } public function getJobs(): array { $jobs = []; - if ($this->caseWorker) { + if (in_array('ROLE_CASE_WORKER', $this->roles)) { $jobs[] = 'Case Worker'; } - if ($this->caseManager) { + if (in_array('ROLE_CASE_MANAGER', $this->roles)) { $jobs[] = 'Case Manager'; } - if ($this->therapist) { + if (in_array('ROLE_THERAPIST', $this->roles)) { $jobs[] = 'Therapist'; } - if ($this->su) { + if (in_array('ROLE_ADMIN', $this->roles)) { $jobs[] = 'Admin'; } @@ -484,4 +414,18 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this; } + + public function generateVCard(): string + { + list($fname, $lname) = explode(' ', $this->name, 2); + return 'BEGIN:VCARD' . + "\nVERSION:3.0" . + "\nN:{$lname};{$fname}" . + "\nFN:$this->name" . + "\nORG:{$this->company->getName()}" . + ($this->workPhone ? "\nTEL;TYPE=WORK,VOICE:$this->workPhone" : null) . + ($this->email ? "\nEMAIL;TYPE=WORK,INTERNET:$this->email" : null) . + "\nREV:" . date('c') . + "\nEND:VCARD"; + } } diff --git a/src/Form/EditUserFormType.php b/src/Form/EditUserFormType.php index fc70ebd..0aabf93 100644 --- a/src/Form/EditUserFormType.php +++ b/src/Form/EditUserFormType.php @@ -38,10 +38,20 @@ class EditUserFormType extends AbstractType ]) ->add('workPhone', TextType::class) ->add('personalPhone', TextType::class) - ->add('caseWorker', CheckboxType::class) - ->add('caseManager', CheckboxType::class) - ->add('therapist', CheckboxType::class) - ->add('su', CheckboxType::class, ['label' => 'Admin']) + ->add('active', CheckboxType::class) + ->add('caseWorker', CheckboxType::class, [ + 'mapped' => false + ]) + ->add('caseManager', CheckboxType::class, [ + 'mapped' => false + ]) + ->add('therapist', CheckboxType::class, [ + 'mapped' => false + ]) + ->add('su', CheckboxType::class, [ + 'mapped' => false, + 'label' => 'Admin' + ]) ->add('rateType', EnumType::class, [ 'class' => RateType::class ]) diff --git a/src/Form/UserFormType.php b/src/Form/UserFormType.php index d7eb278..4268dd8 100644 --- a/src/Form/UserFormType.php +++ b/src/Form/UserFormType.php @@ -61,11 +61,18 @@ class UserFormType extends AbstractType ]) ->add('workPhone', TextType::class) ->add('personalPhone', TextType::class) - ->add('caseWorker', CheckboxType::class) - ->add('caseManager', CheckboxType::class) - ->add('therapist', CheckboxType::class) + ->add('caseWorker', CheckboxType::class, [ + 'mapped' => false + ]) + ->add('caseManager', CheckboxType::class, [ + 'mapped' => false + ]) + ->add('therapist', CheckboxType::class, [ + 'mapped' => false + ]) ->add('su', CheckboxType::class, [ - 'label' => 'Admin', + 'mapped' => false, + 'label' => 'Admin', ]) ->add('level', EnumType::class, [ 'class' => CaseLevel::class, diff --git a/src/Repository/UserRepository.php b/src/Repository/UserRepository.php index 7171e1c..8ff5e8c 100644 --- a/src/Repository/UserRepository.php +++ b/src/Repository/UserRepository.php @@ -53,9 +53,9 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader public function getCaseManagers(Company $company): array { return $this->createQueryBuilder('u') - ->andWhere('u.caseManager = :case_manager') + ->andWhere('u.roles LIKE :role') ->andWhere('u.company = :company') - ->setParameter('case_manager', true) + ->setParameter('role', '%ROLE_CASE_MANAGER%') ->setParameter('company', $company->getId()->toBinary()) ->getQuery() ->getResult() @@ -65,9 +65,9 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader public function getTherapists(Company $company): array { return $this->createQueryBuilder('u') - ->andWhere('u.therapist = :therapist') + ->andWhere('u.roles LIKE :role') ->andWhere('u.company = :company') - ->setParameter('therapist', true) + ->setParameter('role', '%ROLE_THERAPIST%') ->setParameter('company', $company->getId()->toBinary()) ->getQuery() ->getResult() @@ -77,9 +77,9 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader public function getAdmins(Company $company): array { return $this->createQueryBuilder('u') - ->andWhere('u.su = :su') + ->andWhere('u.roles LIKE :role') ->andWhere('u.company = :company') - ->setParameter('su', true) + ->setParameter('role', '%ROLE_ADMIN%') ->setParameter('company', $company->getId()->toBinary()) ->getQuery() ->getResult() @@ -100,40 +100,11 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader public function getCaseWorkers(): array { return $this->createQueryBuilder('u') - ->orWhere('u.caseWorker = :case_worker') - ->orWhere('u.caseManager = :case_manager') - ->orWhere('u.therapist = :therapist') - ->setParameter('case_worker', true) - ->setParameter('case_manager', true) - ->setParameter('therapist', true) + ->andWhere('u.roles LIKE :role') + ->setParameter('role', '%ROLE_CASE_WORKER%') ->orderBy('u.name', 'ASC') ->getQuery() ->getResult() ; } - - // /** - // * @return User[] Returns an array of User objects - // */ - // public function findByExampleField($value): array - // { - // return $this->createQueryBuilder('u') - // ->andWhere('u.exampleField = :val') - // ->setParameter('val', $value) - // ->orderBy('u.id', 'ASC') - // ->setMaxResults(10) - // ->getQuery() - // ->getResult() - // ; - // } - - // public function findOneBySomeField($value): ?User - // { - // return $this->createQueryBuilder('u') - // ->andWhere('u.exampleField = :val') - // ->setParameter('val', $value) - // ->getQuery() - // ->getOneOrNullResult() - // ; - // } }