| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | declare(strict_types=1); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | namespace Setono\SyliusLagersystemPlugin\ViewRepository\Product; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | use Pagerfanta\Adapter\DoctrineORMAdapter; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | use Pagerfanta\Pagerfanta; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  | use Setono\SyliusLagersystemPlugin\Factory\PageViewFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | use Setono\SyliusLagersystemPlugin\Factory\Product\ProductVariantViewFactoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  | use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  | use Setono\SyliusLagersystemPlugin\Repository\ProductVariantRepositoryInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  | use Setono\SyliusLagersystemPlugin\View\PageView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  | use Webmozart\Assert\Assert; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | class ProductVariantViewRepository implements ProductVariantViewRepositoryInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |     /** @var ProductVariantRepositoryInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |     protected $productVariantRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |     /** @var PageViewFactoryInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     protected $pageViewFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |     /** @var ProductVariantViewFactoryInterface */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     protected $productVariantViewFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |         ProductVariantRepositoryInterface $productVariantRepository, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |         PageViewFactoryInterface $pageViewFactory, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |         ProductVariantViewFactoryInterface $productVariantViewFactory | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |         $this->productVariantRepository = $productVariantRepository; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |         $this->pageViewFactory = $pageViewFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         $this->productVariantViewFactory = $productVariantViewFactory; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 37 |  |  |     public function getAllPaginated(PaginatorDetails $paginatorDetails, ?string $localeCode): PageView | 
            
                                                                        
                            
            
                                    
            
            
                | 38 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 39 |  |  |         Assert::notNull($localeCode); | 
            
                                                                        
                            
            
                                    
            
            
                | 40 |  |  |         $queryBuilder = $this->productVariantRepository->createLagersystemListQueryBuilder($localeCode); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 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->productVariantViewFactory->create($currentPageResult, $localeCode); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |         return $pageView; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 53 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 54 |  |  |  |