|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Setono\SyliusLagersystemPlugin\ViewRepository\Shipment; |
|
6
|
|
|
|
|
7
|
|
|
use Pagerfanta\Adapter\DoctrineORMAdapter; |
|
8
|
|
|
use Pagerfanta\Pagerfanta; |
|
9
|
|
|
use Setono\SyliusLagersystemPlugin\Factory\PageViewFactoryInterface; |
|
10
|
|
|
use Setono\SyliusLagersystemPlugin\Factory\Shipping\ShipmentViewFactoryInterface; |
|
11
|
|
|
use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails; |
|
12
|
|
|
use Setono\SyliusLagersystemPlugin\Repository\ShipmentRepositoryInterface; |
|
13
|
|
|
use Setono\SyliusLagersystemPlugin\View\PageView; |
|
14
|
|
|
use Webmozart\Assert\Assert; |
|
15
|
|
|
|
|
16
|
|
|
class ShipmentViewRepository implements ShipmentViewRepositoryInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** @var ShipmentRepositoryInterface */ |
|
19
|
|
|
protected $shipmentRepository; |
|
20
|
|
|
|
|
21
|
|
|
/** @var PageViewFactoryInterface */ |
|
22
|
|
|
protected $pageViewFactory; |
|
23
|
|
|
|
|
24
|
|
|
/** @var ShipmentViewFactoryInterface */ |
|
25
|
|
|
protected $shipmentViewFactory; |
|
26
|
|
|
|
|
27
|
|
|
public function __construct( |
|
28
|
|
|
ShipmentRepositoryInterface $shipmentRepository, |
|
29
|
|
|
PageViewFactoryInterface $pageViewFactory, |
|
30
|
|
|
ShipmentViewFactoryInterface $shipmentViewFactory |
|
31
|
|
|
) { |
|
32
|
|
|
$this->shipmentRepository = $shipmentRepository; |
|
33
|
|
|
$this->pageViewFactory = $pageViewFactory; |
|
34
|
|
|
$this->shipmentViewFactory = $shipmentViewFactory; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
public function getAllPaginated(PaginatorDetails $paginatorDetails, ?string $localeCode): PageView |
|
38
|
|
|
{ |
|
39
|
|
|
Assert::notNull($localeCode); |
|
40
|
|
|
$queryBuilder = $this->shipmentRepository->createLagersystemListQueryBuilder(); |
|
41
|
|
|
|
|
42
|
|
|
$pagerfanta = new Pagerfanta(new DoctrineORMAdapter($queryBuilder)); |
|
43
|
|
|
$pagerfanta->setMaxPerPage($paginatorDetails->limit()); |
|
44
|
|
|
$pagerfanta->setCurrentPage($paginatorDetails->page()); |
|
45
|
|
|
|
|
46
|
|
|
$pageView = $this->pageViewFactory->create($pagerfanta, $paginatorDetails->route(), $paginatorDetails->parameters()); |
|
47
|
|
|
foreach ($pagerfanta->getCurrentPageResults() as $currentPageResult) { |
|
48
|
|
|
$pageView->items[] = $this->shipmentViewFactory->create($currentPageResult, $localeCode); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $pageView; |
|
52
|
|
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|