2026-09-29 15:29:43 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Queries\Slides;
|
|
|
|
|
|
|
|
|
|
use App\Contracts\Query;
|
2026-09-29 16:59:07 +02:00
|
|
|
use App\Contracts\QueryInput;
|
2026-09-29 15:29:43 +02:00
|
|
|
use App\Dto\SlideDto;
|
|
|
|
|
use App\Models\Slide;
|
|
|
|
|
use App\Services\DataTableService;
|
|
|
|
|
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
2026-10-02 19:44:29 +02:00
|
|
|
use Illuminate\Support\Facades\Date;
|
2026-09-29 16:59:07 +02:00
|
|
|
use Webmozart\Assert\Assert;
|
2026-09-29 15:29:43 +02:00
|
|
|
|
|
|
|
|
/**
|
2026-09-29 16:59:07 +02:00
|
|
|
* phpcs:disable Generic.Files.LineLength.TooLong
|
|
|
|
|
*
|
|
|
|
|
* @implements \App\Contracts\Query<\App\Queries\Slides\GetPaginatedSlidesQueryInput, \Illuminate\Contracts\Pagination\LengthAwarePaginator<int, \App\Dto\SlideDto>>
|
2026-09-29 15:29:43 +02:00
|
|
|
*/
|
|
|
|
|
final readonly class GetPaginatedSlidesQuery implements Query
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
|
|
|
|
private DataTableService $dataTable,
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
public function __invoke(QueryInput $input): LengthAwarePaginator
|
2026-09-29 15:29:43 +02:00
|
|
|
{
|
2026-09-29 16:59:07 +02:00
|
|
|
Assert::isAOf(
|
|
|
|
|
$input,
|
|
|
|
|
GetPaginatedSlidesQueryInput::class,
|
|
|
|
|
);
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
$query = Slide::query();
|
|
|
|
|
|
2026-09-30 16:49:26 +02:00
|
|
|
if ($input->publishedOnly) {
|
2026-10-02 19:44:29 +02:00
|
|
|
$now = Date::now();
|
|
|
|
|
$query->where(function ($q) use ($now): void {
|
|
|
|
|
$q->whereNull('date_start')
|
|
|
|
|
->orWhere('date_start', '<=', $now);
|
|
|
|
|
})->where(function ($q) use ($now): void {
|
|
|
|
|
$q->whereNull('date_end')
|
|
|
|
|
->orWhere('date_end', '>=', $now);
|
|
|
|
|
});
|
2026-09-30 16:49:26 +02:00
|
|
|
}
|
|
|
|
|
|
2026-10-02 12:14:48 +02:00
|
|
|
if ($input->forConnectedCustomers === false) {
|
2026-09-30 16:49:26 +02:00
|
|
|
$query->where('connected', false);
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-29 15:29:43 +02:00
|
|
|
$this->dataTable->sortQuery(Slide::class, $query);
|
|
|
|
|
|
2026-09-29 16:59:07 +02:00
|
|
|
$paginator = $this->dataTable->paginateQuery($query, $input->pagination);
|
2026-09-29 15:29:43 +02:00
|
|
|
|
|
|
|
|
return $paginator->through(fn (Slide $slide): SlideDto => SlideDto::fromModel($slide));
|
|
|
|
|
}
|
|
|
|
|
}
|