mirror of
https://github.com/solidtime-io/solidtime.git
synced 2026-10-07 21:33:18 +01:00
47 lines
1.2 KiB
PHP
47 lines
1.2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Resources\V1\Goal;
|
|
|
|
use App\Http\Resources\PaginatedResourceCollection;
|
|
use App\Models\Goal;
|
|
use App\Service\Dto\GoalProgressDto;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Resources\Json\ResourceCollection;
|
|
|
|
class GoalCollection extends ResourceCollection implements PaginatedResourceCollection
|
|
{
|
|
/**
|
|
* @var array<string, GoalProgressDto>
|
|
*/
|
|
private array $progressByGoalId;
|
|
|
|
/**
|
|
* @param array<string, GoalProgressDto> $progressByGoalId
|
|
*/
|
|
public function __construct($resource, array $progressByGoalId)
|
|
{
|
|
parent::__construct($resource);
|
|
$this->progressByGoalId = $progressByGoalId;
|
|
}
|
|
|
|
protected function collects(): ?string
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Transform the resource collection into an array.
|
|
*
|
|
* @return array<array<string, string|bool|int|null|array<string, string|bool|int|null|array<int, string>>>>
|
|
*/
|
|
public function toArray(Request $request): array
|
|
{
|
|
return $this->collection->map(function (Goal $goal) use ($request): array {
|
|
return (new GoalResource($goal, $this->progressByGoalId[$goal->getKey()]))
|
|
->toArray($request);
|
|
})->all();
|
|
}
|
|
}
|