src/Modules/OnlineService/Modules/OnlineService/Controller/OnlineServiceController.php line 59

  1. <?php
  2. namespace App\Modules\OnlineService\Modules\OnlineService\Controller;
  3. use Symfony\Component\HttpFoundation\Request;
  4. use Knp\Component\Pager\PaginatorInterface;
  5. use App\Common\Modules\Payment\Service\PaymentService as CommonPaymentService;
  6. use App\Modules\OnlineService\Controller\BaseController;
  7. use App\Modules\OnlineService\Modules\OnlineService\Service\OnlineServiceService;
  8. use App\Modules\OnlineService\Modules\OnlineService\Service\OnlineServiceRepositoryService;
  9. class OnlineServiceController extends BaseController
  10. {
  11.     const PAGE_SIZE 12;
  12.     private $_paginator;
  13.     private $_commonPaymentService;
  14.     private $_onlineServiceService;
  15.     private $_onlineServiceRepositoryService;
  16.     
  17.     public function __construct(
  18.             PaginatorInterface $paginator,
  19.             CommonPaymentService $commonPaymentService,
  20.             OnlineServiceService $onlineServiceService,
  21.             OnlineServiceRepositoryService $onlineServiceRepositoryService)
  22.     {
  23.         $this->_paginator $paginator;
  24.         $this->_commonPaymentService $commonPaymentService;
  25.         $this->_onlineServiceService $onlineServiceService;
  26.         $this->_onlineServiceRepositoryService $onlineServiceRepositoryService;
  27.     }
  28.     
  29.     public function list(Request $request)
  30.     {
  31.         $noActivePaymentMethod = !$this->_commonPaymentService->getFirstActivePaymentMethod(nullfalse);
  32.         
  33.         if (!$noActivePaymentMethod)
  34.         {
  35.             $pagination $this->_paginator->paginate(
  36.                 $this->_onlineServiceRepositoryService->getQueryBuilder()->getQuery(),
  37.                 $request->query->getInt('page'1),
  38.                 self::PAGE_SIZE,
  39.                 array('defaultSortFieldName' => 't.name''defaultSortDirection' => 'asc')
  40.             );
  41.             $onlineServices = array();
  42.             foreach($pagination as $onlineService)
  43.                 $onlineServices[] = $this->_onlineServiceService->getDetails($onlineService);
  44.         }
  45.         
  46.         return $this->render('Modules/OnlineService/Modules/OnlineService/Templates/OnlineService/list.html.twig', array(
  47.                 'pagination' => $pagination ?? null,
  48.                 'onlineServices' => $onlineServices ?? null,
  49.                 'noActivePaymentMethod' => $noActivePaymentMethod
  50.             ));        
  51.     }
  52.     
  53.     public function details($id)
  54.     {
  55.         $onlineService $this->_onlineServiceRepositoryService->find($id);
  56.         
  57.         if (!$onlineService)
  58.             throw $this->createNotFoundException();
  59.         
  60.         return $this->render('Modules/OnlineService/Modules/OnlineService/Templates/OnlineService/details.html.twig', array(
  61.                 'data' => $this->_onlineServiceService->getDetails($onlineService),
  62.                 'returnUrl' => $this->getReturnUrl($this->generateUrl('online_service_service_list'))
  63.             ));
  64.     }
  65. }