2012-07-03 16:05:09 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace KekRozsak\FrontBundle\Twig;
|
|
|
|
|
|
|
|
use Symfony\Bridge\Doctrine\RegistryInterface;
|
2012-07-23 15:50:40 +00:00
|
|
|
use Symfony\Component\Security\Core\SecurityContextInterface;
|
2012-07-03 16:05:09 +00:00
|
|
|
|
|
|
|
class NewsExtension extends \Twig_Extension
|
|
|
|
{
|
2012-07-23 15:50:40 +00:00
|
|
|
protected $_doctrine;
|
|
|
|
protected $_securityContext;
|
2012-07-03 16:05:09 +00:00
|
|
|
|
2012-07-23 15:50:40 +00:00
|
|
|
public function __construct(RegistryInterface $doctrine, SecurityContextInterface $securityContext)
|
2012-07-03 16:05:09 +00:00
|
|
|
{
|
2012-07-23 15:50:40 +00:00
|
|
|
$this->_doctrine = $doctrine;
|
|
|
|
$this->_securityContext = $securityContext;
|
2012-07-03 16:05:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getGlobals()
|
|
|
|
{
|
2012-07-23 15:50:40 +00:00
|
|
|
$newsRepo = $this->_doctrine->getRepository('KekRozsakFrontBundle:News');
|
|
|
|
$searchCriteria = array();
|
2012-07-23 16:23:13 +00:00
|
|
|
if (!is_object($this->_securityContext->getToken()) || !is_object($this->_securityContext->getToken()->getUser()))
|
2012-07-23 15:50:40 +00:00
|
|
|
$searchCriteria['public'] = true;
|
|
|
|
|
|
|
|
$news = $newsRepo->findBy($searchCriteria, array('createdAt' => 'DESC'), 4);
|
2012-07-03 16:05:09 +00:00
|
|
|
|
|
|
|
return array(
|
|
|
|
'recentNews' => $news,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return 'News';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|