<?php
namespace App\Controller\Front;
use App\Entity\Menu;
use App\Entity\Post;
use App\Entity\UrlRef;
use App\Entity\UrlPost;
use App\Entity\Category;
use App\Entity\Language;
use App\Entity\ListeRef;
use App\Entity\MediaCms;
use App\Entity\Secteurs;
use App\Entity\TypePost;
use App\Entity\Activites;
use App\Entity\ListeMenu;
use App\Service\BuildTree;
use App\Entity\CpPostField;
use App\Entity\PostArchive;
use App\Service\RenderBloc;
use Spatie\SchemaOrg\Graph;
use App\Entity\ParametreRef;
use App\Entity\PostCategory;
use App\Entity\ParametrePartenaires;
use App\Entity\ParametrePartenairesTranslation;
use App\Entity\Partenaires;
use App\Entity\PartenairesTranslation;
use App\Service\MetaService;
use Spatie\SchemaOrg\Schema;
use App\Entity\ModelGallerie;
use App\Entity\ParametreSite;
use App\Entity\ReseauSociaux;
use App\Service\MetaClePageRef;
use App\Service\FunctionService;
use App\Entity\ActiviteSecondaire;
use App\Service\MetaWithoutCategoryService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\JsonResponse;
use Leogout\Bundle\SeoBundle\Seo\Og\OgSeoGenerator;
use Symfony\Component\String\Slugger\SluggerInterface;
use Leogout\Bundle\SeoBundle\Seo\Basic\BasicSeoGenerator;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class PartenairesController extends AbstractController
{
public $basicSeo;
public $seo;
private $slugger;
private $projectDir;
private $metaService;
private $metaClePageRef;
private $renderBloc;
private $buildTree;
private $functionService;
private $metaPostService;
private $theme;
private $requestStack;
public function __construct(string $projectDir,string $theme,
BasicSeoGenerator $basicSeo,
OgSeoGenerator $seo,
RenderBloc $renderBloc,
SluggerInterface $slugger,
BuildTree $buildTree,
MetaService $metaService,
MetaWithoutCategoryService $metaPostService,
MetaClePageRef $metaClePageRef,
FunctionService $functionService,
RequestStack $requestStack){
$this->metaService = $metaService;
$this->metaPostService = $metaPostService;
$this->basicSeo = $basicSeo;
$this->seo = $seo;
$this->buildTree = $buildTree;
$this->slugger = $slugger;
$this->metaClePageRef = $metaClePageRef;
$this->functionService = $functionService;
$this->renderBloc = $renderBloc;
$this->projectDir = $projectDir;
$this->theme = $theme;
$this->requestStack = $requestStack;
}
/**
* @Route("/partenaires", name="page_partenaire",priority=10)
*/
public function PagePartenaires(Request $request)
{
$parametreSite = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
$param_partenaire = $this->getDoctrine()->getRepository(ParametrePartenaires::class)->findOneBy(['actif'=> true]);
$liste_partenaire_bo = $this->getDoctrine()->getRepository(Partenaires::class)->findBy(['actif'=> true]);
$client = HttpClient::create();
$request = $this->requestStack->getCurrentRequest();
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$partenaires_invitations = null;
try {
$response_api = $client->request('GET',
$parametreSite->getDomainApiHrz().'/api/custom/all-partners-domain',
[ 'headers' => ['Accept' => 'application/json'],
'query' => [
'domain' => $baseurl,
'token' => $parametreSite->getTokenApiHrz(),
],
]);
if ($response_api->getStatusCode() === 200) {
$partenaires_invitations = $response_api->toArray()['data'];
}
} catch (\Throwable $th) {
//throw $th;
//dump($th);
}
/* if(!$partenaires_invitations){
throw new NotFoundHttpException('Sorry not existing!');
} */
return $this->render('front/'.$this->theme.'/page_partenaires.html.twig',[
'parametre'=> $param_partenaire,
'liste_partenaire' => $liste_partenaire_bo,
'liste_partenaire_invitations' => $partenaires_invitations,
'baseurl' => $baseurl
]);
}
/**
* @Route("/partenaire/{slug}", name="page_detail_partenaire",priority=10)
*/
public function DetailsPartenaires(Request $request,$slug = null)
{
$api = $request->query->get('p');
if($api == "hr"){
// Api
$parametreSite = $this->getDoctrine()->getRepository(ParametreSite::class)->findOneBy([],['id'=> 'ASC']);
$client = HttpClient::create();
$request = $this->requestStack->getCurrentRequest();
$baseurl = $request->getScheme() . '://' . $request->getHttpHost() . $request->getBasePath();
$partenaire_api = null;
$partenaire = [];
try {
$response_api = $client->request('GET',
$parametreSite->getDomainApiHrz().'/api/custom/partner-detail',
[ 'headers' => ['Accept' => 'application/json'],
'query' => [
'domain' => $baseurl,
'slug' => $slug,
'token' => $parametreSite->getTokenApiHrz(),
],
]);
if ($response_api->getStatusCode() === 200) {
$partenaire_api = $response_api->toArray()['data'];
}
} catch (\Throwable $th) {
//throw $th;
//dump($th);
}
$titre = "";
$texte = "";
$image = "";
$titre = ($partenaire_api['domaine_sender'] == $baseurl) ? $partenaire_api['titre_reciver'] : $titre;
$titre = ($partenaire_api['domaine_reciver'] == $baseurl) ? $partenaire_api['titre_sender'] : $titre;
$texte = ($partenaire_api['domaine_sender'] == $baseurl) ? $partenaire_api['texte_reciver'] : $texte;
$texte = ($partenaire_api['domaine_reciver'] == $baseurl) ? $partenaire_api['texte_sender'] : $texte;
$image = ($partenaire_api['domaine_sender'] == $baseurl) ? $partenaire_api['image_reciver'] : $image;
$image = ($partenaire_api['domaine_reciver'] == $baseurl) ? $partenaire_api['image_sender'] : $image;
$partenaire = [
'titre' => $titre,
'text' => $texte,
'image' => $image
];
}else{
$partenaire = $this->getDoctrine()->getRepository(Partenaires::class)->findBySlug($slug);
}
if(!$partenaire){
throw new NotFoundHttpException('Sorry not existing!');
}
return $this->render('front/'.$this->theme.'/page_detail_partenaires.html.twig',[
'partenaire'=> $partenaire,
]);
}
}
?>