- Implemented SidebarStaff component tests to ensure staff users see only their dashboard and services. - Created StaffMyServicesPage to display assigned services for staff users. - Added migration to link clinic staff rows to user accounts for ROLE_STAFF access. - Defined StaffPermissions class for static permissions related to staff role. - Introduced StaffRouteGuardSubscriber to restrict API access for staff users. - Developed StaffAccountService for managing staff user accounts and linking them to clinic staff. - Added comprehensive tests for StaffAccountService to validate user creation, mobile number handling, and account attachment. - Implemented tests for staff dashboard access to ensure proper permissions and access control. - Created tests for staff login context to verify correct environment visibility based on user roles.
122 lines
5.1 KiB
PHP
122 lines
5.1 KiB
PHP
<?php
|
|
|
|
namespace App\Staff\Entity;
|
|
|
|
use App\Auth\Entity\User;
|
|
use App\Staff\Repository\ClinicStaffRepository;
|
|
use Doctrine\ORM\Mapping as ORM;
|
|
use Symfony\Component\Uid\Uuid;
|
|
|
|
#[ORM\Entity(repositoryClass: ClinicStaffRepository::class)]
|
|
#[ORM\Table(name: 'clinic_staff')]
|
|
#[ORM\Index(columns: ['entity_type', 'entity_id', 'active'], name: 'idx_staff_entity_active')]
|
|
#[ORM\Index(columns: ['user_id', 'active'], name: 'idx_staff_user_active')]
|
|
class ClinicStaff
|
|
{
|
|
#[ORM\Id]
|
|
#[ORM\GeneratedValue]
|
|
#[ORM\Column(type: 'integer')]
|
|
private ?int $id = null;
|
|
|
|
#[ORM\Column(type: 'string', length: 36, unique: true)]
|
|
private string $uuid;
|
|
|
|
#[ORM\Column(name: 'entity_type', type: 'string', length: 10)]
|
|
private string $entityType;
|
|
|
|
#[ORM\Column(name: 'entity_id', type: 'integer')]
|
|
private int $entityId;
|
|
|
|
#[ORM\Column(name: 'full_name', type: 'string', length: 200)]
|
|
private string $fullName;
|
|
|
|
#[ORM\Column(type: 'string', length: 20, nullable: true)]
|
|
private ?string $phone = null;
|
|
|
|
#[ORM\Column(name: 'job_title', type: 'string', length: 100, nullable: true)]
|
|
private ?string $jobTitle = null;
|
|
|
|
#[ORM\Column(type: 'text', nullable: true)]
|
|
private ?string $address = null;
|
|
|
|
#[ORM\Column(name: 'national_code', type: 'string', length: 15, nullable: true)]
|
|
private ?string $nationalCode = null;
|
|
|
|
#[ORM\Column(type: 'boolean')]
|
|
private bool $active = true;
|
|
|
|
/**
|
|
* حساب کاربری پرسنل برای ورود به پنل. nullable است چون پرسنل میتواند صرفاً یک
|
|
* رکورد اطلاعاتی باشد؛ قطع دسترسی هم با null کردن همین ستون انجام میشود تا
|
|
* ارجاعات سرویس/نوبت به این ردیف دستنخورده بماند.
|
|
*/
|
|
#[ORM\ManyToOne(targetEntity: User::class)]
|
|
#[ORM\JoinColumn(name: 'user_id', nullable: true, onDelete: 'SET NULL')]
|
|
private ?User $user = null;
|
|
|
|
#[ORM\Column(name: 'created_at', type: 'integer')]
|
|
private int $createdAt;
|
|
|
|
#[ORM\Column(name: 'updated_at', type: 'integer')]
|
|
private int $updatedAt;
|
|
|
|
public function __construct(string $entityType, int $entityId, string $fullName)
|
|
{
|
|
$this->uuid = Uuid::v4()->toRfc4122();
|
|
$this->entityType = $entityType;
|
|
$this->entityId = $entityId;
|
|
$this->fullName = $fullName;
|
|
$this->createdAt = time();
|
|
$this->updatedAt = time();
|
|
}
|
|
|
|
public function getId(): ?int { return $this->id; }
|
|
public function getUuid(): string { return $this->uuid; }
|
|
public function getEntityType(): string { return $this->entityType; }
|
|
public function getEntityId(): int { return $this->entityId; }
|
|
public function getFullName(): string { return $this->fullName; }
|
|
public function getPhone(): ?string { return $this->phone; }
|
|
public function getJobTitle(): ?string { return $this->jobTitle; }
|
|
public function getAddress(): ?string { return $this->address; }
|
|
public function getNationalCode(): ?string { return $this->nationalCode; }
|
|
public function isActive(): bool { return $this->active; }
|
|
public function getUser(): ?User { return $this->user; }
|
|
public function hasAccount(): bool { return $this->user !== null; }
|
|
public function getCreatedAt(): int { return $this->createdAt; }
|
|
public function getUpdatedAt(): int { return $this->updatedAt; }
|
|
|
|
public function setFullName(string $fullName): self { $this->fullName = $fullName; $this->updatedAt = time(); return $this; }
|
|
public function setPhone(?string $phone): self { $this->phone = $phone; $this->updatedAt = time(); return $this; }
|
|
public function setJobTitle(?string $jobTitle): self { $this->jobTitle = $jobTitle; $this->updatedAt = time(); return $this; }
|
|
public function setAddress(?string $address): self { $this->address = $address; $this->updatedAt = time(); return $this; }
|
|
public function setNationalCode(?string $code): self { $this->nationalCode = $code; $this->updatedAt = time(); return $this; }
|
|
public function setActive(bool $active): self { $this->active = $active; $this->updatedAt = time(); return $this; }
|
|
public function setUser(?User $user): self { $this->user = $user; $this->updatedAt = time(); return $this; }
|
|
|
|
public function toggleActive(): self
|
|
{
|
|
$this->active = !$this->active;
|
|
$this->updatedAt = time();
|
|
return $this;
|
|
}
|
|
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'uuid' => $this->uuid,
|
|
'entity_type' => $this->entityType,
|
|
'entity_id' => $this->entityId,
|
|
'full_name' => $this->fullName,
|
|
'phone' => $this->phone,
|
|
'job_title' => $this->jobTitle,
|
|
'address' => $this->address,
|
|
'national_code' => $this->nationalCode,
|
|
'active' => $this->active,
|
|
'has_account' => $this->user !== null,
|
|
'user_uuid' => $this->user?->getUuid(),
|
|
'created_at' => $this->createdAt,
|
|
'updated_at' => $this->updatedAt,
|
|
];
|
|
}
|
|
}
|