News can now be non-public
This commit is contained in:
parent
bf46316347
commit
acc64ee66d
30
app/DoctrineMigrations/Version20120723171539.php
Normal file
30
app/DoctrineMigrations/Version20120723171539.php
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Application\Migrations;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Migrations\AbstractMigration,
|
||||||
|
Doctrine\DBAL\Schema\Schema;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Auto-generated Migration: Please modify to your need!
|
||||||
|
*/
|
||||||
|
class Version20120723171539 extends AbstractMigration
|
||||||
|
{
|
||||||
|
public function up(Schema $schema)
|
||||||
|
{
|
||||||
|
// this up() migration is autogenerated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||||
|
|
||||||
|
$this->addSql("ALTER TABLE news ADD public TINYINT(1) DEFAULT NULL");
|
||||||
|
$this->addSql("UPDATE news SET public = 1");
|
||||||
|
$this->addSql("ALTER TABLE news CHANGE public public TINYINT(1) NOT NULL");
|
||||||
|
}
|
||||||
|
|
||||||
|
public function down(Schema $schema)
|
||||||
|
{
|
||||||
|
// this down() migration is autogenerated, please modify it to your needs
|
||||||
|
$this->abortIf($this->connection->getDatabasePlatform()->getName() != "mysql");
|
||||||
|
|
||||||
|
$this->addSql("ALTER TABLE news DROP public");
|
||||||
|
}
|
||||||
|
}
|
@ -92,7 +92,9 @@
|
|||||||
<div class="hir">
|
<div class="hir">
|
||||||
<p class="hir-cim">{{ news.title }}</p>
|
<p class="hir-cim">{{ news.title }}</p>
|
||||||
<p class="hir-szoveg">{{ news.text|raw }}</p>
|
<p class="hir-szoveg">{{ news.text|raw }}</p>
|
||||||
|
{% if app.user %}
|
||||||
<p class="hir-szerzo">{{ news.createdBy.displayName }}</p>
|
<p class="hir-szerzo">{{ news.createdBy.displayName }}</p>
|
||||||
|
{% endif %}
|
||||||
<p class="hir-datum">{{ news.createdAt|date('Y-m-d H:i') }}</p>
|
<p class="hir-datum">{{ news.createdAt|date('Y-m-d H:i') }}</p>
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
@ -140,4 +140,33 @@ class News
|
|||||||
{
|
{
|
||||||
return $this->createdBy;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
<services>
|
<services>
|
||||||
<service id="kek_rozsak_front.twig_extension.news" class="KekRozsak\FrontBundle\Twig\NewsExtension">
|
<service id="kek_rozsak_front.twig_extension.news" class="KekRozsak\FrontBundle\Twig\NewsExtension">
|
||||||
<argument type="service" id="doctrine" />
|
<argument type="service" id="doctrine" />
|
||||||
|
<argument type="service" id="security.context" />
|
||||||
<tag name="twig.extension" />
|
<tag name="twig.extension" />
|
||||||
</service>
|
</service>
|
||||||
<service id="form.type_extension.help_message" class="KekRozsak\FrontBundle\Form\Extension\HelpMessageTypeExtension">
|
<service id="form.type_extension.help_message" class="KekRozsak\FrontBundle\Form\Extension\HelpMessageTypeExtension">
|
||||||
|
@ -3,20 +3,28 @@
|
|||||||
namespace KekRozsak\FrontBundle\Twig;
|
namespace KekRozsak\FrontBundle\Twig;
|
||||||
|
|
||||||
use Symfony\Bridge\Doctrine\RegistryInterface;
|
use Symfony\Bridge\Doctrine\RegistryInterface;
|
||||||
|
use Symfony\Component\Security\Core\SecurityContextInterface;
|
||||||
|
use Symfony\Component\Security\Core\Authentication\Token\AnonymousToken;
|
||||||
|
|
||||||
class NewsExtension extends \Twig_Extension
|
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()
|
public function getGlobals()
|
||||||
{
|
{
|
||||||
$newsRepo = $this->doctrine->getRepository('KekRozsakFrontBundle:News');
|
$newsRepo = $this->_doctrine->getRepository('KekRozsakFrontBundle:News');
|
||||||
$news = $newsRepo->findBy(array(), array('createdAt' => 'DESC'), 4);
|
$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(
|
return array(
|
||||||
'recentNews' => $news,
|
'recentNews' => $news,
|
||||||
|
Loading…
Reference in New Issue
Block a user