src/Controller/MediaController.php line 65

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Pimcore\Controller\FrontendController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use \Pimcore\Model\DataObject as DataObj;
  8. class MediaController extends FrontendController
  9. {
  10.     /**
  11.      * @param Request $request
  12.      * @return Response
  13.      */
  14.     public function defaultAction(Request $request): Response
  15.     {
  16.         return $this->render('articles/default.html.twig');
  17.     }
  18.     
  19.     /**
  20.      * @Route("/media/{slug}", name="media-page")
  21.      *
  22.      */
  23.     public function articleListAction(Request $request,  \Knp\Component\Pager\PaginatorInterface $paginator)
  24.     {        
  25.         $getBeritaCategory      DataObj\ArticleCategory::getBySlug('berita',1);    
  26.         $getSiaranCategory      DataObj\ArticleCategory::getBySlug('siaran-pers'1);
  27.         $getInspiCategory       DataObj\ArticleCategory::getBySlug('inspirasi'1);
  28.         $slug        $request->get('slug''berita');
  29.         $getCat      DataObj\ArticleCategory::getBySlug($slug,1); 
  30.         
  31.         $data = new DataObj\Article\Listing();   
  32.         $data->setCondition("articleCategory__id = ?"$getCat->getId());  
  33.         $data->setOrderKey(["datePost","o_creationDate"]);   
  34.         $data->setOrder("desc");     
  35.         $data->load();   
  36.         $paginator $paginator->paginate(
  37.             $data,
  38.             $request->get('page'1),
  39.             9
  40.         );
  41.         
  42.         return $this->render('articles/index.html.twig', [
  43.             'data' => $data,
  44.             'category' => $getCat,
  45.             'categoryBerita' => $getBeritaCategory,
  46.             'categorySiaran' => $getSiaranCategory,
  47.             'categoryInspi' => $getInspiCategory,
  48.             'paginator' => $paginator,
  49.             'slug' => $slug,
  50.             'paginationVariables' => $paginator->getPaginationData(),
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/media/{category}/{slug}", name="media-detail")
  55.      *
  56.      */
  57.     public function articleDetailAction(Request $request,  \Knp\Component\Pager\PaginatorInterface $paginator)
  58.     {        
  59.         // $path   = parse_url($request->getUri(), PHP_URL_PATH); 
  60.         // $pathWl = substr($path, 3);
  61.         $slug           $request->get('slug');
  62.         $category       $request->get('category');
  63.         $getCategory    DataObj\ArticleCategory::getBySlug($category1);
  64.         
  65.         if(!empty($slug) && !empty($category)){
  66.             $detail DataObj\Article::getBySlug($slug1);
  67.             
  68.             if(!empty($detail)){
  69.                 $list = new DataObj\Article\Listing();   
  70.                 $list->setCondition("articleCategory__id = ? AND oo_id != ?", [$getCategory->getId(), $detail->getId()]);     
  71.                 $list->setOrderKey("oo_id");
  72.                 $list->setOrder("asc");    
  73.                 $list->setLimit(3);     
  74.                 $list->load();  
  75.             }else{
  76.                 throw new \Exception('Data Not Found');
  77.             }
  78.             return $this->render('articles/detail.html.twig', [
  79.                 'data' => $detail,
  80.                 'list' => $list,
  81.             ]);
  82.         }else{
  83.             if($this->editmode){
  84.                 $detail DataObj\Article::getBySlug('test'1);
  85.                 $list = new DataObj\Article\Listing();       
  86.                 $list->setOrderKey("oo_id");
  87.                 $list->setOrder("asc");    
  88.                 $list->setLimit(3);     
  89.                 $list->load();  
  90.                 return $this->render('articles/detail.html.twig', [
  91.                     'data' => $detail,
  92.                     'list' => $list,
  93.                 ]);
  94.             }else{
  95.                 throw new \Exception('Data Not Found');
  96.             }
  97.         }
  98.        
  99.     }
  100. }