50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Modules\Catalog\Application\DTOs;
|
|
|
|
/**
|
|
* A step of a workflow template as entered. A null work type means the
|
|
* template's own. Materials are the step's default materials: a stock item
|
|
* id and the quantity as typed ("2,5").
|
|
*/
|
|
final readonly class WorkflowStepData
|
|
{
|
|
/**
|
|
* @param list<array{stockItemId: int, quantity: string}> $materials
|
|
*/
|
|
public function __construct(
|
|
public string $title,
|
|
public ?string $description = null,
|
|
public ?int $workTypeId = null,
|
|
public array $materials = [],
|
|
) {}
|
|
|
|
/**
|
|
* Rows without an item are left out.
|
|
*
|
|
* @param array{title?: string, description?: string|null, work_type_id?: int|string|null, materials?: list<array{stock_item_id?: int|string|null, quantity?: string|null}>} $input
|
|
*/
|
|
public static function fromArray(array $input): self
|
|
{
|
|
$workTypeId = $input['work_type_id'] ?? null;
|
|
$materials = [];
|
|
|
|
foreach ($input['materials'] ?? [] as $material) {
|
|
$itemId = $material['stock_item_id'] ?? null;
|
|
|
|
if ($itemId !== null && $itemId !== '') {
|
|
$materials[] = ['stockItemId' => (int) $itemId, 'quantity' => (string) ($material['quantity'] ?? '')];
|
|
}
|
|
}
|
|
|
|
return new self(
|
|
(string) ($input['title'] ?? ''),
|
|
$input['description'] ?? null,
|
|
$workTypeId === null || $workTypeId === '' ? null : (int) $workTypeId,
|
|
$materials,
|
|
);
|
|
}
|
|
}
|