vendor/score/cms/src/Controller/Page/PublicController.php line 24

Open in your IDE?
  1. <?php
  2. namespace Score\CmsBundle\Controller\Page;
  3. use DateTime;
  4. use Score\CmsBundle\Entity\Menu;
  5. use Score\CmsBundle\Entity\Stat;
  6. use Score\CmsBundle\Services\PageManager;
  7. use Score\CmsBundle\Services\StatManager;
  8. use Score\CmsBundle\Services\OptionManager;
  9. use Symfony\Component\HttpFoundation\Request;
  10. use Symfony\Component\HttpFoundation\Response;
  11. use Symfony\Component\Routing\Annotation\Route;
  12. use Score\BaseBundle\Services\AdjacencyArrayTreeManager;
  13. use Score\BaseBundle\Services\SeoUrl;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. class PublicController extends AbstractController
  16. {
  17.     /**
  18.      * @Route("/", name="default_homepage")
  19.      * @Route("/{seoid}", name="default_subpage", requirements={"seoid"="^(?!login$|logout$|registration$|api/|user/|clanky/|udalosti/|dokumenty/|dokument/|admin/|cookies$|vyhladavanie|_profiler/).+"}, condition="!request.isXmlHttpRequest()")
  20.      */
  21.     public function subpageAction(PageManager $pageManager, $seoid = null, $cmsTemplate = true)
  22.     {
  23.         $responseCode = 200;
  24.         if ($seoid) {
  25.             if ($seoid === "homepage") {
  26.                 return $this->redirectToRoute('default_homepage');
  27.             }
  28.             $page = $pageManager->getPageBySeoId($seoid);
  29.             if (!$page || $page->getIsDeleted() || $page->getStatus() === "hidden") {
  30.                 $page = $pageManager->getPageBySeoId('error');
  31.                 $responseCode = 404;
  32.             }
  33.             if ($page->getRedirectToPage()) {
  34.                 return $this->redirectToRoute('default_subpage', [
  35.                     "seoid" => $page->getRedirectToPage()->getSeoId()
  36.                 ]);
  37.             }
  38.         } else {
  39.             $page = $pageManager->getPageBySeoId('homepage');
  40.         }
  41.         if ($cmsTemplate === false) {
  42.             return ["page" => $page, "code" => $responseCode];
  43.         }
  44.         return new Response($this->renderView('@ScoreCms/Public/default/subpage.html.twig', [
  45.             'page' => $page,
  46.         ]), $responseCode);
  47.     }
  48.     /**
  49.      * @Route("/cookies", name="cookies")
  50.      */
  51.     public function cookiesAction(){
  52.         return $this->render('@ScoreCms/Public/idsk/cookies.html.twig');
  53.     }
  54.      /**
  55.      * @Route("/vyhladavanie", name="search")
  56.      */
  57.     public function searchAction(Request $request, SeoUrl $seoUrlManager, $cmsTemplate = true){
  58.         $slug = $request->get('search');
  59.         $result = [];
  60.         if ($slug && $seoUrlManager->createSlug($slug)) {
  61.             
  62.             //$seoSlug = $seoUrlManager->createSlug($slug);
  63.             $seoSlug = $seoUrlManager->removeDiacritic($slug);
  64.             $con = $this->getDoctrine()->getManager()->getConnection();
  65.             $rawData = [];
  66.             // //$rawData['page'] = $con->fetchAllAssociative('SELECT p.title as name , p.content , p.seo_id as slug, p.icon as icon, p.edited_at as edit FROM cms_page p');
  67.             // $rawData['page'] = $con->fetchAllAssociative('SELECT p.title as name , p.content , p.seo_id as slug, p.icon as icon, p.edited_at as edit FROM cms_page p WHERE p.seo_id NOT IN (?, ?, ?)', ["as", "error", "homepage"]);
  68.             // $rawData['article'] = $con->fetchAllAssociative('SELECT a.name as name, a.teaser, a.body, a.author, a.slug as slug, a.icon as icon, a.edited_at as edit FROM cms_article a');
  69.             // $rawData['event'] = $con->fetchAllAssociative('SELECT e.name as name, e.content, e.teaser, e.organizer, e.contact_person, e.slug as slug, e.icon as icon, e.edited_at as edit FROM cms_event e');
  70.             $rawData['page'] = $con->fetchAllAssociative('SELECT p.title as name , p.seo_id as slug, p.p_search as search, p.icon as icon, p.edited_at as edit FROM cms_page p WHERE p.seo_id NOT IN (?, ?, ?)', ["as", "error", "homepage"]);
  71.             $rawData['article'] = $con->fetchAllAssociative('SELECT a.name as name, a.slug as slug, a.search as search, a.icon as icon, a.edited_at as edit FROM cms_article a');
  72.             $rawData['event'] = $con->fetchAllAssociative('SELECT e.name as name, e.slug as slug, e.e_search as search, e.icon as icon, e.edited_at as edit FROM cms_event e');
  73.             foreach ($rawData as $type => $rows) {
  74.                 foreach ($rows as $row) {
  75.                     if ($row['SEARCH']  && strpos($row['SEARCH'], $seoSlug) !== false) {
  76.                         $result[] = [
  77.                             "title" => $row['NAME'],
  78.                             "slug" => $row['SLUG'],
  79.                             "icon" => $row['ICON'],
  80.                             "edited"=> $row['EDIT'],
  81.                             "type" => $type
  82.                         ];
  83.                     }
  84.                 }
  85.             }
  86.             usort($result, function ($item1, $item2) {
  87.                 return $item2['edited'] <=> $item1['edited'];
  88.             });
  89.         }
  90.         if ($cmsTemplate === false) {
  91.             return $result;
  92.         }
  93.         return $this->render('@ScoreCms/Public/default/search.html.twig', [
  94.             "items" => $result,
  95.             "search_slug" => $slug
  96.         ]);
  97.     }
  98. }