Added a draft property to Post entity
Signed-off-by: Gergely Polonkai (W00d5t0ck) <polesz@w00d5t0ck.info>
This commit is contained in:
parent
773ea55e3d
commit
f16e4c4244
29
app/DoctrineMigrations/Version20120905131921.php
Normal file
29
app/DoctrineMigrations/Version20120905131921.php
Normal file
@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Application\Migrations;
|
||||
|
||||
use Doctrine\DBAL\Migrations\AbstractMigration,
|
||||
Doctrine\DBAL\Schema\Schema;
|
||||
|
||||
/**
|
||||
* Auto-generated Migration: Please modify to your need!
|
||||
*/
|
||||
class Version20120905131921 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 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");
|
||||
}
|
||||
}
|
@ -62,6 +62,7 @@ class AdminController extends Controller
|
||||
}
|
||||
} else {
|
||||
$post = new Post();
|
||||
$post->setDraft(true);
|
||||
}
|
||||
$form = $this->createForm(new PostType(), $post);
|
||||
$request = $this->getRequest();
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ class PostType extends AbstractType
|
||||
{
|
||||
$builder
|
||||
->add('title')
|
||||
->add('draft')
|
||||
->add('content', 'ckeditor')
|
||||
;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user