<?php
namespace App\Controller;
use App\Entity\Edition;
use App\Entity\Path;
use App\Service\EditionFunction;
use App\Service\MetaTags\MetaTags;
use App\Service\Price;
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\FrameworkBundle\Routing\AnnotatedRouteControllerLoader;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Routing\Loader\AnnotationDirectoryLoader;
use Symfony\Component\Routing\Matcher\UrlMatcher;
use Symfony\Component\Routing\RequestContext;
class SiteController extends AbstractController
{
private $metaTags;
private $editionFunction;
private $em;
public function __construct(MetaTags $metaTags, EditionFunction $editionFunction, EntityManagerInterface $em)
{
$this->metaTags = $metaTags;
$this->editionFunction = $editionFunction;
$this->em = $em;
}
public function congratulation()
{
$output = [];
$holiday_now = [];
$holiday = [
'newYear' => [
'time' => ['start' => '25.12', 'end' => '31.12'],
'text' => 'Поздравляем с Новым Годом!',
'label' => 'new_year'
],
'newYear2' => [
'time' => ['start' => '01.01', 'end' => '08.01'],
'text' => 'Поздравляем с Новым Годом!',
'label' => 'new_year'
],
'student' => [
'time' => ['start' => '24.01', 'end' => '25.01'],
'text' => 'Поздравляем с Днем студента!',
'label' => 'student_day'
],
'science' => [
'time' => ['start' => '07.02', 'end' => '08.02'],
'text' => 'Поздравляем с Днем Российской науки!',
'label' => 'science_day'
],
'23february' => [
'time' => ['start' => '22.02', 'end' => '23.02'],
'text' => 'Поздравляем с 23 февраля!',
'label' => 'february_day'
],
'8mart' => [
'time' => ['start' => '07.03', 'end' => '08.03'],
'text' => 'Поздравляем с 8 марта!',
'label' => 'mart_day'
],
'1may' => [
'time' => ['start' => '30.04', 'end' => '01.05'],
'text' => 'Поздравляем с 1 мая!',
'label' => 'one_may'
],
'9may' => [
'time' => ['start' => '08.05', 'end' => '09.05'],
'text' => 'Поздравляем с 9 мая!',
'label' => 'nine_may'
],
'12june' => [
'time' => ['start' => '11.06', 'end' => '12.06'],
'text' => 'Поздравляем с Днем России!',
'label' => 'june_day'
],
'1september' => [
'time' => ['start' => '31.08', 'end' => '01.09'],
'text' => 'Поздравляем с 1 сентября!',
'label' => 'september_day'
],
'5october' => [
'time' => ['start' => '04.10', 'end' => '05.10'],
'text' => 'Поздравляем с Днем учителя!',
'label' => 'october_day'
],
'4november' => [
'time' => ['start' => '03.11', 'end' => '04.11'],
'text' => 'Поздравляем с Днем народного единства!',
'label' => 'november_day'
],
];
$y = date('.Y');
foreach($holiday as $item){
if(time() >= strtotime($item['time']['start'].$y.'00:00:00') && time() <= strtotime($item['time']['end'].$y.'23:59:59')){
$holiday_now = $item;
break;
}
}
if(!empty($holiday_now)) $output['holiday'] = $holiday_now;
return $this->render('blocks/header/congratulation.html.twig', [
'congratulation' => $output,
]);
}
/**
* @
*/
/**
* @Route("/test2134", priority=11, name="test")
*/
public function test()
{
die('end test');
}
/**
* @Route("/calc", priority=11, name="calc")
*/
public function calc(Price $price)
{
return $this->render('site/calc.html.twig', [
'prices' => $price->getActualPrice(),
'metaTags' => $this->metaTags->getCalc(),
]);
}
/**
* @Route("/form/complete", priority=11, name="fake_form_complete")
*/
public function form_complete()
{
return $this->render('site/form_complete.html.twig');
}
/**
* @Route("/", name="index")
*/
public function index()
{
$repository = $this->em->getRepository(Edition::class);
$query = $repository->createQueryBuilder('e')
->select('e')
->andWhere('e.status = 1')
->andWhere('e.date_end >= :date_end')
//->groupBy('e.direction')
->setParameter('date_end', date('Y-m-d'))
->orderBy('e.date_end', 'ASC')
->getQuery()
->getResult();
$IndexEdition = [];
foreach ($query as $item) {
if (empty($IndexEdition[$item->getDirection()])) $IndexEdition[$item->getDirection()] = $item;
}
foreach ($IndexEdition as $key => $item){
$IndexEdition[$key] = $this->editionFunction->getInfoEditionTeaser($item);
}
return $this->render('site/index.html.twig', [
'model' => $IndexEdition,
'direction' => $this->getParameter('direction'),
]);
}
/**
* @Route("/publication-of-articles-for-undergraduates", priority=11, name="publication_undergraduates")
*/
public function publication_undergraduates()
{
$editions = [];
$editions[] = $this->editionFunction->getNowEdition('moluch');
$editions[] = $this->editionFunction->getNowEdition('studmagazine');
return $this->render('site/publication_undergraduates.html.twig', [
'editions' => $editions,
'metaTags' => $this->metaTags->getPublicationUndergraduates(),
'direction' => $this->getParameter('direction'),
]);
}
/**
* @Route("/gde-opublikovat-nauchnuyu-statyu-studentu", priority=11, name="gde_opublikovat_nauchnuyu_statyu_studentu")
*/
public function gde_opublikovat_nauchnuyu_statyu_studentu()
{
$editions = [];
$editions[] = $this->editionFunction->getNowEdition('moluch');
$editions[] = $this->editionFunction->getNowEdition('studmagazine');
return $this->render('site/gde_opublikovat_nauchnuyu_statyu_studentu.html.twig', [
'editions' => $editions,
'metaTags' => $this->metaTags->getGdeOpublikovatNauchnuyuStatyuStudentu(),
]);
}
/**
* @Route("/scientific-conferences", priority=11, name="scientific_conferences")
*/
public function scientific_conferences()
{
$repository = $this->em->getRepository(Edition::class);
$query = $repository->createQueryBuilder('e')
->select('e')
->andWhere('e.status = 1')
->andWhere("e.direction LIKE '%conf/%'")
->andWhere('e.date_end >= :date_end')
->setParameter('date_end', date('Y-m-d H:i:s'))
->orderBy('e.date_end', 'ASC')
->getQuery()
->getResult();
$IndexEdition = [];
foreach ($query as $item) {
if (empty($IndexEdition[$item->getDirection()])) $IndexEdition[$item->getDirection()] = $item;
}
return $this->render('site/scientific_conferences.html.twig', [
'model' => $IndexEdition,
'metaTags' => $this->metaTags->scientific_conferences(),
]);
}
/**
* @Route("/opublikovat-statyu-elibraryru", priority=11, name="opublikovat_statyu_elibraryru")
*/
public function opublikovat_statyu_elibraryru()
{
$repository = $this->em->getRepository(Edition::class);
$query = $repository->createQueryBuilder('e')
->select('e')
->andWhere('e.status = 1')
->andWhere("e.direction IN ('moluch','conf/inno', 'mono')")
->andWhere('e.date_end >= :date_end')
->setParameter('date_end', date('Y-m-d H:i:s'))
->orderBy('e.date_end', 'ASC')
->getQuery()
->getResult();
$IndexEdition = [];
foreach ($query as $item) {
if (empty($IndexEdition[$item->getDirection()])) $IndexEdition[$item->getDirection()] = $item;
}
return $this->render('site/opublikovat_statyu_elibraryru.html.twig', [
'model' => $IndexEdition,
'metaTags' => $this->metaTags->opublikovat_statyu_elibraryru(),
]);
}
/**
* @Route("/nauchnye-konferencii-rinc-2018", priority=11, name="nauchnye_konferencii_rinc_2018")
*/
public function nauchnye_konferencii_rinc_2018()
{
$repository = $this->em->getRepository(Edition::class);
$query = $repository->createQueryBuilder('e')
->select('e')
->andWhere('e.status = 1')
->andWhere("e.direction LIKE '%conf/%' OR e.direction = 'moluch'")
->andWhere('e.date_end >= :date_end')
->setParameter('date_end', date('Y-m-d H:i:s'))
->orderBy('e.date_end', 'ASC')
->getQuery()
->getResult();
$IndexEdition = [];
foreach ($query as $item) {
$IndexEdition[$item->getDirection()][] = $item;
}
return $this->render('site/nauchnye_konferencii_rinc_2018.html.twig', [
'model' => $IndexEdition,
'metaTags' => $this->metaTags->nauchnye_konferencii_rinc_2018(),
]);
}
/**
* @Route("/{path}", priority=10, name="site", requirements={"path"=".+"})
*/
public function GetPathFromDB($path, Request $request)
{
if ($one_login = $request->query->get('one_login')) {
$path = $path . '?one_login=' . $one_login;
}
$post = $this->em
->getRepository(Path::class)
->findBy(['path' => $path], ['entity_type' => 'DESC']);
if (!empty($post[0])) {
$response = $this->forward('App\Controller\\' . ucfirst($post[0]->getEntityType()) . 'Controller::show', array(
'id' => $post[0]->getEntityId(),
));
} else {
$loader = new AnnotationDirectoryLoader(new FileLocator(), new AnnotatedRouteControllerLoader(new AnnotationReader()));
$context = new RequestContext('/');
$routes = $loader->load(__DIR__);
$routes->remove('site');
$matcher = new UrlMatcher($routes, $context);
try {
$parameters = $matcher->match($request->getPathInfo());
$params = [];
foreach ($parameters as $key => $item) {
if (!in_array($key, ['_controller', '_route'])) $params[$key] = $item;
}
$params['request'] = $request;
$response = $this->forward($parameters['_controller'], $params);
} catch (\Exception $e) {
throw $this->createNotFoundException();
}
}
if (!empty($response)) return $response;
return $this->render('site/404.html.twig');
}
}