src/Controller/SiteMapController.php line 22

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\IndustrySolution;
  4. use App\Entity\Project;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use MLDev\BaseBundle\Entity\Page;
  7. use MLDev\CatalogBundle\Entity\Product;
  8. use MLDev\CatalogBundle\Entity\ProductItem;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  14. class SiteMapController extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/sitemap.xml", name="mldev-front-sitemap", defaults={"_format"="xml"})
  18.      */
  19.     public function sitemapAction(Request $requestEntityManagerInterface $entityManager): Response
  20.     {
  21.         $em $entityManager;
  22.         $urls = [];
  23.         $pageQuery $em->createQuery(
  24.             "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"
  25.         );
  26.         /** @var Page $value */
  27.         foreach ($pageQuery->getResult() as $value) {
  28.             $urls[] = [
  29.                 'loc' => $request->getSchemeAndHttpHost() . $value->getUri(),
  30.                 'lastmod' => $value->getUpdatedAt()->format('Y-m-d\TH:i:s+00:00'),
  31.                 'priority' => 1
  32.             ];
  33.         }
  34.         $catalogQuery $em->createQuery(
  35.             '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'
  36.         );
  37.         /** @var ProductItem $value */
  38.         foreach ($catalogQuery->getResult() as $value) {
  39.             $urls[] = [
  40.                 'loc' => $this->generateUrl('mldev-front-product-show', [
  41.                     'id' => $value->getId()
  42.                 ], UrlGeneratorInterface::ABSOLUTE_URL),
  43.                 'lastmod' => $value->getProduct()->getUpdatedAt()->format('Y-m-d\TH:i:s+00:00'),
  44.                 'priority' => 1
  45.             ];
  46.         }
  47.         /* $publicationQuery = $em->createQuery(
  48.             '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'
  49.         );
  50.         // @var Item $value
  51.         foreach ($publicationQuery->getResult() as $value) {
  52.             $urls[] = [
  53.                 'loc' => $this->generateUrl('mldev-front-publication-show', [
  54.                     'uri' => $value->getCategory()->getPage()->getRoute(),
  55.                     'alias' => $value->getAlias(),
  56.                     'id' => $value->getId()
  57.                 ], UrlGeneratorInterface::ABSOLUTE_URL),
  58.                 'lastmod' => $value->getUpdatedAt()->format('Y-m-d\TH:i:s+00:00'),
  59.                 'priority' => 1
  60.             ];
  61.         }
  62.         */
  63.         return $this->render('sitemap.xml.twig', [
  64.             'urls' => $urls,
  65.         ]);
  66.     }
  67. }