src/FoundersBundle/Controller/SiteMapController.php line 94

Open in your IDE?
  1. <?php
  2. namespace FoundersBundle\Controller;
  3. use Doctrine\ORM\EntityManagerInterface;
  4. use FoundersBundle\Entity\Biography;
  5. use FoundersBundle\Entity\CategoryPost;
  6. use FoundersBundle\Entity\Post;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Routing\RouterInterface;
  9. use Symfony\Component\Yaml\Yaml;
  10. class SiteMapController extends BaseController
  11. {
  12.     public function __construct(EntityManagerInterface $em)
  13.     {
  14.         parent::__construct($em);
  15.     }
  16.     public function siteMap(RouterInterface $router): Response
  17.     {
  18.         $root $this->getParameter('kernel.project_dir');
  19.         $routingFile $root '/src/FoundersBundle/Resources/config/routing/sitemap.yml';
  20.         $routes Yaml::parseFile($routingFile);
  21.         $result = [];
  22.         foreach ($routes as $rName => $route) {
  23.             if ($rName == 'founders_homepage') {
  24.                 $result[] = [
  25.                     'url' => $router->generate($rName),
  26.                     'priority' => '1',
  27.                     'changefreq' => 'daily',
  28.                 ];
  29.             }
  30.             if (in_array(
  31.                 $rName, [
  32.                 'founders_family_philosophy_get_posts',
  33.                 'founders_family_biographies',
  34.                 'founders_investment_category',
  35.                 'founders_investment_social_single',
  36.                 'founders_media_posts_single',
  37.                 'founders_homepage',
  38.             ])) {
  39.                 continue;
  40.             }
  41.             $result[] = [
  42.                 'url' => $router->generate($rName),
  43.                 'priority' => '0.5',
  44.                 'changefreq' => 'daily',
  45.             ];
  46.         }
  47.         $biographies $this->em->getRepository(Biography::class)->findAll();
  48.         foreach ($biographies as $biography) {
  49.             $result[] = [
  50.                 'url' => $router->generate('founders_family_biographies', ['url' => $biography->getUrl()]),
  51.                 'priority' => '0.8',
  52.                 'changefreq' => 'daily',
  53.             ];
  54.         }
  55.         $investmentCategories $this->em->getRepository(CategoryPost::class)->findBy(['state' => true]);
  56.         foreach ($investmentCategories as $category) {
  57.             $result[] = [
  58.                 'url' => $router->generate('founders_investment_category', ['category' => $category->getUrl()]),
  59.                 'priority' => '0.5',
  60.                 'changefreq' => 'daily',
  61.             ];
  62.         }
  63.         $investmentPosts $this->em->getRepository(Post::class)->getAllInvestmentPosts();
  64.         foreach ($investmentPosts as $post) {
  65.             $result[] = [
  66.                 'url' => $router->generate('founders_investment_social_single',
  67.                     ['category' => $post->getCategory()->getUrl(), 'url' => $post->getUrl()]),
  68.                 'priority' => '0.5',
  69.                 'changefreq' => 'daily',
  70.             ];
  71.         }
  72.         $allPosts $this->em->getRepository(Post::class)->getAllMediaPosts();
  73.         foreach ($allPosts as $post) {
  74.             $result[] = [
  75.                 'url' => $router->generate('founders_media_posts_single',
  76.                     ['category' => $post->getCategoryUrlById(), 'url' => $post->getUrl()]),
  77.                 'priority' => '0.6',
  78.                 'changefreq' => 'daily',
  79.             ];
  80.         }
  81.         $response $this->baseFounderController('@Founders/sitemap.xml.twig', ['urls' => $result'route' => 'founders_sitemap']);
  82.         $response->headers->set('Content-Type''application/xml');
  83.         $response->setCharset('utf-8');
  84.         return $response;
  85.     }
  86.     public function robots(): Response
  87.     {
  88.         $content $this->renderView('@Founders/robots.txt.twig', []);
  89.         return new Response($contentResponse::HTTP_OK, ['Content-Type' => 'text/plain']);
  90.     }
  91. }