From cf37eb1af3dd32a40d98994c03bf537d925c0af1 Mon Sep 17 00:00:00 2001 From: Polonkai Gergely Date: Sun, 19 Aug 2012 12:20:39 +0200 Subject: [PATCH] Added sticky flag to News entity Signed-off-by: Gergely Polonkai --- .../Version20120819121254.php | 29 +++++++++++++++++ .../FrontBundle/Controller/NewsController.php | 2 +- src/KekRozsak/FrontBundle/Entity/News.php | 31 +++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 app/DoctrineMigrations/Version20120819121254.php diff --git a/app/DoctrineMigrations/Version20120819121254.php b/app/DoctrineMigrations/Version20120819121254.php new file mode 100644 index 0000000..9ace30c --- /dev/null +++ b/app/DoctrineMigrations/Version20120819121254.php @@ -0,0 +1,29 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); + + $this->addSql("ALTER TABLE news ADD sticky TINYINT(1) NOT NULL"); + $this->addSql("UPDATE news SET sticky = FALSE"); + } + + 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 sticky"); + } +} diff --git a/src/KekRozsak/FrontBundle/Controller/NewsController.php b/src/KekRozsak/FrontBundle/Controller/NewsController.php index 1560f4f..edd9a8d 100644 --- a/src/KekRozsak/FrontBundle/Controller/NewsController.php +++ b/src/KekRozsak/FrontBundle/Controller/NewsController.php @@ -30,7 +30,7 @@ class NewsController extends Controller $searchCriteria['public'] = true; } - $news = $newsRepo->findBy($searchCriteria, array('createdAt' => 'DESC'), 4); + $news = $newsRepo->findBy($searchCriteria, array('sticky' => 'DESC', 'createdAt' => 'DESC'), 4); return array( 'recentNews' => $news, diff --git a/src/KekRozsak/FrontBundle/Entity/News.php b/src/KekRozsak/FrontBundle/Entity/News.php index 4367a73..575eae9 100644 --- a/src/KekRozsak/FrontBundle/Entity/News.php +++ b/src/KekRozsak/FrontBundle/Entity/News.php @@ -197,4 +197,35 @@ class News { return $this->public; } + + /** + * TRUE if this News is "sticky" (it should be visible all the time) + * + * @var boolean $sticky + * + * @ORM\Column(type="boolean", nullable=false) + */ + protected $sticky; + + /** + * Set sticky + * + * @param boolean $sticky + * @return News + */ + public function setSticky($sticky) + { + $this->sticky = $sticky; + return $this; + } + + /** + * Get sticky + * + * @return boolean + */ + public function isSticky() + { + return $this->sticky; + } }