src/Controller/FrontpageController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\HttpFoundation\Response;
  4. use Symfony\Component\Routing\Annotation\Route;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use App\Entity\Newsfeed;
  8. use App\Entity\Frontpage;
  9. use App\Entity\Articles;
  10. use App\Entity\Glossaries;
  11. use App\Entity\LocationsFossil;
  12. use App\Entity\LocationsGeology;
  13. use App\Entity\LocationsMuseum;
  14. use App\Entity\LocationsSociety;
  15. //Community
  16. use App\Entity\FossildbFossil;
  17. use App\Form\FrontpageFormType;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. class FrontpageController extends AbstractController
  20. {
  21.     private $em;
  22.     public function __construct(EntityManagerInterface $em)
  23.     {
  24.         $this->em $em;
  25.     }
  26.     /**
  27.      * @Route("/", name="frontpage")
  28.      */
  29.     public function index(EntityManagerInterface $em)
  30.     {
  31.         $repository $this->getDoctrine()->getRepository(Frontpage::class);
  32.         $frontpage $this->em->getRepository(Frontpage::class)->createQueryBuilder('f')
  33.         ->select('f.header_article_type, f.header_article, f.header_article_enabled, f.highlight_location_type, f.highlight_location, f.highlight_article_type, f.highlight_article, f.highlight_fossildb, f.event_title, f.event_text, f.event_url, f.event_enabled')
  34.         ->where('f.id = 1')
  35.         ->getQuery()
  36.         ->getResult()[0];
  37.         if($frontpage['header_article_type'] == 'article') {
  38.             $header_article $this->em->getRepository(Articles::class)->createQueryBuilder('a')
  39.             ->select('a.id, a.url, a.image, a.title_nl, a.title_en, a.intro_nl, a.intro_en ')
  40.             ->where('a.id = '.json_decode($frontpage['header_article'])[0]->id)
  41.             ->getQuery()
  42.             ->getResult()[0];
  43.         }
  44.         elseif($frontpage['header_article_type'] == 'glossary') {
  45.             $header_article $this->em->getRepository(Glossaries::class)->createQueryBuilder('a')
  46.             ->select('a.id, a.url, a.image, a.title_nl, a.title_en, a.intro_nl, a.intro_en ')
  47.             ->where('a.id = '.json_decode($frontpage['header_article'])[0]->id)
  48.             ->getQuery()
  49.             ->getResult()[0];
  50.         }
  51.         if($frontpage['highlight_location_type'] == 'fossil') {
  52.             $highlight_location $this->em->getRepository(LocationsFossil::class)->createQueryBuilder('l')
  53.             ->select('l.id, l.name_nl, l.name_en, l.description_nl, l.description_en')
  54.             ->where('l.id = '.json_decode($frontpage['highlight_location'])[0]->id)
  55.             ->getQuery()
  56.             ->getResult()[0];
  57.         }
  58.         elseif($frontpage['highlight_location_type'] == 'geology') {
  59.             $highlight_location $this->em->getRepository(LocationsGeology::class)->createQueryBuilder('l')
  60.             ->select('l.id, l.name_nl, l.name_en, l.description_nl, l.description_en')
  61.             ->where('l.id = '.json_decode($frontpage['highlight_location'])[0]->id)
  62.             ->getQuery()
  63.             ->getResult()[0];
  64.         }
  65.         elseif(['highlight_location_type'] == 'museum') {
  66.             $highlight_location $this->em->getRepository(LocationsMuseum::class)->createQueryBuilder('l')
  67.             ->select('l.id, l.name_nl, l.name_en, l.description_nl, l.description_en')
  68.             ->where('l.id = '.json_decode($frontpage['highlight_location'])[0]->id)
  69.             ->getQuery()
  70.             ->getResult()[0];
  71.         }
  72.         elseif(['highlight_location_type'] == 'society') {
  73.             $highlight_location $this->em->getRepository(LocationsSociety::class)->createQueryBuilder('l')
  74.             ->select('l.id, l.name_nl, l.name_en, l.description_nl, l.description_en')
  75.             ->where('l.id = '.json_decode($frontpage['highlight_location'])[0]->id)
  76.             ->getQuery()
  77.             ->getResult()[0];
  78.         }
  79.         if($frontpage['highlight_article_type'] == 'article') {
  80.             $highlight_article $this->em->getRepository(Articles::class)->createQueryBuilder('a')
  81.             ->select('a.id, a.url, a.image, a.title_nl, a.title_en, a.description_nl, a.description_en ')
  82.             ->where('a.id = '.json_decode($frontpage['highlight_article'])[0]->id)
  83.             ->getQuery()
  84.             ->getResult()[0];
  85.         }
  86.         elseif($frontpage['highlight_article_type'] == 'glossary') {
  87.             $highlight_article $this->em->getRepository(Glossaries::class)->createQueryBuilder('a')
  88.             ->select('a.id, a.url, a.image, a.title_nl, a.title_en, a.description_nl, a.description_en ')
  89.             ->where('a.id = '.json_decode($frontpage['highlight_article'])[0]->id)
  90.             ->getQuery()
  91.             ->getResult()[0];
  92.         }
  93.         $forumConn $this->getDoctrine()->getConnection('forumdb');
  94.         //$sql = $forumConn->prepare("SELECT `phpbb_posts`.`post_id`, `phpbb_posts`.`forum_id`, `phpbb_posts`.`poster_id`, `phpbb_users`.`username`, `phpbb_posts`.`post_subject`, `phpbb_topics`.`topic_first_post_id` FROM `phpbb_posts`, `phpbb_topics`, `phpbb_users` WHERE `phpbb_topics`.`topic_id` = `phpbb_posts`. `topic_id` AND `phpbb_users`.`user_id` = `phpbb_posts`.`poster_id` ORDER BY `phpbb_posts`.`post_id` DESC LIMIT 1");
  95.         $forumQuery $forumConn->prepare("SELECT `phpbb_posts`.`post_id`, `phpbb_posts`.`forum_id`, `phpbb_users`.`username`, `phpbb_posts`.`post_subject`, `phpbb_posts`.`post_text`, `phpbb_topics`.`topic_first_post_id` FROM `phpbb_posts`, `phpbb_topics`, `phpbb_users` WHERE `phpbb_topics`.`topic_id` = `phpbb_posts`. `topic_id` AND `phpbb_topics`.`forum_id` NOT IN ('70', '90', '94') AND `post_visibility` = 1 AND `phpbb_users`.`user_id` = `phpbb_posts`.`poster_id` ORDER BY `phpbb_posts`.`post_id` DESC LIMIT 1");
  96.         $forumQuery->execute();
  97.         $highlight_community $forumQuery->fetchAll()[0];
  98.         $subrepository $this->getDoctrine()->getRepository(FossildbFossil::class);
  99.         $highlight_fossildb $subrepository->findOneBy(array('id' => $frontpage['highlight_fossildb']));
  100.         $repository $this->getDoctrine()->getRepository(Newsfeed::class);
  101.         $newsfeed $repository->findby(array(),array('time' => 'DESC'),35);
  102.         $newsfeed_part1 array_slice($newsfeed015);
  103.         $newsfeed_part2 array_slice($newsfeed1520);
  104.         
  105.         // $forumQuery = $forumConn->prepare("SELECT `phpbb_posts`.`post_id`, `phpbb_posts`.`forum_id`, `phpbb_posts`.`poster_id`, `phpbb_users`.`username`, `phpbb_posts`.`post_subject`, `phpbb_topics`.`topic_first_post_id` FROM `phpbb_posts`, `phpbb_topics`, `phpbb_users` WHERE `phpbb_topics`.`topic_id` = `phpbb_posts`. `topic_id` AND `phpbb_users`.`user_id` = `phpbb_posts`.`poster_id` ORDER BY `phpbb_posts`.`post_id` DESC LIMIT 35");
  106.         // $forumQuery->execute();
  107.         // $newsfeed_community = $forumQuery->fetchAll();
  108.         // dump($newsfeed_community);
  109.         return $this->render('frontpage.html.twig', [
  110.             'frontpage' => $frontpage,
  111.             'header_article' => $header_article,
  112.             'highlight_location' => $highlight_location,
  113.             'highlight_article' => $highlight_article,
  114.             'highlight_fossildb' => $highlight_fossildb,
  115.             'highlight_community' => $highlight_community,
  116.             'newsfeed_part1' => $newsfeed_part1,
  117.             'newsfeed_part2' => $newsfeed_part2,
  118.         ]);
  119.     }
  120.     /**
  121.      * @Route("/moderate/frontpage/", name="frontpage_moderate")
  122.      */
  123.     public function frontpage(Request $requestEntityManagerInterface $em)
  124.     {
  125.         $this->denyAccessUnlessGranted('ROLE_MOD_FRONTPAGE');
  126.         $repository $this->getDoctrine()->getRepository(Frontpage::class);
  127.         $frontpage $repository->findOneBy(array('id' => 1));
  128.         $form $this->createForm(FrontpageFormType::class, $frontpage);
  129.         $form->handleRequest($request);
  130.         if ($form->isSubmitted() && $form->isValid()){
  131.             $frontpage $form->getData();
  132.             $em->persist($frontpage);
  133.             $em->flush();
  134.         }
  135.         return $this->render('frontpage_moderate.html.twig', [
  136.             'form' => $form->createView(),
  137.             'filter' => $frontpage
  138.         ]);
  139.     }
  140. }