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:
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)]
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>
*/
@ -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";
}
}