src/Controller/SitemapController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Events;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. class SitemapController extends AbstractController
  9. {
  10.     /**
  11.      * @Route("/sitemap.xml", name="app_sitemap", requirements={"_format"="xml"})
  12.      */
  13.     public function getSitemap(Request $request): Response
  14.     {
  15.         $urls = [];
  16.         $hostname $request->getHost();
  17.         $scheme $request->getScheme();
  18.         $urls[] = [
  19.             'loc' => $this->get('router')->generate('home'),
  20.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  21.             'changefreq' => 'daily',
  22.             'priority' => '0.9',
  23.         ];
  24.         $urls[] = [
  25.             'loc' => $this->get('router')->generate('hirek'),
  26.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  27.             'changefreq' => 'weekly',
  28.             'priority' => '0.5',
  29.         ];
  30.         $urls[] = [
  31.             'loc' => $this->get('router')->generate('istentisztelet'),
  32.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  33.             'changefreq' => 'weekly',
  34.             'priority' => '0.9',
  35.         ];
  36.         $istentiszteletek_results $this->getDoctrine()->getRepository(Events::class)->getLastEvents(250);
  37.         $istentisztelet_cities = [];
  38.         foreach ($istentiszteletek_results as $index => $istentisztelet) {
  39.             if ($istentisztelet->getEventType()->getId() == 2) {
  40.                 $istentisztelet_cities[$istentisztelet->getCityId()->getName()] = 1;
  41.             }
  42.         }
  43.         foreach (array_keys($istentisztelet_cities) as $city) {
  44.             $urls[] = [
  45.                 'loc' => $this->get('router')->generate('istentisztelet', ['varos' => $city]),
  46.                 'lastmod' => date('Y-m-d\TH:i:s\Z'),
  47.                 'changefreq' => 'weekly',
  48.                 'priority' => '0.9',
  49.             ];
  50.         }
  51.         $urls[] = [
  52.             'loc' => $this->get('router')->generate('bemutatkozas'),
  53.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  54.             'changefreq' => 'weekly',
  55.             'priority' => '0.9',
  56.         ];
  57.         $urls[] = [
  58.             'loc' => $this->get('router')->generate('kapcsolat'),
  59.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  60.             'changefreq' => 'weekly',
  61.             'priority' => '0.9',
  62.         ];
  63.         $urls[] = [
  64.             'loc' => $this->get('router')->generate('adatvedelem'),
  65.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  66.             'changefreq' => 'monthly',
  67.             'priority' => '0.5',
  68.         ];
  69.         $urls[] = [
  70.             'loc' => $this->get('router')->generate('impressum'),
  71.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  72.             'changefreq' => 'monthly',
  73.             'priority' => '0.9',
  74.         ];
  75.         $urls[] = [
  76.             'loc' => $this->get('router')->generate('napiahitatok'),
  77.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  78.             'changefreq' => 'monthly',
  79.             'priority' => '0.5',
  80.         ];
  81.         $urls[] = [
  82.             'loc' => $this->get('router')->generate('galleries'),
  83.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  84.             'changefreq' => 'monthly',
  85.             'priority' => '0.5',
  86.         ];
  87.         $urls[] = [
  88.             'loc' => $this->get('router')->generate('mediatar'),
  89.             'lastmod' => date('Y-m-d\TH:i:s\Z'),
  90.             'changefreq' => 'monthly',
  91.             'priority' => '0.5',
  92.         ];
  93.         $galleries_records $this->getDoctrine()->getRepository(Events::class)->getAllGalleries();
  94.         $galleries = [];
  95.         foreach ($galleries_records as $item) {
  96.             $galleries[$item->getId()] = 1;
  97.         }
  98.         foreach(array_keys($galleries) as $key) {
  99.             $urls[] = [
  100.                 'loc' => $this->get('router')->generate('gallery_show', ['id' => $key]),
  101.                 'lastmod' => date('Y-m-d\TH:i:s\Z'),
  102.                 'changefreq' => 'weekly',
  103.                 'priority' => '0.9',
  104.             ];
  105.         }
  106.         $response $this->render('sitemap\sitemap.xml.twig', [
  107.             'urls' => $urls,
  108.             'hostname' => $hostname,
  109.             'scheme' => $scheme,
  110.         ]);
  111.         $response->headers->set('Content-Type''xml');
  112.         return $response;
  113.     }
  114.     /**
  115.      * @Route("/sitemap.xsl", name="app_sitemap_xsl", requirements={"_format"="xml"})
  116.      */
  117.     public function getXsl(Request $request)
  118.     {
  119.         $response $this->render('sitemap\sitemap.xsl.twig', []);
  120.         $response->headers->set('Content-Type''xml');
  121.         return $response;
  122.     }
  123. }