From f16e4c42441e02671f9b7c26d13c795f167da1e1 Mon Sep 17 00:00:00 2001 From: "Gergely Polonkai (W00d5t0ck)" Date: Wed, 5 Sep 2012 13:23:03 +0200 Subject: [PATCH] Added a draft property to Post entity Signed-off-by: Gergely Polonkai (W00d5t0ck) --- .../Version20120905131921.php | 29 +++++++++++++++++ .../Controller/AdminController.php | 1 + .../Controller/DefaultController.php | 2 +- .../FrontBundle/Entity/Post.php | 31 +++++++++++++++++++ .../FrontBundle/Form/PostType.php | 1 + 5 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 app/DoctrineMigrations/Version20120905131921.php diff --git a/app/DoctrineMigrations/Version20120905131921.php b/app/DoctrineMigrations/Version20120905131921.php new file mode 100644 index 0000000..6307908 --- /dev/null +++ b/app/DoctrineMigrations/Version20120905131921.php @@ -0,0 +1,29 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); + + $this->addSql("ALTER TABLE blog_posts ADD draft TINYINT(1) NOT NULL"); + $this->addSql("UPDATE blog_posts SET draft = 0"); + } + + 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 blog_posts DROP draft"); + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php b/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php index 96e9ac6..d6f6f49 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/AdminController.php @@ -62,6 +62,7 @@ class AdminController extends Controller } } else { $post = new Post(); + $post->setDraft(true); } $form = $this->createForm(new PostType(), $post); $request = $this->getRequest(); diff --git a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php index 066613e..84b8720 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php @@ -20,7 +20,7 @@ class DefaultController extends Controller */ public function indexAction() { - $query = $this->getDoctrine()->getEntityManager()->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p ORDER BY p.createdAt DESC"); + $query = $this->getDoctrine()->getEntityManager()->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p WHERE p.draft = FALSE ORDER BY p.createdAt DESC"); $query->setMaxResults(4); $posts = $query->getResult(); diff --git a/src/GergelyPolonkai/FrontBundle/Entity/Post.php b/src/GergelyPolonkai/FrontBundle/Entity/Post.php index 7137901..39f83dd 100644 --- a/src/GergelyPolonkai/FrontBundle/Entity/Post.php +++ b/src/GergelyPolonkai/FrontBundle/Entity/Post.php @@ -65,6 +65,14 @@ class Post */ private $createdAt; + /** + * + * @var boolean $draft + * + * @ORM\Column(type="boolean") + */ + private $draft; + /** * Get id * @@ -189,4 +197,27 @@ class Post return $this; } + + /** + * Set draft + * + * @param boolean $draft + * @return Post + */ + public function setDraft($draft) + { + $this->draft = $draft; + + return $this; + } + + /** + * Get draft + * + * @return boolean + */ + public function getDraft() + { + return $this->draft; + } } diff --git a/src/GergelyPolonkai/FrontBundle/Form/PostType.php b/src/GergelyPolonkai/FrontBundle/Form/PostType.php index a8a2289..2e97aac 100644 --- a/src/GergelyPolonkai/FrontBundle/Form/PostType.php +++ b/src/GergelyPolonkai/FrontBundle/Form/PostType.php @@ -12,6 +12,7 @@ class PostType extends AbstractType { $builder ->add('title') + ->add('draft') ->add('content', 'ckeditor') ; }