<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use \Pimcore\Model\DataObject as DataObj;
class MediaController extends FrontendController
{
/**
* @param Request $request
* @return Response
*/
public function defaultAction(Request $request): Response
{
return $this->render('articles/default.html.twig');
}
/**
* @Route("/media/{slug}", name="media-page")
*
*/
public function articleListAction(Request $request, \Knp\Component\Pager\PaginatorInterface $paginator)
{
$getBeritaCategory = DataObj\ArticleCategory::getBySlug('berita',1);
$getSiaranCategory = DataObj\ArticleCategory::getBySlug('siaran-pers', 1);
$getInspiCategory = DataObj\ArticleCategory::getBySlug('inspirasi', 1);
$slug = $request->get('slug', 'berita');
$getCat = DataObj\ArticleCategory::getBySlug($slug,1);
$data = new DataObj\Article\Listing();
$data->setCondition("articleCategory__id = ?", $getCat->getId());
$data->setOrderKey(["datePost","o_creationDate"]);
$data->setOrder("desc");
$data->load();
$paginator = $paginator->paginate(
$data,
$request->get('page', 1),
9
);
return $this->render('articles/index.html.twig', [
'data' => $data,
'category' => $getCat,
'categoryBerita' => $getBeritaCategory,
'categorySiaran' => $getSiaranCategory,
'categoryInspi' => $getInspiCategory,
'paginator' => $paginator,
'slug' => $slug,
'paginationVariables' => $paginator->getPaginationData(),
]);
}
/**
* @Route("/media/{category}/{slug}", name="media-detail")
*
*/
public function articleDetailAction(Request $request, \Knp\Component\Pager\PaginatorInterface $paginator)
{
// $path = parse_url($request->getUri(), PHP_URL_PATH);
// $pathWl = substr($path, 3);
$slug = $request->get('slug');
$category = $request->get('category');
$getCategory = DataObj\ArticleCategory::getBySlug($category, 1);
if(!empty($slug) && !empty($category)){
$detail = DataObj\Article::getBySlug($slug, 1);
if(!empty($detail)){
$list = new DataObj\Article\Listing();
$list->setCondition("articleCategory__id = ? AND oo_id != ?", [$getCategory->getId(), $detail->getId()]);
$list->setOrderKey("oo_id");
$list->setOrder("asc");
$list->setLimit(3);
$list->load();
}else{
throw new \Exception('Data Not Found');
}
return $this->render('articles/detail.html.twig', [
'data' => $detail,
'list' => $list,
]);
}else{
if($this->editmode){
$detail = DataObj\Article::getBySlug('test', 1);
$list = new DataObj\Article\Listing();
$list->setOrderKey("oo_id");
$list->setOrder("asc");
$list->setLimit(3);
$list->load();
return $this->render('articles/detail.html.twig', [
'data' => $detail,
'list' => $list,
]);
}else{
throw new \Exception('Data Not Found');
}
}
}
}