<?php
namespace App\Controller;
use App\Service\Akimedia;
use http\Env\Response;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use GuzzleHttp\Client;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Contracts\Translation\TranslatorInterface;
use Carbon\Carbon;
class CentresController extends FrontendController
{
/**
* @Template
* @param Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function getCentresByProvincesAction(Request $request)
{
$session = $request->getSession();
$token = $session->get('akimedia-token');
if(!$token){
$token = Akimedia::login();
$session->set('akimedia-token', $token);
}
$allsites = Akimedia::getSitesByProvinces($request);
foreach ($allsites as $prov => &$tabs){
foreach ($tabs as &$val){
$availabilities = Akimedia::getSiteAvailabilities($request, $val["id"]);
$info = Akimedia::getSiteInfos($request, $val["id"]);
$horaires = $info["days"];
$val['horaires'] = $horaires;
$val['availibilities'] = $availabilities;
$val['infos'] = $info;
$val['id_akimedia'] = $val["id"];
}
}
// Ajout d'un jour pour avoir les dates du lundi si on est dimanche
$now = Carbon::now()->addDay();
$date['weekStartDate'] = $now->startOfWeek()->format('d/m/Y');
$date['weekEndDate'] = $now->endOfWeek()->format('d/m/Y');
return $this->render('centres/list-provinces-akimedia.html.twig',[
"type" => "akimedia",
"provinces" => $allsites,
"date" => $date
]);
//gestion guzzle
/*$client = new Client();
$response = $client->request('POST', "https://www.donneurdesang.be/". $request->getLocale() ."/api/centres-by-provinces", [
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded',
]
]);
$results = json_decode($response->getBody(), true);
$centres = $results;
return $this->render('centres/list-provinces.html.twig',[
"type" => "dds",
"centres" => $centres
]);*/
}
/**
* @Route("/api/{lang}/sendemailinfo", name="apiEmailData")
*
*/
public function plasmaApiCentresHorairesAction(Request $request, TranslatorInterface $translation) {
$data = json_decode(str_replace("--quote--", "'", $request->get("data")), true);
$email = $request->get("email");
$type = $request->get("type");
$locale = $request->get("lang");
$params = [];
foreach($data as $k => $v) {
$params[$k] = $v;
}
$params['type'] = $type;
$params['email'] = $email;
$mail = new \Pimcore\Mail();
$mail->addTo($email);
$mail->setParams($params);
$mail->setDocument('/emails/'.$locale.'/send-centre-infos');
$mail->send();
$response = array('type' => 'success', 'msg' => $translation->trans('Les informations vous ont bien été envoyée !'));
return new JsonResponse($response);
}
}