feat(services): match Figma خدمات page in settings shell + multi-staff
Render the clinic services page (sections → services) inside the settings sub-navigation shell (SettingsLayout, "خدمات" active) to match the Figma settings design. Restyle section cards to show the service count and a status toggle with edit/delete actions, and service cards with labelled price/duration and personnel chips. A service can now have multiple personnel: add an additive many-to-many ServiceItem↔ClinicStaff (staffMembers, EAGER) while keeping the legacy single `staff` column mirrored for backward compatibility. Endpoints accept `staff_uuids[]` (falling back to the legacy single `staff_uuid`) and return `staff_members[]`; the section list now reports `items_count`. Backfill-safe: pre-migration rows fall back to the single staff in toArray. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -4,6 +4,8 @@ namespace App\ClinicService\Entity;
|
||||
|
||||
use App\ClinicService\Repository\ServiceItemRepository;
|
||||
use App\Staff\Entity\ClinicStaff;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
|
||||
@@ -23,10 +25,21 @@ class ServiceItem
|
||||
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
|
||||
private ServiceSection $section;
|
||||
|
||||
// Legacy single-staff column, kept for backward compatibility with existing
|
||||
// consumers (reception/session). Mirrors the first entry of $staffMembers.
|
||||
#[ORM\ManyToOne(targetEntity: ClinicStaff::class)]
|
||||
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
|
||||
private ?ClinicStaff $staff = null;
|
||||
|
||||
/**
|
||||
* @var Collection<int, ClinicStaff> personnel assigned to this service.
|
||||
* EAGER so hydration always populates the typed property (avoids the
|
||||
* "accessed before initialization" pitfall on lazy typed collections).
|
||||
*/
|
||||
#[ORM\ManyToMany(targetEntity: ClinicStaff::class, fetch: 'EAGER')]
|
||||
#[ORM\JoinTable(name: 'service_item_staff')]
|
||||
private Collection $staffMembers;
|
||||
|
||||
#[ORM\Column(type: 'string', length: 200)]
|
||||
private string $name;
|
||||
|
||||
@@ -59,6 +72,7 @@ class ServiceItem
|
||||
$this->priceRials = $priceRials;
|
||||
$this->createdAt = time();
|
||||
$this->updatedAt = time();
|
||||
$this->staffMembers = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int { return $this->id; }
|
||||
@@ -75,6 +89,33 @@ class ServiceItem
|
||||
public function getUpdatedAt(): int { return $this->updatedAt; }
|
||||
|
||||
public function setStaff(?ClinicStaff $staff): self { $this->staff = $staff; $this->updatedAt = time(); return $this; }
|
||||
|
||||
/** @return Collection<int, ClinicStaff> */
|
||||
public function getStaffMembers(): Collection
|
||||
{
|
||||
// Doctrine hydrates without the constructor; guard the typed property.
|
||||
return $this->staffMembers ??= new ArrayCollection();
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the assigned personnel. Also mirrors the first member into the
|
||||
* legacy single {@see $staff} column so back-compat consumers keep working.
|
||||
*
|
||||
* @param ClinicStaff[] $members
|
||||
*/
|
||||
public function setStaffMembers(array $members): self
|
||||
{
|
||||
$collection = $this->getStaffMembers();
|
||||
$collection->clear();
|
||||
foreach ($members as $m) {
|
||||
if (!$collection->contains($m)) {
|
||||
$collection->add($m);
|
||||
}
|
||||
}
|
||||
$this->staff = $members[0] ?? null;
|
||||
$this->updatedAt = time();
|
||||
return $this;
|
||||
}
|
||||
public function setName(string $name): self { $this->name = $name; $this->updatedAt = time(); return $this; }
|
||||
public function setPriceRials(int $price): self { $this->priceRials = $price; $this->updatedAt = time(); return $this; }
|
||||
public function setActive(bool $active): self { $this->active = $active; $this->updatedAt = time(); return $this; }
|
||||
@@ -84,14 +125,26 @@ class ServiceItem
|
||||
|
||||
public function toArray(): array
|
||||
{
|
||||
// Prefer the multi-staff collection; fall back to the legacy single
|
||||
// staff so rows created before the migration still expose personnel.
|
||||
$members = array_values($this->getStaffMembers()->toArray());
|
||||
if (empty($members) && $this->staff !== null) {
|
||||
$members = [$this->staff];
|
||||
}
|
||||
$primary = $members[0] ?? null;
|
||||
|
||||
return [
|
||||
'uuid' => $this->uuid,
|
||||
'section_uuid' => $this->section->getUuid(),
|
||||
'staff_uuid' => $this->staff?->getUuid(),
|
||||
'staff_name' => $this->staff?->getFullName(),
|
||||
'staff' => $this->staff !== null
|
||||
? ['uuid' => $this->staff->getUuid(), 'full_name' => $this->staff->getFullName()]
|
||||
'staff_uuid' => $primary?->getUuid(),
|
||||
'staff_name' => $primary?->getFullName(),
|
||||
'staff' => $primary !== null
|
||||
? ['uuid' => $primary->getUuid(), 'full_name' => $primary->getFullName()]
|
||||
: null,
|
||||
'staff_members' => array_map(
|
||||
fn(ClinicStaff $s) => ['uuid' => $s->getUuid(), 'full_name' => $s->getFullName()],
|
||||
$members
|
||||
),
|
||||
'name' => $this->name,
|
||||
'price_rials' => $this->priceRials,
|
||||
'active' => $this->active,
|
||||
|
||||
Reference in New Issue
Block a user