diff --git a/app/DoctrineMigrations/Version20120915132603.php b/app/DoctrineMigrations/Version20120915132603.php new file mode 100644 index 0000000..54e52c8 --- /dev/null +++ b/app/DoctrineMigrations/Version20120915132603.php @@ -0,0 +1,30 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); + + $this->addSql("CREATE TABLE comments (id INT AUTO_INCREMENT NOT NULL, post_id INT NOT NULL, user_id INT DEFAULT NULL, createdAt DATETIME NOT NULL, subject VARCHAR(150) DEFAULT NULL, hidden TINYINT(1) NOT NULL, content LONGTEXT NOT NULL, INDEX IDX_5F9E962A4B89032C (post_id), INDEX IDX_5F9E962AA76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB"); + $this->addSql("ALTER TABLE comments ADD CONSTRAINT FK_5F9E962A4B89032C FOREIGN KEY (post_id) REFERENCES blog_posts (id)"); + $this->addSql("ALTER TABLE comments ADD CONSTRAINT FK_5F9E962AA76ED395 FOREIGN KEY (user_id) REFERENCES users (id)"); + } + + 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("DROP TABLE comments"); + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Entity/Comment.php b/src/GergelyPolonkai/FrontBundle/Entity/Comment.php new file mode 100644 index 0000000..a42c7ca --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Entity/Comment.php @@ -0,0 +1,198 @@ +id; + } + + /** + * Set createdAt + * + * @param \DateTime $createdAt + * @return Comment + */ + public function setCreatedAt($createdAt) + { + $this->createdAt = $createdAt; + + return $this; + } + + /** + * Get createdAt + * + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * Set subject + * + * @param string $subject + * @return Comment + */ + public function setSubject($subject) + { + $this->subject = $subject; + + return $this; + } + + /** + * Get subject + * + * @return string + */ + public function getSubject() + { + return $this->subject; + } + + /** + * Set hidden + * + * @param boolean $hidden + * @return Comment + */ + public function setHidden($hidden) + { + $this->hidden = $hidden; + + return $this; + } + + /** + * Get hidden + * + * @return boolean + */ + public function getHidden() + { + return $this->hidden; + } + + /** + * Set content + * + * @param string $content + * @return Comment + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * Get content + * + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Set post + * + * @param GergelyPolonkai\FrontBundle\Entity\Post $post + * @return Comment + */ + public function setPost(\GergelyPolonkai\FrontBundle\Entity\Post $post) + { + $this->post = $post; + + return $this; + } + + /** + * Get post + * + * @return GergelyPolonkai\FrontBundle\Entity\Post + */ + public function getPost() + { + return $this->post; + } + + /** + * Set user + * + * @param GergelyPolonkai\FrontBundle\Entity\User $user + * @return Comment + */ + public function setUser(\GergelyPolonkai\FrontBundle\Entity\User $user = null) + { + $this->user = $user; + + return $this; + } + + /** + * Get user + * + * @return GergelyPolonkai\FrontBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Entity/Post.php b/src/GergelyPolonkai/FrontBundle/Entity/Post.php index 39f83dd..d166e70 100644 --- a/src/GergelyPolonkai/FrontBundle/Entity/Post.php +++ b/src/GergelyPolonkai/FrontBundle/Entity/Post.php @@ -6,6 +6,11 @@ use Doctrine\ORM\Mapping as ORM; use Gedmo\Mapping\Annotation as GedmoORM; use Symfony\Component\Validator\Constraints as Assert; +use Doctrine\Common\Collections\ArrayCollection; + +use GergelyPolonkai\FrontBundle\Entity\Comment; +use GergelyPolonkai\FrontBundle\Entity\User; + /** * Description of Post * @@ -73,6 +78,22 @@ class Post */ private $draft; + /** + * + * @var Doctrine\Common\Collections\ArrayCollection $comments + * + * @ORM\OneToMany(targetEntity="Comment", mappedBy="post", fetch="LAZY") + */ + private $comments; + + /** + * Constructor + */ + public function __construct() + { + $this->comments = new ArrayCollection(); + } + /** * Get id * @@ -122,7 +143,7 @@ class Post * @param GergelyPolonkai\FrontBundle\Entity\User $user * @return Post */ - public function setUser(\GergelyPolonkai\FrontBundle\Entity\User $user) + public function setUser(User $user) { $this->user = $user; @@ -191,7 +212,7 @@ class Post * @param \DateTime $createdAt * @return Post */ - public function setCreatedAt($createdAt) + public function setCreatedAt(\DateTime $createdAt) { $this->createdAt = $createdAt; @@ -220,4 +241,36 @@ class Post { return $this->draft; } + /** + * Add comments + * + * @param GergelyPolonkai\FrontBundle\Entity\Comment $comments + * @return Post + */ + public function addComment(Comment $comments) + { + $this->comments[] = $comments; + + return $this; + } + + /** + * Remove comments + * + * @param GergelyPolonkai\FrontBundle\Entity\Comment $comments + */ + public function removeComment(Comment $comments) + { + $this->comments->removeElement($comments); + } + + /** + * Get comments + * + * @return Doctrine\Common\Collections\Collection + */ + public function getComments() + { + return $this->comments; + } } diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Admin/index.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Admin/index.html.twig index b5ca09e..c36d176 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Admin/index.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Admin/index.html.twig @@ -7,4 +7,4 @@ {% block admincontent %} {% endblock %} -{% endblock content %} \ No newline at end of file +{% endblock content %} diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig index c35fd9f..da9c0d1 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/list.html.twig @@ -30,4 +30,4 @@ {% include 'GergelyPolonkaiFrontBundle:Blog:postViewer.html.twig' with {'post': post, 'title_links': true} %} {% endfor %} {{ block('paginator') }} -{% endblock content %} \ No newline at end of file +{% endblock content %} diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/about.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/about.html.twig index 1dc8d22..6586b76 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/about.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/about.html.twig @@ -7,4 +7,4 @@

I'm learning about different IT subjects since the late '90s. These include web development, application building, systems engineering, systems security and many others. I also dug my nose into free software, dealing with different types of Linux and its applications, while also writing and contributing to some open source projects.

On this site I will write blog posts about different stuff I face during work (oh my, yet another IT solutions blog), hoping they can help you with your own, or just to get along with your brand new netbook that shipped with Linux.

Feel free to send me any suggestions on what should I post. I will try my best to provide some help or directions.

-{% endblock content %} \ No newline at end of file +{% endblock content %} diff --git a/src/GergelyPolonkai/FrontBundle/Twig/RandomHeader.php b/src/GergelyPolonkai/FrontBundle/Twig/RandomHeader.php index e6263b2..54ba82b 100644 --- a/src/GergelyPolonkai/FrontBundle/Twig/RandomHeader.php +++ b/src/GergelyPolonkai/FrontBundle/Twig/RandomHeader.php @@ -2,7 +2,6 @@ namespace GergelyPolonkai\FrontBundle\Twig; use JMS\DiExtraBundle\Annotation as DI; -use Symfony\Component\DependencyInjection\ContainerInterface; /** * Description of RandomHeader @@ -45,10 +44,12 @@ class RandomHeader extends \Twig_Extension $files[] = $fn; } } + return $files[array_rand($files)]; } - public function getName() { + public function getName() + { return 'random_header'; } }