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

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/|file/|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) {
  30.                 $page $pageManager->getPageBySeoId('error');
  31.                 $responseCode 404;
  32.             }
  33.         } else {
  34.             $page $pageManager->getPageBySeoId('homepage');
  35.         }
  36.         if ($cmsTemplate === false) {
  37.             return ["page" => $page"code" => $responseCode];
  38.         }
  39.         return new Response($this->renderView('@ScoreCms/Public/default/subpage.html.twig', [
  40.             'page' => $page,
  41.         ]), $responseCode);
  42.     }
  43.     /**
  44.      * @Route("/cookies", name="cookies")
  45.      */
  46.     public function cookiesAction(){
  47.         return $this->render('@ScoreCms/Public/idsk/cookies.html.twig');
  48.     }
  49.      /**
  50.      * @Route("/vyhladavanie", name="search")
  51.      */
  52.     public function searchAction(Request $requestSeoUrl $seoUrlManager$cmsTemplate true){
  53.         $slug $request->get('search');
  54.         $result = [];
  55.         if ($slug && $seoUrlManager->createSlug($slug)) {
  56.             
  57.             //$seoSlug = $seoUrlManager->createSlug($slug);
  58.             $seoSlug $seoUrlManager->removeDiacritic($slug);
  59.             $con $this->getDoctrine()->getManager()->getConnection();
  60.             $rawData = [];
  61.             // //$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');
  62.             // $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"]);
  63.             // $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');
  64.             // $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');
  65.             $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"]);
  66.             $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');
  67.             $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');
  68.             foreach ($rawData as $type => $rows) {
  69.                 foreach ($rows as $row) {
  70.                     if ($row['search']  && strpos($row['search'], $seoSlug) !== false) {
  71.                         $result[] = [
  72.                             "title" => $row['name'],
  73.                             "slug" => $row['slug'],
  74.                             "icon" => $row['icon'],
  75.                             "edited"=> $row['edit'],
  76.                             "type" => $type
  77.                         ];
  78.                     }
  79.                 }
  80.             }
  81.             usort($result, function ($item1$item2) {
  82.                 return $item2['edited'] <=> $item1['edited'];
  83.             });
  84.         }
  85.         if ($cmsTemplate === false) {
  86.             return $result;
  87.         }
  88.         return $this->render('@ScoreCms/Public/default/search.html.twig', [
  89.             "items" => $result,
  90.             "search_slug" => $slug
  91.         ]);
  92.     }
  93. }