<?php
namespace App\Controller;
use Pimcore\Model\DataObject\ServiceProvider;
use Pimcore\Model\DataObject\Folder;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Website\LinkGenerator\SpLinkGenerator;
use App\Website\Navigation\BreadcrumbHelperService;
use Knp\Component\Pager\PaginatorInterface;
use Pimcore\Twig\Extension\Templating\HeadTitle;
use Pimcore\Twig\Extension\Templating\Placeholder;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\Routing\Annotation\Route;
class SpController extends BaseController
{
const SP_DEFAULT_DOCUMENT_PROPERTY_NAME = 'sp_default_document';
/**
* @param Request $request
*
* @return Response
*
* @throws \Exception
*/
public function listingAction(Request $request, PaginatorInterface $paginator)
{
$spListing = new ServiceProvider\Listing();
$spListing->setOrderKey('title');
$spListing->setOrder('ASC');
$spMembers = Folder::getById(1846);
$spObservers = Folder::getById(1847);
$spPartners = Folder::getById(1848);
$paginator = $paginator->paginate(
$spListing,
$request->get('page', 1),
6
);
return $this->render('sp/listing.html.twig', [
'members' => $spMembers,
'observers' => $spObservers,
'partners' => $spPartners
]);
// return $this->render('sp/listing.html.twig', ['spListing' => $spListing]);
}
/**
* @Route("{path}/{sptitle}-spid{sp}", name="sp-detail", defaults={"path"=""}, requirements={"path"=".*?", "sptitle"="[\w-]+", "sp"="\d+"})
*
* @param Request $request
* @param HeadTitle $headTitleHelper
* @param Placeholder $placeholderHelper
* @param SpLinkGenerator $spLinkGenerator
* @param BreadcrumbHelperService $breadcrumbHelperService
*
* @return Response
*/
public function detailAction(Request $request, HeadTitle $headTitleHelper, Placeholder $placeholderHelper, SpLinkGenerator $spLinkGenerator, BreadcrumbHelperService $breadcrumbHelperService)
{
$sp = ServiceProvider::getById($request->get('sp'));
//$sp = ServiceProvider::getById(4);
if (!($sp instanceof ServiceProvider && ($sp->isPublished() || $this->verifyPreviewRequest($request, $sp)))) {
throw new NotFoundHttpException('Sp not found.');
}
$headTitleHelper($sp->getTitle());
$breadcrumbHelperService->enrichSpPage($sp);
$placeholderHelper('canonical')->set($spLinkGenerator->generate($sp, ['document' => $this->document->getProperty(self::SP_DEFAULT_DOCUMENT_PROPERTY_NAME)]));
return $this->render('sp/detail.html.twig', [
'sp' => $sp
]);
}
}