src/Controller/SiteController.php line 196

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Edition;
  4. use App\Entity\Path;
  5. use App\Service\EditionFunction;
  6. use App\Service\MetaTags\MetaTags;
  7. use App\Service\Price;
  8. use Doctrine\Common\Annotations\AnnotationReader;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  11. use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
  12. use Symfony\Component\Config\FileLocator;
  13. use Symfony\Component\HttpFoundation\Request;
  14. use Symfony\Component\Routing\Annotation\Route;
  15. use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
  16. use Symfony\Component\Routing\Matcher\UrlMatcher;
  17. use Symfony\Component\Routing\RequestContext;
  18. class SiteController extends AbstractController
  19. {
  20.     private $metaTags;
  21.     private $editionFunction;
  22.     private $em;
  23.     public function __construct(MetaTags $metaTagsEditionFunction $editionFunctionEntityManagerInterface $em)
  24.     {
  25.         $this->metaTags $metaTags;
  26.         $this->editionFunction $editionFunction;
  27.         $this->em $em;
  28.     }
  29.     public function congratulation()
  30.     {
  31.         $output = [];
  32.         $holiday_now = [];
  33.         $holiday = [
  34.             'newYear' => [
  35.                 'time' => ['start' => '25.12''end' => '31.12'],
  36.                 'text' => 'Поздравляем с Новым Годом!',
  37.                 'label' => 'new_year'
  38.             ],
  39.             'newYear2' => [
  40.                 'time' => ['start' => '01.01''end' => '08.01'],
  41.                 'text' => 'Поздравляем с Новым Годом!',
  42.                 'label' => 'new_year'
  43.             ],
  44.             'student' => [
  45.                 'time' => ['start' => '24.01''end' => '25.01'],
  46.                 'text' => 'Поздравляем с Днем студента!',
  47.                 'label' => 'student_day'
  48.             ],
  49.             'science' => [
  50.                 'time' => ['start' => '07.02''end' => '08.02'],
  51.                 'text' => 'Поздравляем с Днем Российской науки!',
  52.                 'label' => 'science_day'
  53.             ],
  54.             '23february' => [
  55.                 'time' => ['start' => '22.02''end' => '23.02'],
  56.                 'text' => 'Поздравляем с 23 февраля!',
  57.                 'label' => 'february_day'
  58.             ],
  59.             '8mart' => [
  60.                 'time' => ['start' => '07.03''end' => '08.03'],
  61.                 'text' => 'Поздравляем с 8 марта!',
  62.                 'label' => 'mart_day'
  63.             ],
  64.             '1may' => [
  65.                 'time' => ['start' => '30.04''end' => '01.05'],
  66.                 'text' => 'Поздравляем с 1 мая!',
  67.                 'label' => 'one_may'
  68.             ],
  69.             '9may' => [
  70.                 'time' => ['start' => '08.05''end' => '09.05'],
  71.                 'text' => 'Поздравляем с 9 мая!',
  72.                 'label' => 'nine_may'
  73.             ],
  74.             '12june' => [
  75.                 'time' => ['start' => '11.06''end' => '12.06'],
  76.                 'text' => 'Поздравляем с Днем России!',
  77.                 'label' => 'june_day'
  78.             ],
  79.             '1september' => [
  80.                 'time' => ['start' => '31.08''end' => '01.09'],
  81.                 'text' => 'Поздравляем с 1 сентября!',
  82.                 'label' => 'september_day'
  83.             ],
  84.             '5october' => [
  85.                 'time' => ['start' => '04.10''end' => '05.10'],
  86.                 'text' => 'Поздравляем с Днем учителя!',
  87.                 'label' => 'october_day'
  88.             ],
  89.             '4november' => [
  90.                 'time' => ['start' => '03.11''end' => '04.11'],
  91.                 'text' => 'Поздравляем с Днем народного единства!',
  92.                 'label' => 'november_day'
  93.             ],
  94.         ];
  95.         $y date('.Y');
  96.         foreach($holiday as $item){
  97.             if(time() >= strtotime($item['time']['start'].$y.'00:00:00') && time() <= strtotime($item['time']['end'].$y.'23:59:59')){
  98.                 $holiday_now $item;
  99.                 break;
  100.             }
  101.         }
  102.         if(!empty($holiday_now)) $output['holiday'] = $holiday_now;
  103.         return $this->render('blocks/header/congratulation.html.twig', [
  104.             'congratulation' => $output,
  105.         ]);
  106.     }
  107.     /**
  108.      * @
  109.      */
  110.     /**
  111.      * @Route("/test2134", priority=11, name="test")
  112.      */
  113.     public function test()
  114.     {
  115.         die('end test');
  116.     }
  117.     /**
  118.      * @Route("/calc", priority=11, name="calc")
  119.      */
  120.     public function calc(Price $price)
  121.     {
  122.         return $this->render('site/calc.html.twig', [
  123.             'prices' => $price->getActualPrice(),
  124.             'metaTags' => $this->metaTags->getCalc(),
  125.         ]);
  126.     }
  127.     /**
  128.      * @Route("/form/complete", priority=11, name="fake_form_complete")
  129.      */
  130.     public function form_complete()
  131.     {
  132.         return $this->render('site/form_complete.html.twig');
  133.     }
  134.     /**
  135.      * @Route("/", name="index")
  136.      */
  137.     public function index()
  138.     {
  139.         $repository $this->em->getRepository(Edition::class);
  140.         $query $repository->createQueryBuilder('e')
  141.             ->select('e')
  142.             ->andWhere('e.status = 1')
  143.             ->andWhere('e.date_end >= :date_end')
  144.             //->groupBy('e.direction')
  145.             ->setParameter('date_end'date('Y-m-d'))
  146.             ->orderBy('e.date_end''ASC')
  147.             ->getQuery()
  148.             ->getResult();
  149.         $IndexEdition = [];
  150.         foreach ($query as $item) {
  151.             if (empty($IndexEdition[$item->getDirection()])) $IndexEdition[$item->getDirection()] = $item;
  152.         }
  153.         foreach ($IndexEdition as $key => $item){
  154.             $IndexEdition[$key] = $this->editionFunction->getInfoEditionTeaser($item);
  155.         }
  156.         return $this->render('site/index.html.twig', [
  157.             'model' => $IndexEdition,
  158.             'direction' => $this->getParameter('direction'),
  159.         ]);
  160.     }
  161.     /**
  162.      * @Route("/publication-of-articles-for-undergraduates", priority=11, name="publication_undergraduates")
  163.      */
  164.     public function publication_undergraduates()
  165.     {
  166.         $editions = [];
  167.         $editions[] = $this->editionFunction->getNowEdition('moluch');
  168.         $editions[] = $this->editionFunction->getNowEdition('studmagazine');
  169.         return $this->render('site/publication_undergraduates.html.twig', [
  170.             'editions' => $editions,
  171.             'metaTags' => $this->metaTags->getPublicationUndergraduates(),
  172.             'direction' => $this->getParameter('direction'),
  173.         ]);
  174.     }
  175.     /**
  176.      * @Route("/gde-opublikovat-nauchnuyu-statyu-studentu", priority=11, name="gde_opublikovat_nauchnuyu_statyu_studentu")
  177.      */
  178.     public function gde_opublikovat_nauchnuyu_statyu_studentu()
  179.     {
  180.         $editions = [];
  181.         $editions[] = $this->editionFunction->getNowEdition('moluch');
  182.         $editions[] = $this->editionFunction->getNowEdition('studmagazine');
  183.         return $this->render('site/gde_opublikovat_nauchnuyu_statyu_studentu.html.twig', [
  184.             'editions' => $editions,
  185.             'metaTags' => $this->metaTags->getGdeOpublikovatNauchnuyuStatyuStudentu(),
  186.         ]);
  187.     }
  188.     /**
  189.      * @Route("/scientific-conferences", priority=11, name="scientific_conferences")
  190.      */
  191.     public function scientific_conferences()
  192.     {
  193.         $repository $this->em->getRepository(Edition::class);
  194.         $query $repository->createQueryBuilder('e')
  195.             ->select('e')
  196.             ->andWhere('e.status = 1')
  197.             ->andWhere("e.direction LIKE '%conf/%'")
  198.             ->andWhere('e.date_end >= :date_end')
  199.             ->setParameter('date_end'date('Y-m-d H:i:s'))
  200.             ->orderBy('e.date_end''ASC')
  201.             ->getQuery()
  202.             ->getResult();
  203.         $IndexEdition = [];
  204.         foreach ($query as $item) {
  205.             if (empty($IndexEdition[$item->getDirection()])) $IndexEdition[$item->getDirection()] = $item;
  206.         }
  207.         return $this->render('site/scientific_conferences.html.twig', [
  208.             'model' => $IndexEdition,
  209.             'metaTags' => $this->metaTags->scientific_conferences(),
  210.         ]);
  211.     }
  212.     /**
  213.      * @Route("/opublikovat-statyu-elibraryru", priority=11, name="opublikovat_statyu_elibraryru")
  214.      */
  215.     public function opublikovat_statyu_elibraryru()
  216.     {
  217.         $repository $this->em->getRepository(Edition::class);
  218.         $query $repository->createQueryBuilder('e')
  219.             ->select('e')
  220.             ->andWhere('e.status = 1')
  221.             ->andWhere("e.direction IN ('moluch','conf/inno', 'mono')")
  222.             ->andWhere('e.date_end >= :date_end')
  223.             ->setParameter('date_end'date('Y-m-d H:i:s'))
  224.             ->orderBy('e.date_end''ASC')
  225.             ->getQuery()
  226.             ->getResult();
  227.         $IndexEdition = [];
  228.         foreach ($query as $item) {
  229.             if (empty($IndexEdition[$item->getDirection()])) $IndexEdition[$item->getDirection()] = $item;
  230.         }
  231.         return $this->render('site/opublikovat_statyu_elibraryru.html.twig', [
  232.             'model' => $IndexEdition,
  233.             'metaTags' => $this->metaTags->opublikovat_statyu_elibraryru(),
  234.         ]);
  235.     }
  236.     /**
  237.      * @Route("/nauchnye-konferencii-rinc-2018", priority=11, name="nauchnye_konferencii_rinc_2018")
  238.      */
  239.     public function nauchnye_konferencii_rinc_2018()
  240.     {
  241.         $repository $this->em->getRepository(Edition::class);
  242.         $query $repository->createQueryBuilder('e')
  243.             ->select('e')
  244.             ->andWhere('e.status = 1')
  245.             ->andWhere("e.direction LIKE '%conf/%' OR e.direction = 'moluch'")
  246.             ->andWhere('e.date_end >= :date_end')
  247.             ->setParameter('date_end'date('Y-m-d H:i:s'))
  248.             ->orderBy('e.date_end''ASC')
  249.             ->getQuery()
  250.             ->getResult();
  251.         $IndexEdition = [];
  252.         foreach ($query as $item) {
  253.             $IndexEdition[$item->getDirection()][] = $item;
  254.         }
  255.         return $this->render('site/nauchnye_konferencii_rinc_2018.html.twig', [
  256.             'model' => $IndexEdition,
  257.             'metaTags' => $this->metaTags->nauchnye_konferencii_rinc_2018(),
  258.         ]);
  259.     }
  260.     /**
  261.      * @Route("/{path}", priority=10, name="site", requirements={"path"=".+"})
  262.      */
  263.     public function GetPathFromDB($pathRequest $request)
  264.     {
  265.         if ($one_login $request->query->get('one_login')) {
  266.             $path $path '?one_login=' $one_login;
  267.         }
  268.         $post $this->em
  269.             ->getRepository(Path::class)
  270.             ->findBy(['path' => $path], ['entity_type' => 'DESC']);
  271.         if (!empty($post[0])) {
  272.             $response $this->forward('App\Controller\\' ucfirst($post[0]->getEntityType()) . 'Controller::show', array(
  273.                 'id' => $post[0]->getEntityId(),
  274.             ));
  275.         } else {
  276.             $loader = new AnnotationDirectoryLoader(new FileLocator(), new AnnotatedRouteControllerLoader(new AnnotationReader()));
  277.             $context = new RequestContext('/');
  278.             $routes $loader->load(__DIR__);
  279.             $routes->remove('site');
  280.             $matcher = new UrlMatcher($routes$context);
  281.             try {
  282.                 $parameters $matcher->match($request->getPathInfo());
  283.                 $params = [];
  284.                 foreach ($parameters as $key => $item) {
  285.                     if (!in_array($key, ['_controller''_route'])) $params[$key] = $item;
  286.                 }
  287.                 $params['request'] = $request;
  288.                 $response $this->forward($parameters['_controller'], $params);
  289.             } catch (\Exception $e) {
  290.                 throw $this->createNotFoundException();
  291.             }
  292.         }
  293.         if (!empty($response)) return $response;
  294.         return $this->render('site/404.html.twig');
  295.     }
  296. }