<?php
namespace App\Controller;
use Pimcore\Controller\FrontendController;
use Symfony\Component\HttpFoundation\Request;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Routing\Annotation\Route;
use Pimcore\Model\DataObject;
date_default_timezone_set('Europe/Brussels');
class NewController extends FrontendController
{
/**
* @Template
* @param Request $request
* @return array
*/
public function listAction(Request $request, \Knp\Component\Pager\PaginatorInterface $paginator)
{
$news = new DataObject\News\Listing();
$news->setOrderKey('date');
$news->setOrder('Desc');
$news->load();
$countPerPage = intval($this->document->getProperty("newItemCountPerPage"));
if(!$countPerPage) :
$countPerPage = 3;
endif;
$paginator = $paginator->paginate(
$news,
$request->get('page', 1),
$countPerPage
);
return $this->render('news/list.html.twig', [
'paginator' => $paginator,
'paginationVariables' => $paginator->getPaginationData(),
'news' => $news
]);
}
/**
* @Template
* @param Request $request
* @route("/{_locale}/actualites/{slug}/{id}", name="newsDetail",methods={"GET"})
* @return array
*/
public function detailAction(Request $request)
{
$id = $request->get('id');
$new = DataObject\News::getById($id);
return $this->render('news/detail.html.twig', [
'new' => $new
]);
}
/**
* @Template
* @param Request $request
* @return array
*/
public function snippetAction(Request $request)
{
$lastnew = new DataObject\News\Listing();
$lastnew->setOrderKey('date');
$lastnew->setOrder('Desc');
$lastnew->setLimit(3);
$lastnew->load();
return $this->render('snippets/last-news.html.twig', [
'lastnew' => $lastnew
]);
}
}