<?php
namespace App\Controller\Frontend;
use Symfony\Component\HttpFoundation\Request;
use FOS\RestBundle\Controller\Annotations as Rest;
use App\Misc\ImageUrlHelper;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Symfony\Component\Routing\Annotation\Route;
class AlumniController extends BaseFrontendController
{
/**
* @Route("/{_locale}/alumni", requirements={"_locale": "en|fr"}, defaults={"_locale"="fr"}, name="alumni_index")
*/
public function index(
UrlGeneratorInterface $urlGenerator,
ImageUrlHelper $imageUrlHelper,
TranslatorInterface $translator
) {
$requestData['limit'] = 10000;
$alumni = $this->currentService->getListAll($requestData);
$siteName = $translator->trans('siteName');
$metaTitle = $translator->trans(
'alumni.title',
[
'%siteName%' => $siteName
]
);
$this->addTitle($metaTitle);
$this->setDescription($translator->trans(
'alumni.desc',
[
'%siteName%' => $siteName
]
));
// BreadcrumbSnippet
$breadcrumbSnippet = [
'@context' => 'https://schema.org',
'@type' => 'BreadcrumbList',
'itemListElement' => [
[
'@type' => 'ListItem',
'position' => 1,
'name' => $siteName,
'item' => $urlGenerator->generate(
'home',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
],
[
'@type' => 'ListItem',
'position' => 2,
'name' => $metaTitle,
],
]
];
// Article snippet
$pageModifyDate = new \DateTime('first day of this month');
$newsArticleRichSnippet = [
'@context' => 'https://schema.org',
'@type' => 'NewsArticle',
'headline' => $metaTitle,
'image' => [
$imageUrlHelper->getNewsImageUrl()
],
'datePublished' => '2022-09-01 00:00:00',
'dateModified' => $pageModifyDate->format('Y-m-d') . ' 00:00:00',
'author' => [
'@type' => 'Organization',
'name' => 'Estiam France',
'url' => $urlGenerator->generate(
'home',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
],
];
$data['alumni'] = $alumni;
$data['richSnippets'] = [];
$data['richSnippets'][] = $breadcrumbSnippet;
$data['richSnippets'][] = $newsArticleRichSnippet;
return $this->render(
'alumni/index.html.twig',
$data
);
}
/**
* @Rest\Get("/{_locale}/{id}-{slug}", requirements={"_locale": "en|fr", "slug": "[a-zA-Z0-9\-]+", "id": "[0-9]+"}, defaults={"_locale"="fr"}, name="alumni_detail")
*/
public function detail(
$slug,
Request $request,
UrlGeneratorInterface $urlGenerator,
ImageUrlHelper $imageUrlHelper
) {
$alumni = $this->currentService->getBySlug($slug, $request);
if (!$alumni) throw $this->createNotFoundException('');
$siteName = $this->getParameter('site_name');
$this->addTitle($alumni->seoTitle);
$this->setDescription($alumni->seoDescription);
// Breadcrumb snippet
$breadcrumbSnippet = [
'@context' => 'https://schema.org',
'@type' => 'BreadcrumbList',
'itemListElement' => [
[
'@type' => 'ListItem',
'position' => 1,
'name' => $alumni->seoTitle,
'item' => $urlGenerator->generate(
'home',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
],
[
'@type' => 'ListItem',
'position' => 2,
'name' => $siteName
]
]
];
// NewsArticle richSnippet ------------------------------------
$newsArticleRichSnippet = [
'@context' => 'https://schema.org',
'@type' => 'NewsArticle',
'headline' => $alumni->seoTitle,
'image' => [
$alumni->photo ?? $imageUrlHelper->getLogoUrl()
],
'datePublished' => $alumni->createdDate,
'dateModified' => $alumni->updatedDate,
'author' => [
'@type' => 'Organization',
'name' => $siteName,
'url' => $urlGenerator->generate(
'home',
[],
UrlGeneratorInterface::ABSOLUTE_URL
)
],
];
$data['alumni'] = $alumni;
$data['richSnippets'] = [];
$data['richSnippets'][] = $breadcrumbSnippet;
$data['richSnippets'][] = $newsArticleRichSnippet;
return $this->render(
'alumni/detail.html.twig',
$data
);
}
}