*/ public array $templates = []; /** * @param list $steps Title and the step's own work type. */ public function addTemplate(int $id, string $name, int $workTypeId, int $serviceUnitId, array $steps, bool $active = true): void { $this->templates[$id] = new WorkflowTemplateDetails( $id, $name, $workTypeId, 'työtehtävä '.$workTypeId, $serviceUnitId, $active, array_map(fn (array $step): WorkflowStepSummary => new WorkflowStepSummary( $step[0], null, $step[1] ?? null, $step[1] ?? $workTypeId, 'työtehtävä '.($step[1] ?? $workTypeId), ), $steps), ); } public function all(): array { return array_values(array_map(fn (WorkflowTemplateDetails $template): WorkflowTemplateSummary => new WorkflowTemplateSummary( $template->id, $template->name, $template->workTypeId, $template->workTypeName, $template->serviceUnitId, 'yksikkö '.$template->serviceUnitId, $template->isActive, count($template->steps), ), $this->templates)); } public function find(int $id): ?WorkflowTemplateDetails { return $this->templates[$id] ?? null; } /** * Unit 9 plays the shared unit. */ public function activeFor(array $serviceUnitIds): array { return array_values(array_filter( $this->templates, fn (WorkflowTemplateDetails $template): bool => $template->isActive && (in_array($template->serviceUnitId, $serviceUnitIds, true) || $template->serviceUnitId === 9), )); } }