diff --git a/app/AppKernel.php b/app/AppKernel.php index cbcd68a..eb09665 100644 --- a/app/AppKernel.php +++ b/app/AppKernel.php @@ -20,7 +20,9 @@ class AppKernel extends Kernel new JMS\AopBundle\JMSAopBundle(), new JMS\DiExtraBundle\JMSDiExtraBundle($this), new JMS\SecurityExtraBundle\JMSSecurityExtraBundle(), - new Io\TcpdfBundle\IoTcpdfBundle(), + new Io\TcpdfBundle\IoTcpdfBundle(), + new Stof\DoctrineExtensionsBundle\StofDoctrineExtensionsBundle(), + new Doctrine\Bundle\MigrationsBundle\DoctrineMigrationsBundle(), new GergelyPolonkai\FrontBundle\GergelyPolonkaiFrontBundle(), new GergelyPolonkai\GeshiBundle\GergelyPolonkaiGeshiBundle(), ); diff --git a/app/DoctrineMigrations/Version20120904115727.php b/app/DoctrineMigrations/Version20120904115727.php new file mode 100644 index 0000000..d6f19ec --- /dev/null +++ b/app/DoctrineMigrations/Version20120904115727.php @@ -0,0 +1,32 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != "mysql"); + + $this->addSql("CREATE TABLE users (id INT AUTO_INCREMENT NOT NULL, username VARCHAR(50) NOT NULL, name VARCHAR(100) NOT NULL, UNIQUE INDEX UNIQ_1483A5E9F85E0677 (username), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB"); + $this->addSql("CREATE TABLE blog_posts (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, title VARCHAR(100) NOT NULL, slug VARCHAR(100) NOT NULL, content LONGTEXT NOT NULL, created_at DATETIME NOT NULL, INDEX IDX_78B2F932A76ED395 (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci ENGINE = InnoDB"); + $this->addSql("ALTER TABLE blog_posts ADD CONSTRAINT FK_78B2F932A76ED395 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("ALTER TABLE blog_posts DROP FOREIGN KEY FK_78B2F932A76ED395"); + $this->addSql("DROP TABLE users"); + $this->addSql("DROP TABLE blog_posts"); + } +} diff --git a/app/config/config.yml b/app/config/config.yml index 70b76a9..b41bb37 100644 --- a/app/config/config.yml +++ b/app/config/config.yml @@ -57,3 +57,15 @@ swiftmailer: username: %mailer_user% password: %mailer_password% spool: { type: memory } + +jms_di_extra: + locations: + all_bundles: false + bundles: [ GergelyPolonkaiFrontBundle ] + +stof_doctrine_extensions: + default_locale: en_US + orm: + default: + sluggable: true + timestampable: true \ No newline at end of file diff --git a/app/config/parameters.yml b/app/config/parameters.yml index 6f0c6ee..0da2335 100644 --- a/app/config/parameters.yml +++ b/app/config/parameters.yml @@ -2,9 +2,9 @@ parameters: database_driver: pdo_mysql database_host: localhost database_port: ~ - database_name: symfony - database_user: root - database_password: ~ + database_name: gergelypolonkai + database_user: gergelypolonkai + database_password: the8dooM mailer_transport: smtp mailer_host: localhost @@ -12,4 +12,4 @@ parameters: mailer_password: ~ locale: en - secret: ThisTokenIsNotSoSecretChangeIt + secret: rie5chooqu8oche5ha6Keidop3ahxoob diff --git a/composer.json b/composer.json index db5f94f..7f47d0b 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,8 @@ "jms/security-extra-bundle": "1.2.*", "jms/di-extra-bundle": "1.1.*", "easybook/geshi": "dev-master", + "stof/doctrine-extensions-bundle": "dev-master", + "doctrine/doctrine-migrations-bundle": "dev-master", "gergelypolonkai/tcpdfbundle": "dev-master" }, "scripts": { diff --git a/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php new file mode 100644 index 0000000..181bc77 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Controller/BlogController.php @@ -0,0 +1,41 @@ +setDate($year, $month, $day); + $date->setTime(0, 0, 0); + $date2 = new \DateTime(); + $date2->setDate($year, $month, $day); + $date2->setTime(0, 0, 0); + $date2->add(new \DateInterval('P1D')); + + $query = $this->getDoctrine()->getEntityManager()->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p WHERE p.slug = :slug AND p.createdAt BETWEEN :date1 AND :date2"); + $query->setParameter(':slug', $slug); + $query->setParameter(':date1', $date); + $query->setParameter(':date2', $date2); + $post = $query->getOneOrNullResult(); + + return array( + 'post' => $post, + ); + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php index d12d8c9..20b1894 100644 --- a/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php +++ b/src/GergelyPolonkai/FrontBundle/Controller/DefaultController.php @@ -17,7 +17,13 @@ class DefaultController extends Controller */ public function indexAction() { - return array(); + $query = $this->getDoctrine()->getEntityManager()->createQuery("SELECT p FROM GergelyPolonkaiFrontBundle:Post p ORDER BY p.createdAt DESC"); + $query->setMaxResults(4); + $posts = $query->getResult(); + + return array( + 'posts' => $posts, + ); } /** @@ -30,7 +36,7 @@ class DefaultController extends Controller } /** - * @param string $_format + * @param string $_format * * @Route("/resume.{_format}", name="GergelyPolonkaiFrontBundle_resume") * @Template diff --git a/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php b/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php index 286ed20..9af3dba 100644 --- a/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php +++ b/src/GergelyPolonkai/FrontBundle/DependencyInjection/Configuration.php @@ -23,7 +23,6 @@ class Configuration implements ConfigurationInterface // Here you should define the parameters that are allowed to // configure your bundle. See the documentation linked above for // more information on that topic. - return $treeBuilder; } } diff --git a/src/GergelyPolonkai/FrontBundle/Entity/Post.php b/src/GergelyPolonkai/FrontBundle/Entity/Post.php new file mode 100644 index 0000000..82b91b8 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Entity/Post.php @@ -0,0 +1,163 @@ +id; + } + + /** + * Set title + * + * @param string $title + * @return Post + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get title + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Get slug + * + * @return string + */ + public function getSlug() + { + return $this->slug; + } + + /** + * Set user + * + * @param GergelyPolonkai\FrontBundle\Entity\User $user + * @return Post + */ + public function setUser(\GergelyPolonkai\FrontBundle\Entity\User $user) + { + $this->user = $user; + + return $this; + } + + /** + * Get user + * + * @return GergelyPolonkai\FrontBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } + + /** + * Set content + * + * @param string $content + * @return Post + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * Get content + * + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Get createdAt + * + * @return \DateTime + */ + public function getCreatedAt() + { + return $this->createdAt; + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Entity/User.php b/src/GergelyPolonkai/FrontBundle/Entity/User.php new file mode 100644 index 0000000..0bc5f30 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Entity/User.php @@ -0,0 +1,88 @@ +id; + } + + /** + * Set username + * + * @param string $username + * @return User + */ + public function setUsername($username) + { + $this->username = $username; + + return $this; + } + + /** + * Get username + * + * @return string + */ + public function getUsername() + { + return $this->username; + } + + /** + * Set name + * + * @param string $name + * @return User + */ + public function setName($name) + { + $this->name = $name; + + return $this; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } +} diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/viewPost.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/viewPost.html.twig new file mode 100644 index 0000000..2cfd600 --- /dev/null +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Blog/viewPost.html.twig @@ -0,0 +1,6 @@ +{% extends 'GergelyPolonkaiFrontBundle:Default:front_base.html.twig' %} +{% block content %} +
{{ post.createdAt|date('m-d-Y :: H:i') }} by {{ post.user.name }}
+{{ post.content|raw }} +{% endblock content %} diff --git a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig index 1ae49c9..14139c6 100644 --- a/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig +++ b/src/GergelyPolonkai/FrontBundle/Resources/views/Default/front_base.html.twig @@ -42,4 +42,3 @@