Add catalog module for service units, services and work types
Phase 1, item 3: the hierarchy customer jobs, tasks and time entries will refer to. - New Catalog module: service unit > optional service > work type. Names are unique per level (case-insensitive); items are never deleted, only deactivated, and foreign keys restrict deletes. - Pohjatiedot page (/catalog, admins and management): add, rename, reorder with move up/down buttons (keyboard-friendly, focus kept and announced) and an "in use" checkbox per row. Work types can move to another service of the same unit. - A migration inserts the starting catalog from the specification when the tables are empty, so every installation has it. - CatalogQueries gives other modules the active service units and the work types of chosen units plus the shared ones. - Spec and CLAUDE.md updated. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Modules\Catalog\Domain\Entities;
|
||||
|
||||
use App\Modules\Catalog\Domain\ValueObjects\CatalogName;
|
||||
|
||||
/**
|
||||
* What service units, services and work types share: a name that is unique
|
||||
* among its siblings, an order among them, and an active flag. Items are
|
||||
* never deleted, only deactivated, so old references keep working.
|
||||
*/
|
||||
abstract class CatalogItem
|
||||
{
|
||||
public function __construct(
|
||||
protected ?int $id,
|
||||
protected CatalogName $name,
|
||||
protected bool $active,
|
||||
protected int $sortOrder,
|
||||
) {}
|
||||
|
||||
public function id(): ?int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function name(): CatalogName
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
public function isActive(): bool
|
||||
{
|
||||
return $this->active;
|
||||
}
|
||||
|
||||
public function sortOrder(): int
|
||||
{
|
||||
return $this->sortOrder;
|
||||
}
|
||||
|
||||
public function rename(CatalogName $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
public function activate(): void
|
||||
{
|
||||
$this->active = true;
|
||||
}
|
||||
|
||||
public function deactivate(): void
|
||||
{
|
||||
$this->active = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Swaps places with a sibling.
|
||||
*/
|
||||
public function swapOrderWith(self $sibling): void
|
||||
{
|
||||
[$this->sortOrder, $sibling->sortOrder] = [$sibling->sortOrder, $this->sortOrder];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user