diff --git a/app/DoctrineMigrations/Version20120723171539.php b/app/DoctrineMigrations/Version20120723171539.php
new file mode 100644
index 0000000..5fcd31a
--- /dev/null
+++ b/app/DoctrineMigrations/Version20120723171539.php
@@ -0,0 +1,30 @@
+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");
+ }
+}
diff --git a/app/Resources/views/main_template.html.twig b/app/Resources/views/main_template.html.twig
index 560b604..765f39c 100644
--- a/app/Resources/views/main_template.html.twig
+++ b/app/Resources/views/main_template.html.twig
@@ -92,7 +92,9 @@
{{ news.title }}
{{ news.text|raw }}
+{% if app.user %}
{{ news.createdBy.displayName }}
+{% endif %}
{{ news.createdAt|date('Y-m-d H:i') }}
{% endfor %}
diff --git a/src/KekRozsak/FrontBundle/Entity/News.php b/src/KekRozsak/FrontBundle/Entity/News.php
index 81c6dd9..f0ae6aa 100644
--- a/src/KekRozsak/FrontBundle/Entity/News.php
+++ b/src/KekRozsak/FrontBundle/Entity/News.php
@@ -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;
+ }
}
diff --git a/src/KekRozsak/FrontBundle/Resources/config/services.xml b/src/KekRozsak/FrontBundle/Resources/config/services.xml
index 853a6d1..e6e6826 100644
--- a/src/KekRozsak/FrontBundle/Resources/config/services.xml
+++ b/src/KekRozsak/FrontBundle/Resources/config/services.xml
@@ -4,6 +4,7 @@
+
diff --git a/src/KekRozsak/FrontBundle/Twig/NewsExtension.php b/src/KekRozsak/FrontBundle/Twig/NewsExtension.php
index 506cf4a..491b428 100644
--- a/src/KekRozsak/FrontBundle/Twig/NewsExtension.php
+++ b/src/KekRozsak/FrontBundle/Twig/NewsExtension.php
@@ -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,