src/Controller/Api/Banner/V1/CpcViewController.php line 32

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Api\Banner\V1;
  3. use App\Controller\Api\ApiInterface;
  4. use App\Service\TourCpcBanner;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use App\Service\FlightCpcBanner;
  10. class CpcViewController extends AbstractController implements ApiInterface
  11. {
  12.     private $flightCpcBanner;
  13.     private $tourCpcBanner;
  14.     public function __construct(FlightCpcBanner $flightCpcBanner,TourCpcBanner $tourCpcBanner)
  15.     {
  16.         $this->flightCpcBanner $flightCpcBanner;
  17.         $this->tourCpcBanner $tourCpcBanner;
  18.     }
  19.     /**
  20.      * @param Request $request
  21.      * @return Response
  22.      * @Route("api/banner/v1/cpc",name="api.banner.v1.cpc",methods={"GET"})
  23.      */
  24.     public function index(Request $request): Response
  25.     {
  26.         $cors = ['Access-Control-Allow-Origin'=>'*','Access-Control-Allow-Methods'=>'GET, POST, PATCH, PUT, DELETE, OPTIONS','Access-Control-Allow-Headers'=>'*','X-Robots-Tag'=>'noindex'];
  27.     if($request->get('prod') == 'flight'){
  28.             $banner $this->flightCpcBanner;
  29.             $availableBanner $banner->getBanner($request->get('dim'),$request->get('zone'),$request->get('origin'),$request->get('destination'),$request->get('platform'));
  30.             if(!empty($availableBanner)) {
  31.                 return $this->json(['status' => "success"'data' => ['image' => $availableBanner['file'], 'link' => $_ENV['BASE_URL'] . 'api/banner/v1/click/' $availableBanner['uid']]],200,$cors);
  32.             }else{
  33.                 return $this->json(['status'=>"success","data"=>null],200,$cors);
  34.             }
  35.         }else if($request->get('prod') == 'tour'){
  36.             $banner $this->tourCpcBanner;
  37.             $availableBanner $banner->getBanner($request->get('dim'),$request->get('zone'),$request->get('origin'),$request->get('destination'),$request->get('platform'));
  38.             if(!empty($availableBanner)) {
  39.             return $this->json(['status'=>"success",'data'=>['image'=>$availableBanner['file'],'link'=>$_ENV['BASE_URL'].'api/banner/v1/click/'.$availableBanner['uid']]],200,$cors);
  40.             }else{
  41.                 return $this->json(['status'=>"success","data"=>null],200,$cors);
  42.             }
  43.         }
  44.     }
  45. }