fix: User

various updates
* remove unnecessary caseWorker, caseManager, therapist, su properties
* Removed retrieveUnreadNotifications method that was just a stub
* convert "is..." methods to check for present roles
* update getJobs method with above logic
* add generateVCard method to support company directory
This commit is contained in:
Ryan Prather 2025-01-21 14:29:31 -05:00
parent 224a5cd243
commit 922852f211
4 changed files with 58 additions and 126 deletions

View File

@ -63,20 +63,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(enumType: CaseLevel::class)] #[ORM\Column(enumType: CaseLevel::class)]
private ?CaseLevel $level = null; 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<int, UserCase> * @var Collection<int, UserCase>
*/ */
@ -107,6 +93,8 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
#[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)] #[ORM\Column(type: Types::DATETIME_MUTABLE, nullable: true)]
private ?\DateTimeInterface $lastLogin = null; private ?\DateTimeInterface $lastLogin = null;
private ?User $supervisor = null;
public function __construct() public function __construct()
{ {
$this->userCases = new ArrayCollection(); $this->userCases = new ArrayCollection();
@ -267,36 +255,6 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this; 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 public function getSupervisor(): ?User
{ {
return $this->supervisor; return $this->supervisor;
@ -311,68 +269,40 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
public function isCaseWorker(): ?bool public function isCaseWorker(): ?bool
{ {
return $this->caseWorker; return in_array('ROLE_CASE_WORKER', $this->roles);
}
public function setCaseWorker(bool $caseWorker): static
{
$this->caseWorker = $caseWorker;
return $this;
} }
public function isCaseManager(): ?bool public function isCaseManager(): ?bool
{ {
return $this->caseManager; return in_array('ROLE_CASE_MANAGER', $this->roles);
}
public function setCaseManager(bool $caseManager): static
{
$this->caseManager = $caseManager;
return $this;
} }
public function isTherapist(): ?bool 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 in_array('ROLE_ADMIN', $this->roles);
return $this;
}
public function isSu(): ?bool
{
return $this->su;
}
public function setSu(bool $su): static
{
$this->su = $su;
return $this;
} }
public function getJobs(): array public function getJobs(): array
{ {
$jobs = []; $jobs = [];
if ($this->caseWorker) { if (in_array('ROLE_CASE_WORKER', $this->roles)) {
$jobs[] = 'Case Worker'; $jobs[] = 'Case Worker';
} }
if ($this->caseManager) { if (in_array('ROLE_CASE_MANAGER', $this->roles)) {
$jobs[] = 'Case Manager'; $jobs[] = 'Case Manager';
} }
if ($this->therapist) { if (in_array('ROLE_THERAPIST', $this->roles)) {
$jobs[] = 'Therapist'; $jobs[] = 'Therapist';
} }
if ($this->su) { if (in_array('ROLE_ADMIN', $this->roles)) {
$jobs[] = 'Admin'; $jobs[] = 'Admin';
} }
@ -484,4 +414,18 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
return $this; 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";
}
} }

View File

@ -38,10 +38,20 @@ class EditUserFormType extends AbstractType
]) ])
->add('workPhone', TextType::class) ->add('workPhone', TextType::class)
->add('personalPhone', TextType::class) ->add('personalPhone', TextType::class)
->add('caseWorker', CheckboxType::class) ->add('active', CheckboxType::class)
->add('caseManager', CheckboxType::class) ->add('caseWorker', CheckboxType::class, [
->add('therapist', CheckboxType::class) 'mapped' => false
->add('su', CheckboxType::class, ['label' => 'Admin']) ])
->add('caseManager', CheckboxType::class, [
'mapped' => false
])
->add('therapist', CheckboxType::class, [
'mapped' => false
])
->add('su', CheckboxType::class, [
'mapped' => false,
'label' => 'Admin'
])
->add('rateType', EnumType::class, [ ->add('rateType', EnumType::class, [
'class' => RateType::class 'class' => RateType::class
]) ])

View File

@ -61,11 +61,18 @@ class UserFormType extends AbstractType
]) ])
->add('workPhone', TextType::class) ->add('workPhone', TextType::class)
->add('personalPhone', TextType::class) ->add('personalPhone', TextType::class)
->add('caseWorker', CheckboxType::class) ->add('caseWorker', CheckboxType::class, [
->add('caseManager', CheckboxType::class) 'mapped' => false
->add('therapist', CheckboxType::class) ])
->add('caseManager', CheckboxType::class, [
'mapped' => false
])
->add('therapist', CheckboxType::class, [
'mapped' => false
])
->add('su', CheckboxType::class, [ ->add('su', CheckboxType::class, [
'label' => 'Admin', 'mapped' => false,
'label' => 'Admin',
]) ])
->add('level', EnumType::class, [ ->add('level', EnumType::class, [
'class' => CaseLevel::class, 'class' => CaseLevel::class,

View File

@ -53,9 +53,9 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
public function getCaseManagers(Company $company): array public function getCaseManagers(Company $company): array
{ {
return $this->createQueryBuilder('u') return $this->createQueryBuilder('u')
->andWhere('u.caseManager = :case_manager') ->andWhere('u.roles LIKE :role')
->andWhere('u.company = :company') ->andWhere('u.company = :company')
->setParameter('case_manager', true) ->setParameter('role', '%ROLE_CASE_MANAGER%')
->setParameter('company', $company->getId()->toBinary()) ->setParameter('company', $company->getId()->toBinary())
->getQuery() ->getQuery()
->getResult() ->getResult()
@ -65,9 +65,9 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
public function getTherapists(Company $company): array public function getTherapists(Company $company): array
{ {
return $this->createQueryBuilder('u') return $this->createQueryBuilder('u')
->andWhere('u.therapist = :therapist') ->andWhere('u.roles LIKE :role')
->andWhere('u.company = :company') ->andWhere('u.company = :company')
->setParameter('therapist', true) ->setParameter('role', '%ROLE_THERAPIST%')
->setParameter('company', $company->getId()->toBinary()) ->setParameter('company', $company->getId()->toBinary())
->getQuery() ->getQuery()
->getResult() ->getResult()
@ -77,9 +77,9 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
public function getAdmins(Company $company): array public function getAdmins(Company $company): array
{ {
return $this->createQueryBuilder('u') return $this->createQueryBuilder('u')
->andWhere('u.su = :su') ->andWhere('u.roles LIKE :role')
->andWhere('u.company = :company') ->andWhere('u.company = :company')
->setParameter('su', true) ->setParameter('role', '%ROLE_ADMIN%')
->setParameter('company', $company->getId()->toBinary()) ->setParameter('company', $company->getId()->toBinary())
->getQuery() ->getQuery()
->getResult() ->getResult()
@ -100,40 +100,11 @@ class UserRepository extends ServiceEntityRepository implements PasswordUpgrader
public function getCaseWorkers(): array public function getCaseWorkers(): array
{ {
return $this->createQueryBuilder('u') return $this->createQueryBuilder('u')
->orWhere('u.caseWorker = :case_worker') ->andWhere('u.roles LIKE :role')
->orWhere('u.caseManager = :case_manager') ->setParameter('role', '%ROLE_CASE_WORKER%')
->orWhere('u.therapist = :therapist')
->setParameter('case_worker', true)
->setParameter('case_manager', true)
->setParameter('therapist', true)
->orderBy('u.name', 'ASC') ->orderBy('u.name', 'ASC')
->getQuery() ->getQuery()
->getResult() ->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()
// ;
// }
} }