<?php
namespace App\Controller\Api\Banner\V1;
use App\Controller\Api\ApiInterface;
use App\Service\TourCpcBanner;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Service\FlightCpcBanner;
class CpcViewController extends AbstractController implements ApiInterface
{
private $flightCpcBanner;
private $tourCpcBanner;
public function __construct(FlightCpcBanner $flightCpcBanner,TourCpcBanner $tourCpcBanner)
{
$this->flightCpcBanner = $flightCpcBanner;
$this->tourCpcBanner = $tourCpcBanner;
}
/**
* @param Request $request
* @return Response
* @Route("api/banner/v1/cpc",name="api.banner.v1.cpc",methods={"GET"})
*/
public function index(Request $request): Response
{
$cors = ['Access-Control-Allow-Origin'=>'*','Access-Control-Allow-Methods'=>'GET, POST, PATCH, PUT, DELETE, OPTIONS','Access-Control-Allow-Headers'=>'*','X-Robots-Tag'=>'noindex'];
if($request->get('prod') == 'flight'){
$banner = $this->flightCpcBanner;
$availableBanner = $banner->getBanner($request->get('dim'),$request->get('zone'),$request->get('origin'),$request->get('destination'),$request->get('platform'));
if(!empty($availableBanner)) {
return $this->json(['status' => "success", 'data' => ['image' => $availableBanner['file'], 'link' => $_ENV['BASE_URL'] . 'api/banner/v1/click/' . $availableBanner['uid']]],200,$cors);
}else{
return $this->json(['status'=>"success","data"=>null],200,$cors);
}
}else if($request->get('prod') == 'tour'){
$banner = $this->tourCpcBanner;
$availableBanner = $banner->getBanner($request->get('dim'),$request->get('zone'),$request->get('origin'),$request->get('destination'),$request->get('platform'));
if(!empty($availableBanner)) {
return $this->json(['status'=>"success",'data'=>['image'=>$availableBanner['file'],'link'=>$_ENV['BASE_URL'].'api/banner/v1/click/'.$availableBanner['uid']]],200,$cors);
}else{
return $this->json(['status'=>"success","data"=>null],200,$cors);
}
}
}
}