<?php
namespace App\Controller;
use App\Entity\IndustrySolution;
use App\Entity\Project;
use Doctrine\ORM\EntityManagerInterface;
use MLDev\BaseBundle\Entity\Page;
use MLDev\CatalogBundle\Entity\Product;
use MLDev\CatalogBundle\Entity\ProductItem;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
class SiteMapController extends AbstractController
{
/**
* @Route("/sitemap.xml", name="mldev-front-sitemap", defaults={"_format"="xml"})
*/
public function sitemapAction(Request $request, EntityManagerInterface $entityManager): Response
{
$em = $entityManager;
$urls = [];
$pageQuery = $em->createQuery(
"select P from MLDevBaseBundle:Page P where P.parent is not null and P.type = 'LOCAL' and P.isActive = true group by P.id order by P.lft asc, P.priority asc"
);
/** @var Page $value */
foreach ($pageQuery->getResult() as $value) {
$urls[] = [
'loc' => $request->getSchemeAndHttpHost() . $value->getUri(),
'lastmod' => $value->getUpdatedAt()->format('Y-m-d\TH:i:s+00:00'),
'priority' => 1
];
}
$catalogQuery = $em->createQuery(
'select PI from MLDevCatalogBundle:ProductItem PI JOIN PI.product P JOIN P.pages PG where PG.isActive = true and P.isActive = true and PI.isActive = true order by P.priority asc, P.id asc'
);
/** @var ProductItem $value */
foreach ($catalogQuery->getResult() as $value) {
$urls[] = [
'loc' => $this->generateUrl('mldev-front-product-show', [
'id' => $value->getId()
], UrlGeneratorInterface::ABSOLUTE_URL),
'lastmod' => $value->getProduct()->getUpdatedAt()->format('Y-m-d\TH:i:s+00:00'),
'priority' => 1
];
}
/* $publicationQuery = $em->createQuery(
'select I from MLDevPublicationBundle:Item I JOIN I.category C JOIN C.page P where P.id is not null and P.isActive = true and I.isActive = true order by I.priority asc, I.id asc'
);
// @var Item $value
foreach ($publicationQuery->getResult() as $value) {
$urls[] = [
'loc' => $this->generateUrl('mldev-front-publication-show', [
'uri' => $value->getCategory()->getPage()->getRoute(),
'alias' => $value->getAlias(),
'id' => $value->getId()
], UrlGeneratorInterface::ABSOLUTE_URL),
'lastmod' => $value->getUpdatedAt()->format('Y-m-d\TH:i:s+00:00'),
'priority' => 1
];
}
*/
return $this->render('sitemap.xml.twig', [
'urls' => $urls,
]);
}
}