<?php
namespace App\AMZ\Core\Controller;
use App\AMZ\Core\Entity\Category;
use App\AMZ\Core\Entity\Post;
use Doctrine\Persistence\ManagerRegistry;
use Knp\Component\Pager\PaginatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Twig\Environment;
class FrontendController extends AbstractController
{
protected $doctrine;
protected $twig;
protected $paginator;
const THEME = 'ismart';
public function __construct(ManagerRegistry $managerRegistry, Environment $twig, PaginatorInterface $paginator)
{
$this->doctrine = $managerRegistry;
$this->twig = $twig;
$this->paginator = $paginator;
}
protected function getTemplateByCategory(Category $category){
$type = $category->getPostType();
$slug = $category->getSlug();
$tmpType = "default";
$templates = $this->getParameter('templates');
if(isset($templates[$type])){
$tmpType = $templates[$type];
}
$template = 'themes/'.self::THEME.'/post/'.$tmpType.'/category.html.twig';
$categoryTemplate = 'themes/'.self::THEME.'/post/'.$tmpType.'/category/'.$slug.'.html.twig';
if($this->twig->getLoader()->exists($categoryTemplate)){
$template = $categoryTemplate;
}
return $template;
}
protected function getTemplateByPost(Post $post){
$type = $post->getPostType();
$slug = $post->getSlug();
$templates = $this->getParameter('templates');
$tmpType = $templates['default'];
if(isset($templates[$type])){
$tmpType = $templates[$type];
}
$template = 'themes/'.self::THEME.'/post/'.$tmpType.'/detail.html.twig';
$postTemplate = 'themes/'.self::THEME.'/post/'.$tmpType.'/'.$slug.'.html.twig';
if($this->twig->getLoader()->exists($postTemplate)){
$template = $postTemplate;
}
return $template;
}
}