src/Bidcoz/Bundle/FrontendBundle/Controller/Auction/AuctionController.php line 27

Open in your IDE?
  1. <?php
  2. namespace Bidcoz\Bundle\FrontendBundle\Controller\Auction;
  3. use Bidcoz\Bundle\CoreBundle\Controller\CoreController;
  4. use Bidcoz\Bundle\CoreBundle\Entity\Auction\Auction;
  5. use Bidcoz\Bundle\CoreBundle\Entity\Campaign;
  6. use Bidcoz\Bundle\CoreBundle\Entity\Organization;
  7. use Bidcoz\Bundle\FrontendBundle\Filter\ItemFilterType;
  8. use Bidcoz\Bundle\FrontendBundle\Filter\Order\ItemOrderType;
  9. use Doctrine\ORM\QueryBuilder;
  10. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  11. use Symfony\Component\Form\Form;
  12. use Symfony\Component\HttpFoundation\Request;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. /**
  15.  * @Route("/{orgSlug}/{campaignSlug}/auction")
  16.  * @IsGranted("VIEW", subject="organization")
  17.  * @IsGranted("FRONT_END", subject="campaign")
  18.  */
  19. class AuctionController extends CoreController
  20. {
  21.     /**
  22.      * @Route("/list", name="auction_catalog")
  23.      */
  24.     public function catalogAction(Request $requestOrganization $organizationCampaign $campaignAuction $auction)
  25.     {
  26.         $qb $this->getRepository('Auction\Item')->getAuctionQueryBuilder($auctiontruefalse);
  27.         $filterForm $this->getItemFilterForm($auction);
  28.         $hasFilter  $this->applyFilters($request$filterForm$qb);
  29.         $orderForm $this->getItemOrderForm($auction);
  30.         $hasOrder  $this->applyOrder($request$orderForm$qb);
  31.         $items $this->getPagination($qb);
  32.         return $this->render('@BidcozFrontend/Auction/catalog.html.twig', [
  33.             'type'         => 'auction',
  34.             'title'        => 'Auction Catalog',
  35.             'organization' => $organization,
  36.             'campaign'     => $campaign,
  37.             'auction'      => $auction,
  38.             'filterForm'   => $filterForm->createView(),
  39.             'orderForm'    => $orderForm->createView(),
  40.             'items'        => $items,
  41.             'hasFilter'    => $hasFilter || $hasOrder,
  42.             'requireCC'    => !$this->isGranted('WITH_CC'$campaign),
  43.         ]);
  44.     }
  45.     protected function getItemFilterForm(Auction $auction)
  46.     {
  47.         return $this->createForm(ItemFilterType::class, null, [
  48.             'auction'            => $auction,
  49.             'permission_manager' => $this->getAuctionPermissionManager(),
  50.         ]);
  51.     }
  52.     protected function getItemOrderForm(Auction $auction)
  53.     {
  54.         return $this->createForm(ItemOrderType::class);
  55.     }
  56.     protected function applyOrder(Request $requestForm $orderFormQueryBuilder $qb)
  57.     {
  58.         try {
  59.             if ($request->query->has($orderForm->getName())) {
  60.                 $orderForm->submit($request->query->get($orderForm->getName()));
  61.                 $sortKey        $orderForm->get('order')->getData();
  62.                 $orderQuery     ItemOrderType::getMap()[$sortKey];
  63.                 $fieldsAndOrder explode(','$orderQuery);
  64.                 foreach ($fieldsAndOrder as $idx => $fieldAndOrder) {
  65.                     [$field$order] = explode(':'$fieldAndOrder);
  66.                     // If sorting by bid count, remove fixed priced items
  67.                     if ('bidCount' === $field) {
  68.                         $qb->andWhere($qb->expr()->neq('i.saleType'':fixed_price_sale_type'));
  69.                     }
  70.                     if (=== $idx) {
  71.                         $qb->orderBy($field$order);
  72.                     } else {
  73.                         $qb->addorderBy($field$order);
  74.                     }
  75.                 }
  76.                 return true;
  77.             }
  78.         } catch (\Exception $e) {
  79.         }
  80.         return false;
  81.     }
  82. }