News can now be non-public

This commit is contained in:
Polonkai Gergely
2012-07-23 17:50:40 +02:00
parent bf46316347
commit acc64ee66d
5 changed files with 75 additions and 5 deletions

View File

@@ -140,4 +140,33 @@ class News
{
return $this->createdBy;
}
/**
* @var boolean $public
*
* @ORM\Column(type="boolean", nullable=false)
*/
protected $public;
/**
* Set public
*
* @param boolean $public
* @return News
*/
public function setPublic($public)
{
$this->public = $public;
return $this;
}
/**
* Get public
*
* @return boolean
*/
public function getPublic()
{
return $this->public;
}
}

View File

@@ -4,6 +4,7 @@
<services>
<service id="kek_rozsak_front.twig_extension.news" class="KekRozsak\FrontBundle\Twig\NewsExtension">
<argument type="service" id="doctrine" />
<argument type="service" id="security.context" />
<tag name="twig.extension" />
</service>
<service id="form.type_extension.help_message" class="KekRozsak\FrontBundle\Form\Extension\HelpMessageTypeExtension">

View File

@@ -3,20 +3,28 @@
namespace KekRozsak\FrontBundle\Twig;
use Symfony\Bridge\Doctrine\RegistryInterface;
use Symfony\Component\Security\Core\SecurityContextInterface;
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
class NewsExtension extends \Twig_Extension
{
protected $doctrine;
protected $_doctrine;
protected $_securityContext;
public function __construct(RegistryInterface $doctrine)
public function __construct(RegistryInterface $doctrine, SecurityContextInterface $securityContext)
{
$this->doctrine = $doctrine;
$this->_doctrine = $doctrine;
$this->_securityContext = $securityContext;
}
public function getGlobals()
{
$newsRepo = $this->doctrine->getRepository('KekRozsakFrontBundle:News');
$news = $newsRepo->findBy(array(), array('createdAt' => 'DESC'), 4);
$newsRepo = $this->_doctrine->getRepository('KekRozsakFrontBundle:News');
$searchCriteria = array();
if (!$this->_securityContext->getToken() instanceof Symfony\Component\Security\Core\Authentication\Token\AnonymousToken)
$searchCriteria['public'] = true;
$news = $newsRepo->findBy($searchCriteria, array('createdAt' => 'DESC'), 4);
return array(
'recentNews' => $news,