From e0e0431a27a003ee2890c1180fa8c9bfc38dde17 Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Mon, 11 Jun 2012 22:09:57 -0400 Subject: [PATCH 01/11] WIP --- Manager/AbstractManager.php | 37 ++++++++++++++++++++++++++++++++ Manager/CommentManager.php | 30 ++++++++++++++++++++++++++ Manager/PostManager.php | 30 ++++++++++++++++++++++++++ PSSBlogBundleEvent.php | 20 +++++++++++++++++ Repository/CommentRepository.php | 11 ++++++++++ 5 files changed, 128 insertions(+) create mode 100644 Manager/AbstractManager.php create mode 100644 Manager/CommentManager.php create mode 100644 Manager/PostManager.php create mode 100644 PSSBlogBundleEvent.php create mode 100644 Repository/CommentRepository.php diff --git a/Manager/AbstractManager.php b/Manager/AbstractManager.php new file mode 100644 index 0000000..005851e --- /dev/null +++ b/Manager/AbstractManager.php @@ -0,0 +1,37 @@ +dispatcher = $dispatcher; + $this->em = $em; + } +} \ No newline at end of file diff --git a/Manager/CommentManager.php b/Manager/CommentManager.php new file mode 100644 index 0000000..d03951f --- /dev/null +++ b/Manager/CommentManager.php @@ -0,0 +1,30 @@ + Date: Mon, 11 Jun 2012 23:08:41 -0400 Subject: [PATCH 02/11] WIP --- Controller/BlogController.php | 92 ++++++++++++++----- Entity/Post.php | 53 +++++++++++ Manager/AbstractManager.php | 9 +- Manager/CommentManager.php | 1 + Manager/PostManager.php | 12 +++ Resources/config/services.yml | 19 +++- .../doc/recipe-extending-blog-controller.md | 0 Resources/doc/recipe-extending-blog.md | 7 ++ Resources/views/Blog/postsList.html.twig | 4 +- Resources/views/Blog/recentPosts.html.twig | 2 +- Twig/Extension/ContentExtension.php | 30 ++++++ 11 files changed, 199 insertions(+), 30 deletions(-) create mode 100644 Resources/doc/recipe-extending-blog-controller.md create mode 100644 Resources/doc/recipe-extending-blog.md diff --git a/Controller/BlogController.php b/Controller/BlogController.php index c79a978..64eb13f 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -2,25 +2,67 @@ namespace PSS\Bundle\BlogBundle\Controller; + +# Symfony/Doctrine internal use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; +use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; + + +# Specific + + +# Domain objects + +# Entities +use PSS\Bundle\BlogBundle\Entity\Post; + + + +/** + * Base Controller + * + * Basic views available here, to override you can + * use the PostManager service. The idea of this controller + * is that you can extend as a Base, and alter the returned array() + * that each method returns using parent::methodName(); + * + * Cookbook in @PSSBlogBundle/Resources/doc/recipe-extending-blog-controller.md + * + * @Route("/blog") + */ class BlogController extends Controller { + + + + /** - * @Route("/blog", name="blog_index") + * @Route("/{year}/{month}/{slug}", name="blog_show") + * @Template() */ - public function indexAction() + public function showAction(Post $post) { - $entityManager = $this->get('doctrine.orm.entity_manager'); + return array( + 'post' => $post->onlyIfPublished() + ); + } - $query = $entityManager - ->getRepository('PSS\Bundle\BlogBundle\Entity\Post') - ->getPublishedPostsQuery(); - $paginator = $this->createPaginator($query); + /** + * @Route("/", name="blog_index") + * @Template() + */ + public function indexAction() + { + $pm = $this->getPostManager(); + $paginator = $this->createPaginator($pm->getPublishedQuery()); - return $this->render('PSSBlogBundle:Blog:index.html.twig', array('paginator' => $paginator)); + return array( + 'pm' => $pm, + 'paginator' => $paginator + ); } /** @@ -43,23 +85,7 @@ public function postsByTagAction($tag) return $this->render('PSSBlogBundle:Blog:postsByTag.html.twig', array('paginator' => $paginator)); } - /** - * @Route("/{slug}", name="blog_show") - */ - public function showAction($slug) - { - $entityManager = $this->get('doctrine.orm.entity_manager'); - - try { - $post = $entityManager - ->getRepository('PSS\Bundle\BlogBundle\Entity\Post') - ->findPublishedPostOrPage($slug); - } catch (\Doctrine\ORM\NoResultException $exception) { - throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException('Page Not Found'); - } - return $this->render('PSSBlogBundle:Blog:show.html.twig', array('post' => $post)); - } public function recentPostsAction($max) { @@ -85,12 +111,28 @@ public function tagCloudAction() return $this->render('PSSBlogBundle:Blog:tagCloud.html.twig', array('tagCloud' => $tagCloud)); } + + + /** + * Access to Post Manager service + * + * @return \PSS\Bundle\BlogBundle\Manager\PostManager + */ + protected function getPostManager() + { + return $this->get('pss.blog.manager.post'); + } + + + /** + * Create a paginator from a Query + * * @param \Doctrine\ORM\Query $query * * @return \Knp\Component\Pager\Pagination\PaginationInterface */ - private function createPaginator(\Doctrine\ORM\Query $query) + protected function createPaginator(\Doctrine\ORM\Query $query) { $paginator = $this->get('knp_paginator'); $request = $this->get('request'); diff --git a/Entity/Post.php b/Entity/Post.php index 63d280c..6a6895a 100755 --- a/Entity/Post.php +++ b/Entity/Post.php @@ -2,8 +2,25 @@ namespace PSS\Bundle\BlogBundle\Entity; + +# Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +# Specific + + +# Domain objects + + +# Entities + + +# Exceptions +use \Symfony\Component\HttpKernel\Exception\NotFoundHttpException; + + + /** * @ORM\Table(name="wp_posts") * @ORM\Entity(repositoryClass="PSS\Bundle\BlogBundle\Repository\PostRepository") @@ -256,4 +273,40 @@ public function getTitle() { return $this->title; } + + + /** + * @return integer + */ + public function getYear() + { + $date = $this->getPublishedAt(); + return $date->format('Y'); + } + + + /** + * @return integer + */ + public function getMonth() + { + $date = $this->getPublishedAt(); + return $date->format('m'); + } + + + + /** + * Validate if post is set as published + * + * @return Post The post + * @throws NotFoundHttpException If post status is NOT to "publish" + */ + public function onlyIfPublished(){ + if($this->status != static::STATUS_PUBLISH) + { + throw new NotFoundHttpException('Page Not Found'); + } + return $this; + } } diff --git a/Manager/AbstractManager.php b/Manager/AbstractManager.php index 005851e..b02a053 100644 --- a/Manager/AbstractManager.php +++ b/Manager/AbstractManager.php @@ -4,7 +4,7 @@ # Symfony/Doctrine internal use Doctrine\ORM\EntityManager; -use Symfony\Component\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\EventDispatcher; # Specific @@ -34,4 +34,11 @@ public function __construct(EventDispatcher $dispatcher, EntityManager $em) $this->dispatcher = $dispatcher; $this->em = $em; } + + protected function getRepository($name=null) + { + $entityName = ($name === null)?static::CLASSNAME:$name; + $repository = $this->em->getRepository($entityName); + return $repository; + } } \ No newline at end of file diff --git a/Manager/CommentManager.php b/Manager/CommentManager.php index d03951f..486ecca 100644 --- a/Manager/CommentManager.php +++ b/Manager/CommentManager.php @@ -26,5 +26,6 @@ class CommentManager extends AbstractManager { const CLASSNAME = 'PSS\Bundle\BlogBundle\Entity\Comment'; + const SHORTCUT = 'PSSBlogBundle:Comment'; } \ No newline at end of file diff --git a/Manager/PostManager.php b/Manager/PostManager.php index 2ef5177..0fcfc5a 100644 --- a/Manager/PostManager.php +++ b/Manager/PostManager.php @@ -26,5 +26,17 @@ class PostManager extends AbstractManager { const CLASSNAME = 'PSS\Bundle\BlogBundle\Entity\Post'; + const SHORTCUT = 'PSSBlogBundle:Post'; + + public function getPublishedQuery(){ + $query = $this->getRepository()->getPublishedPostsQuery(); + return $query; + } + + public function getHilighted() + { + $array = $this->getPublishedQuery()->setMaxResults(3)->getResult(); + return new \Doctrine\Common\Collections\ArrayCollection($array); + } } \ No newline at end of file diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 69696f5..6a60c2f 100755 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -1,6 +1,23 @@ +parameters: + pss.blog.manager.post.class: PSS\Bundle\BlogBundle\Manager\PostManager + pss.blog.manager.comment.class: PSS\Bundle\BlogBundle\Manager\CommentManager + pss.twig.extension.content.class: PSS\Bundle\BlogBundle\Twig\Extension\ContentExtension + services: pss.twig.extension.content: - class: PSS\Bundle\BlogBundle\Twig\Extension\ContentExtension + class: %pss.twig.extension.content.class% public: false tags: - { name: twig.extension } + + + pss.blog.manager.entity.abstract: + abstract: true + arguments: + dispatcher: '@event_dispatcher' + em: '@doctrine.orm.entity_manager' + + + pss.blog.manager.post: + parent: pss.blog.manager.entity.abstract + class: %pss.blog.manager.post.class% \ No newline at end of file diff --git a/Resources/doc/recipe-extending-blog-controller.md b/Resources/doc/recipe-extending-blog-controller.md new file mode 100644 index 0000000..e69de29 diff --git a/Resources/doc/recipe-extending-blog.md b/Resources/doc/recipe-extending-blog.md new file mode 100644 index 0000000..8167299 --- /dev/null +++ b/Resources/doc/recipe-extending-blog.md @@ -0,0 +1,7 @@ +HOW TO EXTEND BLOG CONTROLLER TO SUIT WITH SPECIFIC QUERIES + +#TODO: ... to write... + +=Topic: Table of contents + * Introduction + * Adding your own views diff --git a/Resources/views/Blog/postsList.html.twig b/Resources/views/Blog/postsList.html.twig index 3c798d4..7730169 100644 --- a/Resources/views/Blog/postsList.html.twig +++ b/Resources/views/Blog/postsList.html.twig @@ -1,10 +1,10 @@ {% for post in paginator %} -

{{ post.title }}

+

{{ post.title }}

{% if post.excerpt %} {{ post.excerpt | autop | raw }} {% else %} - {% set moreLink = '' ~ '» Read more' | trans ~ '' %} + {% set moreLink = '' ~ '» Read more' | trans ~ '' %} {{ post.content | autop | more(moreLink) | raw }} {% endif %}
diff --git a/Resources/views/Blog/recentPosts.html.twig b/Resources/views/Blog/recentPosts.html.twig index 4cfb340..6e20543 100644 --- a/Resources/views/Blog/recentPosts.html.twig +++ b/Resources/views/Blog/recentPosts.html.twig @@ -1,6 +1,6 @@

Recent posts

diff --git a/Twig/Extension/ContentExtension.php b/Twig/Extension/ContentExtension.php index 193f403..2160eae 100755 --- a/Twig/Extension/ContentExtension.php +++ b/Twig/Extension/ContentExtension.php @@ -8,6 +8,7 @@ public function getFilters() { return array( 'autop' => new \Twig_Filter_Method($this, 'autop'), + 'summarize' => new \Twig_Filter_Method($this, 'summarize'), 'more' => new \Twig_Filter_Method($this, 'cutToMoreTag') ); } @@ -112,4 +113,33 @@ protected static function cleanPre($matches) return $text; } + + /** + * Create a summary based on the first letters + * + * Escapes HTML and creates a resume on $numb characters + * in the possibility the $numb's letter in in the middle of + * a word, it adjusts to take up to the end of the word. + * + * Taken from php.net example + * + * @param string $text Content text + * @param int $numb Content length + * @param string $etc How you want it to mark the end (default: "...") + * @return integer $max + */ + public function summarize($text, $numb = 200, $etc = "...") + { + $text = strip_tags($text); + if (strlen($text) > $numb) { + $text = mb_substr($text, 0, $numb); + $text = mb_substr($text,0,strrpos($text," ")); + //This strips the full stop: + if ((mb_substr($text, -1)) == ".") { + $text = mb_substr($text,0,(mb_strrpos($text,"."))); + } + $text = $text.$etc; + } + return $text; + } } From f3d05e5c736a14070b3da7684a73a61ebee8898a Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Sun, 17 Jun 2012 20:54:09 -0400 Subject: [PATCH 03/11] WIP --- Controller/BlogController.php | 14 ++++++------- Manager/AbstractManager.php | 3 ++- Manager/PostManager.php | 12 ----------- Repository/AbstractRepository.php | 35 +++++++++++++++++++++++++++++++ Repository/CommentRepository.php | 14 ++++++++++++- Repository/PostRepository.php | 28 ++++++++++++++++++++++++- Repository/TermRepository.php | 14 ++++++++++++- Resources/config/services.yml | 7 ++++++- 8 files changed, 103 insertions(+), 24 deletions(-) create mode 100644 Repository/AbstractRepository.php diff --git a/Controller/BlogController.php b/Controller/BlogController.php index 64eb13f..0f02321 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -17,6 +17,7 @@ # Entities use PSS\Bundle\BlogBundle\Entity\Post; +use PSS\Bundle\BlogBundle\Entity\Tag; @@ -57,24 +58,23 @@ public function showAction(Post $post) public function indexAction() { $pm = $this->getPostManager(); - $paginator = $this->createPaginator($pm->getPublishedQuery()); + $paginator = $this->createPaginator($pm->getRepository()->getPublishedPostsQuery()); return array( - 'pm' => $pm, 'paginator' => $paginator ); } /** - * @Route("/tag/{tag}", name="blog_posts_by_tag") + * @Route("/tag/{name}", name="blog_posts_by_tag") */ - public function postsByTagAction($tag) + public function postsByTagAction(Tag $tag) { $entityManager = $this->get('doctrine.orm.entity_manager'); - $query = $entityManager - ->getRepository('PSS\Bundle\BlogBundle\Entity\Post') - ->getPublishedPostsByTagQuery($tag); + $pm = $this->getPostManager() + ->getRepository() + ->getPublishedPostsByTagQuery($tag->getName()); $paginator = $this->createPaginator($query); diff --git a/Manager/AbstractManager.php b/Manager/AbstractManager.php index b02a053..c3ca50b 100644 --- a/Manager/AbstractManager.php +++ b/Manager/AbstractManager.php @@ -35,7 +35,8 @@ public function __construct(EventDispatcher $dispatcher, EntityManager $em) $this->em = $em; } - protected function getRepository($name=null) + + public function getRepository($name=null) { $entityName = ($name === null)?static::CLASSNAME:$name; $repository = $this->em->getRepository($entityName); diff --git a/Manager/PostManager.php b/Manager/PostManager.php index 0fcfc5a..f2b79dc 100644 --- a/Manager/PostManager.php +++ b/Manager/PostManager.php @@ -27,16 +27,4 @@ class PostManager extends AbstractManager { const CLASSNAME = 'PSS\Bundle\BlogBundle\Entity\Post'; const SHORTCUT = 'PSSBlogBundle:Post'; - - - public function getPublishedQuery(){ - $query = $this->getRepository()->getPublishedPostsQuery(); - return $query; - } - - public function getHilighted() - { - $array = $this->getPublishedQuery()->setMaxResults(3)->getResult(); - return new \Doctrine\Common\Collections\ArrayCollection($array); - } } \ No newline at end of file diff --git a/Repository/AbstractRepository.php b/Repository/AbstractRepository.php new file mode 100644 index 0000000..043dc23 --- /dev/null +++ b/Repository/AbstractRepository.php @@ -0,0 +1,35 @@ +getResult(); } + + /** * @return Doctrine\ORM\Query */ @@ -64,6 +81,8 @@ public function getPublishedPostsByTagQuery($tagSlug) return $query; } + + /** * @param string $slug * @return PSS\Bundle\BlogBundle\Entity\Post @@ -84,4 +103,11 @@ public function findPublishedPostOrPage($slug) return $query->getSingleResult(); } + + + + public function getPublishedPosts() + { + return $this->toCollection($this->getPublishedPostsQuery()->getResults()); + } } diff --git a/Repository/TermRepository.php b/Repository/TermRepository.php index 0c38156..5ea483d 100755 --- a/Repository/TermRepository.php +++ b/Repository/TermRepository.php @@ -2,10 +2,22 @@ namespace PSS\Bundle\BlogBundle\Repository; +# Symfony/Doctrine internal use Doctrine\ORM\EntityRepository; + + +# Specific + + +# Domain objects + + +# Entities use PSS\Bundle\BlogBundle\Entity\TermTaxonomy; -class TermRepository extends EntityRepository + + +class TermRepository extends AbstractRepository { /** * @return array diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 6a60c2f..72bb5bf 100755 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -20,4 +20,9 @@ services: pss.blog.manager.post: parent: pss.blog.manager.entity.abstract - class: %pss.blog.manager.post.class% \ No newline at end of file + class: %pss.blog.manager.post.class% + + + pss.blog.manager.comment: + parent: pss.blog.manager.entity.abstract + class: %pss.blog.manager.comment.class% \ No newline at end of file From b9a7330dbbd7cefb4128ed4920342771f97f1117 Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Sun, 17 Jun 2012 21:47:43 -0400 Subject: [PATCH 04/11] WIP --- Controller/BlogController.php | 15 ++++++++------- Repository/AbstractRepository.php | 2 -- Repository/CommentRepository.php | 2 -- Repository/PostRepository.php | 7 ------- 4 files changed, 8 insertions(+), 18 deletions(-) diff --git a/Controller/BlogController.php b/Controller/BlogController.php index 0f02321..d9d3f50 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -66,23 +66,24 @@ public function indexAction() } /** - * @Route("/tag/{name}", name="blog_posts_by_tag") + * @Route("/tag/{tag}", name="blog_posts_by_tag") + * @Template() */ - public function postsByTagAction(Tag $tag) + public function postsByTagAction($tag) { $entityManager = $this->get('doctrine.orm.entity_manager'); - $pm = $this->getPostManager() - ->getRepository() - ->getPublishedPostsByTagQuery($tag->getName()); + $repository = $this->getPostManager()->getRepository(); - $paginator = $this->createPaginator($query); + $paginator = $this->createPaginator($repository->getPublishedPostsByTagQuery($tag)); if ($paginator->getTotalItemCount() == 0) { throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException('Page Not Found'); } - return $this->render('PSSBlogBundle:Blog:postsByTag.html.twig', array('paginator' => $paginator)); + return array( + 'paginator' => $paginator + ); } diff --git a/Repository/AbstractRepository.php b/Repository/AbstractRepository.php index 043dc23..b0af972 100644 --- a/Repository/AbstractRepository.php +++ b/Repository/AbstractRepository.php @@ -14,8 +14,6 @@ # Entities -use PSS\Bundle\BlogBundle\Entity\TermTaxonomy; -use PSS\Bundle\BlogBundle\Entity\Post; diff --git a/Repository/CommentRepository.php b/Repository/CommentRepository.php index e1b6c5e..14e125f 100644 --- a/Repository/CommentRepository.php +++ b/Repository/CommentRepository.php @@ -3,7 +3,6 @@ namespace PSS\Bundle\BlogBundle\Repository; # Symfony/Doctrine internal -use Doctrine\ORM\EntityRepository; # Specific @@ -13,7 +12,6 @@ # Entities -use PSS\Bundle\BlogBundle\Entity\Post; diff --git a/Repository/PostRepository.php b/Repository/PostRepository.php index ef169bd..8908acc 100755 --- a/Repository/PostRepository.php +++ b/Repository/PostRepository.php @@ -103,11 +103,4 @@ public function findPublishedPostOrPage($slug) return $query->getSingleResult(); } - - - - public function getPublishedPosts() - { - return $this->toCollection($this->getPublishedPostsQuery()->getResults()); - } } From 15708c7137834a02aabe900f208fe98eb624b862 Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Wed, 20 Jun 2012 01:12:17 -0400 Subject: [PATCH 05/11] Adding some helpers to debug and convert QueryBuilder to Query --- Repository/AbstractRepository.php | 55 +++++++++++++++++++++++++++++-- Repository/PostRepository.php | 42 ++++++++++++++++------- 2 files changed, 84 insertions(+), 13 deletions(-) diff --git a/Repository/AbstractRepository.php b/Repository/AbstractRepository.php index b0af972..7f73f38 100644 --- a/Repository/AbstractRepository.php +++ b/Repository/AbstractRepository.php @@ -3,8 +3,9 @@ namespace PSS\Bundle\BlogBundle\Repository; # Symfony/Doctrine internal -use Doctrine\ORM\EntityRepository; +use \Doctrine\ORM\EntityRepository; use \Doctrine\Common\Collections\ArrayCollection; +use \Doctrine\ORM\Query; # Specific @@ -19,6 +20,24 @@ abstract class AbstractRepository extends EntityRepository { + /** + * Use Doctrine Debug + */ + public function debugDump($in) + { + throw new \Exception('Debugging result:'.\Doctrine\Common\Util\Debug::dump($in)); + } + + + /** + * Show DQL from a Query object + */ + protected function debugDql(Query $in) + { + throw new \Exception('Debugging query:'.$in->getDQL()); + } + + /** * Convert Array to ArrayCollection @@ -28,6 +47,38 @@ abstract class AbstractRepository extends EntityRepository */ public function toCollection($array) { - return ArrayCollection($array); + return $this->_toCollection($array); } + + + /** + * Return the first Entity class + * + * @param QueryBuilder $qb a QueryBuilder instance + * @return Object an Entity object + */ + protected function _fistInCollectionFromQueryBuilder(QueryBuilder $qb) + { + $collection = $this->_collectionFromQueryBuilder($qb); + return $collection->first(); + } + + + /** + * Convert a result Collection based on QueryBuilder + * + * @param QueryBuilder $qb a QueryBuilder instance + * @return Object an Entity object + */ + protected function _collectionFromQueryBuilder(QueryBuilder $qb) + { + $result = $qb->getQuery()->getResult(); + return $this->_toCollection($result); + } + + + protected function _toCollection($result) + { + return new \Doctrine\Common\Collections\ArrayCollection($result); + } } \ No newline at end of file diff --git a/Repository/PostRepository.php b/Repository/PostRepository.php index 8908acc..4680c8c 100755 --- a/Repository/PostRepository.php +++ b/Repository/PostRepository.php @@ -17,26 +17,46 @@ use PSS\Bundle\BlogBundle\Entity\Post; +# Exceptions +use Doctrine\ORM\NoResultException; + + + class PostRepository extends AbstractRepository { /** - * @return Doctrine\ORM\Query + * @return Doctrine\ORM\QueryBuilder */ - public function getPublishedPostsQuery() + public function getPublished( $max = null ) { - $query = $this->getEntityManager()->createQuery( - 'SELECT p, a FROM PSS\Bundle\BlogBundle\Entity\Post p - INNER JOIN p.author a - WHERE p.type = :type AND p.status = :status - ORDER BY p.publishedAt DESC' - ); + $qb = $this->createQueryBuilder("p") + ->select('p,a') + ->innerJoin('p.author', 'a') + ->where('p.type = :type AND p.status = :status') + ->orderBy('p.publishedAt', 'DESC'); - $query->setParameter('type', Post::TYPE_POST); - $query->setParameter('status', Post::STATUS_PUBLISH); + if (is_numeric($max)) + { + $qb->setMaxResults($limit); + } - return $query; + $qb->setParameter('type', Post::TYPE_POST); + $qb->setParameter('status', Post::STATUS_PUBLISH); + + return $qb; + } + + /** + * @return Doctrine\ORM\Query + */ + public function getPublishedPostsQuery() + { + $qb = $this->getPublished(); + $qb->setParameter('type', Post::TYPE_POST); + $qb->setParameter('status', Post::STATUS_PUBLISH); + return $qb->getQuery(); } From 534251af942bb78504757b425e27fc95a649292b Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Thu, 21 Jun 2012 23:07:28 -0400 Subject: [PATCH 06/11] WIP --- Controller/BlogController.php | 17 ++++---- Repository/AbstractRepository.php | 18 ++++++++ Repository/PostRepository.php | 58 +++++++++++++++---------- Resources/views/Blog/tagCloud.html.twig | 2 +- 4 files changed, 62 insertions(+), 33 deletions(-) diff --git a/Controller/BlogController.php b/Controller/BlogController.php index d9d3f50..8d318b4 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -17,7 +17,7 @@ # Entities use PSS\Bundle\BlogBundle\Entity\Post; -use PSS\Bundle\BlogBundle\Entity\Tag; +use PSS\Bundle\BlogBundle\Entity\Term; @@ -65,17 +65,19 @@ public function indexAction() ); } + /** - * @Route("/tag/{tag}", name="blog_posts_by_tag") + * @Route("/tag/{slug}", name="blog_posts_by_tag") * @Template() */ - public function postsByTagAction($tag) + public function postsByTagAction(Term $term) { - $entityManager = $this->get('doctrine.orm.entity_manager'); - - $repository = $this->getPostManager()->getRepository(); + $pm = $this->getPostManager(); + $repository = $pm->getRepository(); + $query = $repository + ->getPublishedByTerm($term); - $paginator = $this->createPaginator($repository->getPublishedPostsByTagQuery($tag)); + $paginator = $this->createPaginator($query->getQuery()); if ($paginator->getTotalItemCount() == 0) { throw new \Symfony\Component\HttpKernel\Exception\NotFoundHttpException('Page Not Found'); @@ -87,7 +89,6 @@ public function postsByTagAction($tag) } - public function recentPostsAction($max) { $entityManager = $this->get('doctrine.orm.entity_manager'); diff --git a/Repository/AbstractRepository.php b/Repository/AbstractRepository.php index 7f73f38..109b54e 100644 --- a/Repository/AbstractRepository.php +++ b/Repository/AbstractRepository.php @@ -20,6 +20,8 @@ abstract class AbstractRepository extends EntityRepository { + private $qb = null; + /** * Use Doctrine Debug */ @@ -29,6 +31,7 @@ public function debugDump($in) } + /** * Show DQL from a Query object */ @@ -51,6 +54,19 @@ public function toCollection($array) } + + /** + * Convert Array to ArrayCollection + * + * @return ArrayCollection + */ + public function asCollection() + { + return $this->_toCollection($this->qb); + } + + + /** * Return the first Entity class * @@ -64,6 +80,7 @@ protected function _fistInCollectionFromQueryBuilder(QueryBuilder $qb) } + /** * Convert a result Collection based on QueryBuilder * @@ -77,6 +94,7 @@ protected function _collectionFromQueryBuilder(QueryBuilder $qb) } + protected function _toCollection($result) { return new \Doctrine\Common\Collections\ArrayCollection($result); diff --git a/Repository/PostRepository.php b/Repository/PostRepository.php index 4680c8c..e55ee07 100755 --- a/Repository/PostRepository.php +++ b/Repository/PostRepository.php @@ -15,6 +15,8 @@ # Entities use PSS\Bundle\BlogBundle\Entity\TermTaxonomy; use PSS\Bundle\BlogBundle\Entity\Post; +use PSS\Bundle\BlogBundle\TagCloud\TagInterface; +use PSS\Bundle\BlogBundle\Entity\Term; # Exceptions @@ -31,23 +33,46 @@ class PostRepository extends AbstractRepository */ public function getPublished( $max = null ) { - $qb = $this->createQueryBuilder("p") + $this->qb = $this->createQueryBuilder("p") ->select('p,a') ->innerJoin('p.author', 'a') - ->where('p.type = :type AND p.status = :status') + ->where('p.type = :type') + ->andWhere('p.status = :status') ->orderBy('p.publishedAt', 'DESC'); if (is_numeric($max)) { - $qb->setMaxResults($limit); + $this->qb->setMaxResults($max); } - $qb->setParameter('type', Post::TYPE_POST); - $qb->setParameter('status', Post::STATUS_PUBLISH); + $this->qb->setParameter('type', Post::TYPE_POST); + $this->qb->setParameter('status', Post::STATUS_PUBLISH); - return $qb; + return $this->qb; } + + + + + /** + * @return Doctrine\ORM\QueryBuilder + */ + public function getPublishedByTerm(Term $term=null) + { + $this->qb = $this->getPublished() + ->innerJoin('p.termRelationships', 'tr') + ->innerJoin('tr.termTaxonomy', 'tt') + ->innerJoin('tt.term','t') + ->andWhere('tt.taxonomy = :taxonomy') + ->andWhere('t.slug = :slug'); + + $this->qb->setParameter('slug', $term->getSlug()); + $this->qb->setParameter('taxonomy', TermTaxonomy::POST_TAG); + + return $this->qb; + } + /** * @return Doctrine\ORM\Query */ @@ -80,25 +105,10 @@ public function findPublishedPosts($max = 3) */ public function getPublishedPostsByTagQuery($tagSlug) { - $query = $this->getEntityManager()->createQuery( - 'SELECT p, a FROM PSS\Bundle\BlogBundle\Entity\Post p - INNER JOIN p.author a - INNER JOIN p.termRelationships tr - INNER JOIN tr.termTaxonomy tt - INNER JOIN tt.term t - WHERE p.type = :type - AND p.status = :status - AND tt.taxonomy = :taxonomy - AND t.slug = :slug - ORDER BY p.publishedAt DESC' - ); - - $query->setParameter('type', Post::TYPE_POST); - $query->setParameter('status', Post::STATUS_PUBLISH); - $query->setParameter('slug', $tagSlug); - $query->setParameter('taxonomy', TermTaxonomy::POST_TAG); + $this->qb = $this->getPublishedByTerm() + ->setParameter('slug', $tagSlug); - return $query; + return $this->qb->getQuery(); } diff --git a/Resources/views/Blog/tagCloud.html.twig b/Resources/views/Blog/tagCloud.html.twig index e7f5243..cc8ab59 100644 --- a/Resources/views/Blog/tagCloud.html.twig +++ b/Resources/views/Blog/tagCloud.html.twig @@ -1,6 +1,6 @@ From f3a7ecd5ed335aafd2297eb349f201099643bd30 Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Mon, 25 Jun 2012 15:40:06 -0400 Subject: [PATCH 07/11] Adding getter/setters --- Controller/BlogController.php | 2 +- Entity/Comment.php | 333 +++++++++++++++++++++- Entity/CommentMeta.php | 86 +++++- Entity/Link.php | 310 +++++++++++++++++++- Entity/Option.php | 106 ++++++- Entity/Post.php | 473 ++++++++++++++++++++++++++++++- Entity/PostMeta.php | 86 +++++- Entity/Term.php | 104 ++++++- Entity/TermRelationship.php | 146 +++++++++- Entity/TermTaxonomy.php | 163 ++++++++++- Entity/User.php | 262 ++++++++++++++++- Entity/UserMeta.php | 86 +++++- Repository/CommentRepository.php | 8 +- Repository/PostRepository.php | 10 +- 14 files changed, 2149 insertions(+), 26 deletions(-) diff --git a/Controller/BlogController.php b/Controller/BlogController.php index 8d318b4..eac2f6a 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -29,7 +29,7 @@ * is that you can extend as a Base, and alter the returned array() * that each method returns using parent::methodName(); * - * Cookbook in @PSSBlogBundle/Resources/doc/recipe-extending-blog-controller.md + * Cookbook in PSSBlogBundle/Resources/doc/recipe-extending-blog-controller.md * * @Route("/blog") */ diff --git a/Entity/Comment.php b/Entity/Comment.php index 1c7c826..55d5bc3 100755 --- a/Entity/Comment.php +++ b/Entity/Comment.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_comments") * @ORM\Entity @@ -126,4 +140,321 @@ class Comment * @ORM\JoinColumn(name="comment_ID", referencedColumnName="comment_id") */ private $meta; -} + + + + public function __construct() + { + $this->meta = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set authorName + * + * @param text $authorName + */ + public function setAuthorName($authorName) + { + $this->authorName = $authorName; + } + + /** + * Get authorName + * + * @return text + */ + public function getAuthorName() + { + return $this->authorName; + } + + /** + * Set authorEmail + * + * @param string $authorEmail + */ + public function setAuthorEmail($authorEmail) + { + $this->authorEmail = $authorEmail; + } + + /** + * Get authorEmail + * + * @return string + */ + public function getAuthorEmail() + { + return $this->authorEmail; + } + + /** + * Set authorUrl + * + * @param string $authorUrl + */ + public function setAuthorUrl($authorUrl) + { + $this->authorUrl = $authorUrl; + } + + /** + * Get authorUrl + * + * @return string + */ + public function getAuthorUrl() + { + return $this->authorUrl; + } + + /** + * Set authorIp + * + * @param string $authorIp + */ + public function setAuthorIp($authorIp) + { + $this->authorIp = $authorIp; + } + + /** + * Get authorIp + * + * @return string + */ + public function getAuthorIp() + { + return $this->authorIp; + } + + /** + * Set createdAt + * + * @param datetime $createdAt + */ + public function setCreatedAt($createdAt) + { + $this->createdAt = $createdAt; + } + + /** + * Get createdAt + * + * @return datetime + */ + public function getCreatedAt() + { + return $this->createdAt; + } + + /** + * Set createdAtAsGmt + * + * @param datetime $createdAtAsGmt + */ + public function setCreatedAtAsGmt($createdAtAsGmt) + { + $this->createdAtAsGmt = $createdAtAsGmt; + } + + /** + * Get createdAtAsGmt + * + * @return datetime + */ + public function getCreatedAtAsGmt() + { + return $this->createdAtAsGmt; + } + + /** + * Set content + * + * @param text $content + */ + public function setContent($content) + { + $this->content = $content; + } + + /** + * Get content + * + * @return text + */ + public function getContent() + { + return $this->content; + } + + /** + * Set karma + * + * @param integer $karma + */ + public function setKarma($karma) + { + $this->karma = $karma; + } + + /** + * Get karma + * + * @return integer + */ + public function getKarma() + { + return $this->karma; + } + + /** + * Set approved + * + * @param string $approved + */ + public function setApproved($approved) + { + $this->approved = $approved; + } + + /** + * Get approved + * + * @return string + */ + public function getApproved() + { + return $this->approved; + } + + /** + * Set agent + * + * @param string $agent + */ + public function setAgent($agent) + { + $this->agent = $agent; + } + + /** + * Get agent + * + * @return string + */ + public function getAgent() + { + return $this->agent; + } + + /** + * Set type + * + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * Get type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set parentId + * + * @param bigint $parentId + */ + public function setParentId($parentId) + { + $this->parentId = $parentId; + } + + /** + * Get parentId + * + * @return bigint + */ + public function getParentId() + { + return $this->parentId; + } + + /** + * Set post + * + * @param PSS\Bundle\BlogBundle\Entity\Post $post + */ + public function setPost(\PSS\Bundle\BlogBundle\Entity\Post $post) + { + $this->post = $post; + } + + /** + * Get post + * + * @return PSS\Bundle\BlogBundle\Entity\Post + */ + public function getPost() + { + return $this->post; + } + + /** + * Set user + * + * @param PSS\Bundle\BlogBundle\Entity\User $user + */ + public function setUser(\PSS\Bundle\BlogBundle\Entity\User $user) + { + $this->user = $user; + } + + /** + * Get user + * + * @return PSS\Bundle\BlogBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } + + /** + * Add meta + * + * @param PSS\Bundle\BlogBundle\Entity\CommentMeta $meta + */ + public function addCommentMeta(\PSS\Bundle\BlogBundle\Entity\CommentMeta $meta) + { + $this->meta[] = $meta; + } + + /** + * Get meta + * + * @return Doctrine\Common\Collections\Collection + */ + public function getMeta() + { + return $this->meta; + } +} \ No newline at end of file diff --git a/Entity/CommentMeta.php b/Entity/CommentMeta.php index b16441b..4b1a739 100755 --- a/Entity/CommentMeta.php +++ b/Entity/CommentMeta.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_commentmeta") * @ORM\Entity @@ -40,4 +54,74 @@ class CommentMeta * @ORM\Column(name="meta_value", type="text", nullable=true) */ private $value; -} + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set key + * + * @param string $key + */ + public function setKey($key) + { + $this->key = $key; + } + + /** + * Get key + * + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * Set value + * + * @param text $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * Get value + * + * @return text + */ + public function getValue() + { + return $this->value; + } + + /** + * Set comment + * + * @param PSS\Bundle\BlogBundle\Entity\Comment $comment + */ + public function setComment(\PSS\Bundle\BlogBundle\Entity\Comment $comment) + { + $this->comment = $comment; + } + + /** + * Get comment + * + * @return PSS\Bundle\BlogBundle\Entity\Comment + */ + public function getComment() + { + return $this->comment; + } +} \ No newline at end of file diff --git a/Entity/Link.php b/Entity/Link.php index 074564d..19bd55f 100755 --- a/Entity/Link.php +++ b/Entity/Link.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_links") * @ORM\Entity @@ -117,4 +131,298 @@ class Link * @ORM\JoinColumn(name="link_id", referencedColumnName="object_id") */ private $termRelationships; -} + public function __construct() + { + $this->termRelationships = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set url + * + * @param string $url + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * Get url + * + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set image + * + * @param string $image + */ + public function setImage($image) + { + $this->image = $image; + } + + /** + * Get image + * + * @return string + */ + public function getImage() + { + return $this->image; + } + + /** + * Set target + * + * @param string $target + */ + public function setTarget($target) + { + $this->target = $target; + } + + /** + * Get target + * + * @return string + */ + public function getTarget() + { + return $this->target; + } + + /** + * Set category + * + * @param bigint $category + */ + public function setCategory($category) + { + $this->category = $category; + } + + /** + * Get category + * + * @return bigint + */ + public function getCategory() + { + return $this->category; + } + + /** + * Set description + * + * @param string $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * Get description + * + * @return string + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set visible + * + * @param string $visible + */ + public function setVisible($visible) + { + $this->visible = $visible; + } + + /** + * Get visible + * + * @return string + */ + public function getVisible() + { + return $this->visible; + } + + /** + * Set owner + * + * @param bigint $owner + */ + public function setOwner($owner) + { + $this->owner = $owner; + } + + /** + * Get owner + * + * @return bigint + */ + public function getOwner() + { + return $this->owner; + } + + /** + * Set rating + * + * @param integer $rating + */ + public function setRating($rating) + { + $this->rating = $rating; + } + + /** + * Get rating + * + * @return integer + */ + public function getRating() + { + return $this->rating; + } + + /** + * Set updatedAt + * + * @param datetime $updatedAt + */ + public function setUpdatedAt($updatedAt) + { + $this->updatedAt = $updatedAt; + } + + /** + * Get updatedAt + * + * @return datetime + */ + public function getUpdatedAt() + { + return $this->updatedAt; + } + + /** + * Set rel + * + * @param string $rel + */ + public function setRel($rel) + { + $this->rel = $rel; + } + + /** + * Get rel + * + * @return string + */ + public function getRel() + { + return $this->rel; + } + + /** + * Set notes + * + * @param text $notes + */ + public function setNotes($notes) + { + $this->notes = $notes; + } + + /** + * Get notes + * + * @return text + */ + public function getNotes() + { + return $this->notes; + } + + /** + * Set rss + * + * @param string $rss + */ + public function setRss($rss) + { + $this->rss = $rss; + } + + /** + * Get rss + * + * @return string + */ + public function getRss() + { + return $this->rss; + } + + /** + * Add termRelationships + * + * @param PSS\Bundle\BlogBundle\Entity\TermRelationship $termRelationships + */ + public function addTermRelationship(\PSS\Bundle\BlogBundle\Entity\TermRelationship $termRelationships) + { + $this->termRelationships[] = $termRelationships; + } + + /** + * Get termRelationships + * + * @return Doctrine\Common\Collections\Collection + */ + public function getTermRelationships() + { + return $this->termRelationships; + } +} \ No newline at end of file diff --git a/Entity/Option.php b/Entity/Option.php index 5fd9c06..17e3efb 100755 --- a/Entity/Option.php +++ b/Entity/Option.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_options") * @ORM\Entity @@ -46,4 +60,94 @@ class Option * @ORM\Column(name="autoload", type="string", length=20, nullable=false) */ private $autoload; -} + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set blogId + * + * @param integer $blogId + */ + public function setBlogId($blogId) + { + $this->blogId = $blogId; + } + + /** + * Get blogId + * + * @return integer + */ + public function getBlogId() + { + return $this->blogId; + } + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + /** + * Get name + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * Set value + * + * @param text $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * Get value + * + * @return text + */ + public function getValue() + { + return $this->value; + } + + /** + * Set autoload + * + * @param string $autoload + */ + public function setAutoload($autoload) + { + $this->autoload = $autoload; + } + + /** + * Get autoload + * + * @return string + */ + public function getAutoload() + { + return $this->autoload; + } +} \ No newline at end of file diff --git a/Entity/Post.php b/Entity/Post.php index 6a6895a..31b0e22 100755 --- a/Entity/Post.php +++ b/Entity/Post.php @@ -3,24 +3,25 @@ namespace PSS\Bundle\BlogBundle\Entity; -# Symfony/Doctrine internal +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; -# Specific +// Specific -# Domain objects +// Domain objects -# Entities +// Entities -# Exceptions +// Exceptions use \Symfony\Component\HttpKernel\Exception\NotFoundHttpException; + /** * @ORM\Table(name="wp_posts") * @ORM\Entity(repositoryClass="PSS\Bundle\BlogBundle\Repository\PostRepository") @@ -309,4 +310,464 @@ public function onlyIfPublished(){ } return $this; } -} + + + public function __construct() + { + $this->comments = new \Doctrine\Common\Collections\ArrayCollection(); + $this->meta = new \Doctrine\Common\Collections\ArrayCollection(); + $this->termRelationships = new \Doctrine\Common\Collections\ArrayCollection(); + } + + + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set publishedAt + * + * @param datetime $publishedAt + */ + public function setPublishedAt($publishedAt) + { + $this->publishedAt = $publishedAt; + } + + /** + * Set publishedAtAsGmt + * + * @param datetime $publishedAtAsGmt + */ + public function setPublishedAtAsGmt($publishedAtAsGmt) + { + $this->publishedAtAsGmt = $publishedAtAsGmt; + } + + /** + * Get publishedAtAsGmt + * + * @return datetime + */ + public function getPublishedAtAsGmt() + { + return $this->publishedAtAsGmt; + } + + /** + * Set content + * + * @param text $content + */ + public function setContent($content) + { + $this->content = $content; + } + + /** + * Set title + * + * @param text $title + */ + public function setTitle($title) + { + $this->title = $title; + } + + /** + * Set excerpt + * + * @param text $excerpt + */ + public function setExcerpt($excerpt) + { + $this->excerpt = $excerpt; + } + + /** + * Set status + * + * @param string $status + */ + public function setStatus($status) + { + $this->status = $status; + } + + /** + * Get status + * + * @return string + */ + public function getStatus() + { + return $this->status; + } + + /** + * Set commentStatus + * + * @param string $commentStatus + */ + public function setCommentStatus($commentStatus) + { + $this->commentStatus = $commentStatus; + } + + /** + * Get commentStatus + * + * @return string + */ + public function getCommentStatus() + { + return $this->commentStatus; + } + + /** + * Set pingStatus + * + * @param string $pingStatus + */ + public function setPingStatus($pingStatus) + { + $this->pingStatus = $pingStatus; + } + + /** + * Get pingStatus + * + * @return string + */ + public function getPingStatus() + { + return $this->pingStatus; + } + + /** + * Set password + * + * @param string $password + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * Get password + * + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * Set slug + * + * @param string $slug + */ + public function setSlug($slug) + { + $this->slug = $slug; + } + + /** + * Set toPing + * + * @param text $toPing + */ + public function setToPing($toPing) + { + $this->toPing = $toPing; + } + + /** + * Get toPing + * + * @return text + */ + public function getToPing() + { + return $this->toPing; + } + + /** + * Set pinged + * + * @param text $pinged + */ + public function setPinged($pinged) + { + $this->pinged = $pinged; + } + + /** + * Get pinged + * + * @return text + */ + public function getPinged() + { + return $this->pinged; + } + + /** + * Set modifiedAt + * + * @param datetime $modifiedAt + */ + public function setModifiedAt($modifiedAt) + { + $this->modifiedAt = $modifiedAt; + } + + /** + * Get modifiedAt + * + * @return datetime + */ + public function getModifiedAt() + { + return $this->modifiedAt; + } + + /** + * Set modifiedAtAsGmt + * + * @param datetime $modifiedAtAsGmt + */ + public function setModifiedAtAsGmt($modifiedAtAsGmt) + { + $this->modifiedAtAsGmt = $modifiedAtAsGmt; + } + + /** + * Get modifiedAtAsGmt + * + * @return datetime + */ + public function getModifiedAtAsGmt() + { + return $this->modifiedAtAsGmt; + } + + /** + * Set contentFiltered + * + * @param text $contentFiltered + */ + public function setContentFiltered($contentFiltered) + { + $this->contentFiltered = $contentFiltered; + } + + /** + * Get contentFiltered + * + * @return text + */ + public function getContentFiltered() + { + return $this->contentFiltered; + } + + /** + * Set parentId + * + * @param bigint $parentId + */ + public function setParentId($parentId) + { + $this->parentId = $parentId; + } + + /** + * Get parentId + * + * @return bigint + */ + public function getParentId() + { + return $this->parentId; + } + + /** + * Set guid + * + * @param string $guid + */ + public function setGuid($guid) + { + $this->guid = $guid; + } + + /** + * Get guid + * + * @return string + */ + public function getGuid() + { + return $this->guid; + } + + /** + * Set menuOrder + * + * @param integer $menuOrder + */ + public function setMenuOrder($menuOrder) + { + $this->menuOrder = $menuOrder; + } + + /** + * Get menuOrder + * + * @return integer + */ + public function getMenuOrder() + { + return $this->menuOrder; + } + + /** + * Set type + * + * @param string $type + */ + public function setType($type) + { + $this->type = $type; + } + + /** + * Get type + * + * @return string + */ + public function getType() + { + return $this->type; + } + + /** + * Set mimeType + * + * @param string $mimeType + */ + public function setMimeType($mimeType) + { + $this->mimeType = $mimeType; + } + + /** + * Get mimeType + * + * @return string + */ + public function getMimeType() + { + return $this->mimeType; + } + + /** + * Set commentCount + * + * @param bigint $commentCount + */ + public function setCommentCount($commentCount) + { + $this->commentCount = $commentCount; + } + + /** + * Get commentCount + * + * @return bigint + */ + public function getCommentCount() + { + return $this->commentCount; + } + + /** + * Set author + * + * @param PSS\Bundle\BlogBundle\Entity\User $author + */ + public function setAuthor(\PSS\Bundle\BlogBundle\Entity\User $author) + { + $this->author = $author; + } + + /** + * Add comments + * + * @param PSS\Bundle\BlogBundle\Entity\Comment $comments + */ + public function addComment(\PSS\Bundle\BlogBundle\Entity\Comment $comments) + { + $this->comments[] = $comments; + } + + /** + * Get comments + * + * @return Doctrine\Common\Collections\Collection + */ + public function getComments() + { + return $this->comments; + } + + /** + * Add meta + * + * @param PSS\Bundle\BlogBundle\Entity\PostMeta $meta + */ + public function addPostMeta(\PSS\Bundle\BlogBundle\Entity\PostMeta $meta) + { + $this->meta[] = $meta; + } + + /** + * Get meta + * + * @return Doctrine\Common\Collections\Collection + */ + public function getMeta() + { + return $this->meta; + } + + /** + * Add termRelationships + * + * @param PSS\Bundle\BlogBundle\Entity\TermRelationship $termRelationships + */ + public function addTermRelationship(\PSS\Bundle\BlogBundle\Entity\TermRelationship $termRelationships) + { + $this->termRelationships[] = $termRelationships; + } + + /** + * Get termRelationships + * + * @return Doctrine\Common\Collections\Collection + */ + public function getTermRelationships() + { + return $this->termRelationships; + } +} \ No newline at end of file diff --git a/Entity/PostMeta.php b/Entity/PostMeta.php index 0df0166..a24c42c 100755 --- a/Entity/PostMeta.php +++ b/Entity/PostMeta.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_postmeta") * @ORM\Entity @@ -40,4 +54,74 @@ class PostMeta * @ORM\Column(name="meta_value", type="text", nullable=true) */ private $value; -} + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set key + * + * @param string $key + */ + public function setKey($key) + { + $this->key = $key; + } + + /** + * Get key + * + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * Set value + * + * @param text $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * Get value + * + * @return text + */ + public function getValue() + { + return $this->value; + } + + /** + * Set post + * + * @param PSS\Bundle\BlogBundle\Entity\Post $post + */ + public function setPost(\PSS\Bundle\BlogBundle\Entity\Post $post) + { + $this->post = $post; + } + + /** + * Get post + * + * @return PSS\Bundle\BlogBundle\Entity\Post + */ + public function getPost() + { + return $this->post; + } +} \ No newline at end of file diff --git a/Entity/Term.php b/Entity/Term.php index acb8787..290b0bf 100755 --- a/Entity/Term.php +++ b/Entity/Term.php @@ -2,9 +2,23 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + + +// Specific + + +// Domain objects + + +// Entities use PSS\Bundle\BlogBundle\Entity\TermTaxonomy; + + + /** * @ORM\Table(name="wp_terms") * @ORM\Entity(repositoryClass="PSS\Bundle\BlogBundle\Repository\TermRepository") @@ -49,6 +63,7 @@ class Term implements \PSS\Bundle\BlogBundle\TagCloud\TagInterface */ private $termTaxonomies; + /** * @return string */ @@ -57,6 +72,7 @@ public function getName() return $this->name; } + /** * @return string */ @@ -65,6 +81,7 @@ public function getSlug() return $this->slug; } + /** * @return integer */ @@ -73,6 +90,7 @@ public function getFrequency() return $this->getPostCount(); } + /** * @return integer */ @@ -83,6 +101,7 @@ public function getPostCount() return is_null($termTaxonomy) ? 0 : $termTaxonomy->getPostCount(); } + /** * @return PSS\Bundle\BlogBundle\Entity\TermTaxonomy */ @@ -98,4 +117,87 @@ private function getPostTagTaxonomy() return null; } -} + + + public function __construct() + { + $this->termTaxonomies = new \Doctrine\Common\Collections\ArrayCollection(); + } + + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + + /** + * Set name + * + * @param string $name + */ + public function setName($name) + { + $this->name = $name; + } + + + /** + * Set slug + * + * @param string $slug + */ + public function setSlug($slug) + { + $this->slug = $slug; + } + + + /** + * Set group + * + * @param bigint $group + */ + public function setGroup($group) + { + $this->group = $group; + } + + + /** + * Get group + * + * @return bigint + */ + public function getGroup() + { + return $this->group; + } + + + /** + * Add termTaxonomies + * + * @param PSS\Bundle\BlogBundle\Entity\TermTaxonomy $termTaxonomies + */ + public function addTermTaxonomy(\PSS\Bundle\BlogBundle\Entity\TermTaxonomy $termTaxonomies) + { + $this->termTaxonomies[] = $termTaxonomies; + } + + + /** + * Get termTaxonomies + * + * @return Doctrine\Common\Collections\Collection + */ + public function getTermTaxonomies() + { + return $this->termTaxonomies; + } +} \ No newline at end of file diff --git a/Entity/TermRelationship.php b/Entity/TermRelationship.php index 6ddf27c..836ed96 100755 --- a/Entity/TermRelationship.php +++ b/Entity/TermRelationship.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_term_relationships") * @ORM\Entity @@ -58,4 +72,134 @@ class TermRelationship * @ORM\Column(name="term_order", type="integer", nullable=false) */ private $termOrder; -} + + + /** + * Set objectId + * + * @param bigint $objectId + */ + public function setObjectId($objectId) + { + $this->objectId = $objectId; + } + + + /** + * Get objectId + * + * @return bigint + */ + public function getObjectId() + { + return $this->objectId; + } + + + /** + * Set termTaxonomyId + * + * @param bigint $termTaxonomyId + */ + public function setTermTaxonomyId($termTaxonomyId) + { + $this->termTaxonomyId = $termTaxonomyId; + } + + + /** + * Get termTaxonomyId + * + * @return bigint + */ + public function getTermTaxonomyId() + { + return $this->termTaxonomyId; + } + + + /** + * Set termOrder + * + * @param integer $termOrder + */ + public function setTermOrder($termOrder) + { + $this->termOrder = $termOrder; + } + + + /** + * Get termOrder + * + * @return integer + */ + public function getTermOrder() + { + return $this->termOrder; + } + + + /** + * Set link + * + * @param PSS\Bundle\BlogBundle\Entity\Link $link + */ + public function setLink(\PSS\Bundle\BlogBundle\Entity\Link $link) + { + $this->link = $link; + } + + + /** + * Get link + * + * @return PSS\Bundle\BlogBundle\Entity\Link + */ + public function getLink() + { + return $this->link; + } + + + /** + * Set post + * + * @param PSS\Bundle\BlogBundle\Entity\Post $post + */ + public function setPost(\PSS\Bundle\BlogBundle\Entity\Post $post) + { + $this->post = $post; + } + + + /** + * Get post + * + * @return PSS\Bundle\BlogBundle\Entity\Post + */ + public function getPost() + { + return $this->post; + } + + /** + * Set termTaxonomy + * + * @param PSS\Bundle\BlogBundle\Entity\TermTaxonomy $termTaxonomy + */ + public function setTermTaxonomy(\PSS\Bundle\BlogBundle\Entity\TermTaxonomy $termTaxonomy) + { + $this->termTaxonomy = $termTaxonomy; + } + + /** + * Get termTaxonomy + * + * @return PSS\Bundle\BlogBundle\Entity\TermTaxonomy + */ + public function getTermTaxonomy() + { + return $this->termTaxonomy; + } +} \ No newline at end of file diff --git a/Entity/TermTaxonomy.php b/Entity/TermTaxonomy.php index df6a0b7..cae11e9 100755 --- a/Entity/TermTaxonomy.php +++ b/Entity/TermTaxonomy.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_term_taxonomy") * @ORM\Entity @@ -89,4 +103,151 @@ public function getPostCount() { return $this->count; } -} + + + public function __construct() + { + $this->termRelationships = new \Doctrine\Common\Collections\ArrayCollection(); + } + + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set termId + * + * @param bigint $termId + */ + public function setTermId($termId) + { + $this->termId = $termId; + } + + /** + * Get termId + * + * @return bigint + */ + public function getTermId() + { + return $this->termId; + } + + /** + * Set taxonomy + * + * @param string $taxonomy + */ + public function setTaxonomy($taxonomy) + { + $this->taxonomy = $taxonomy; + } + + /** + * Set description + * + * @param text $description + */ + public function setDescription($description) + { + $this->description = $description; + } + + /** + * Get description + * + * @return text + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set parentId + * + * @param bigint $parentId + */ + public function setParentId($parentId) + { + $this->parentId = $parentId; + } + + /** + * Get parentId + * + * @return bigint + */ + public function getParentId() + { + return $this->parentId; + } + + /** + * Set count + * + * @param bigint $count + */ + public function setCount($count) + { + $this->count = $count; + } + + /** + * Get count + * + * @return bigint + */ + public function getCount() + { + return $this->count; + } + + /** + * Set term + * + * @param PSS\Bundle\BlogBundle\Entity\Term $term + */ + public function setTerm(\PSS\Bundle\BlogBundle\Entity\Term $term) + { + $this->term = $term; + } + + /** + * Get term + * + * @return PSS\Bundle\BlogBundle\Entity\Term + */ + public function getTerm() + { + return $this->term; + } + + /** + * Add termRelationships + * + * @param PSS\Bundle\BlogBundle\Entity\TermRelationship $termRelationships + */ + public function addTermRelationship(\PSS\Bundle\BlogBundle\Entity\TermRelationship $termRelationships) + { + $this->termRelationships[] = $termRelationships; + } + + /** + * Get termRelationships + * + * @return Doctrine\Common\Collections\Collection + */ + public function getTermRelationships() + { + return $this->termRelationships; + } +} \ No newline at end of file diff --git a/Entity/User.php b/Entity/User.php index f38d987..c773788 100755 --- a/Entity/User.php +++ b/Entity/User.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_users") * @ORM\Entity @@ -113,4 +127,250 @@ public function getDisplayName() { return $this->displayName; } -} + public function __construct() + { + $this->posts = new \Doctrine\Common\Collections\ArrayCollection(); + $this->comments = new \Doctrine\Common\Collections\ArrayCollection(); + $this->meta = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set login + * + * @param string $login + */ + public function setLogin($login) + { + $this->login = $login; + } + + /** + * Get login + * + * @return string + */ + public function getLogin() + { + return $this->login; + } + + /** + * Set password + * + * @param string $password + */ + public function setPassword($password) + { + $this->password = $password; + } + + /** + * Get password + * + * @return string + */ + public function getPassword() + { + return $this->password; + } + + /** + * Set niceName + * + * @param string $niceName + */ + public function setNiceName($niceName) + { + $this->niceName = $niceName; + } + + /** + * Get niceName + * + * @return string + */ + public function getNiceName() + { + return $this->niceName; + } + + /** + * Set email + * + * @param string $email + */ + public function setEmail($email) + { + $this->email = $email; + } + + /** + * Get email + * + * @return string + */ + public function getEmail() + { + return $this->email; + } + + /** + * Set url + * + * @param string $url + */ + public function setUrl($url) + { + $this->url = $url; + } + + /** + * Get url + * + * @return string + */ + public function getUrl() + { + return $this->url; + } + + /** + * Set registeredAt + * + * @param datetime $registeredAt + */ + public function setRegisteredAt($registeredAt) + { + $this->registeredAt = $registeredAt; + } + + /** + * Get registeredAt + * + * @return datetime + */ + public function getRegisteredAt() + { + return $this->registeredAt; + } + + /** + * Set activationKey + * + * @param string $activationKey + */ + public function setActivationKey($activationKey) + { + $this->activationKey = $activationKey; + } + + /** + * Get activationKey + * + * @return string + */ + public function getActivationKey() + { + return $this->activationKey; + } + + /** + * Set status + * + * @param integer $status + */ + public function setStatus($status) + { + $this->status = $status; + } + + /** + * Get status + * + * @return integer + */ + public function getStatus() + { + return $this->status; + } + + /** + * Set displayName + * + * @param string $displayName + */ + public function setDisplayName($displayName) + { + $this->displayName = $displayName; + } + + /** + * Add posts + * + * @param PSS\Bundle\BlogBundle\Entity\Post $posts + */ + public function addPost(\PSS\Bundle\BlogBundle\Entity\Post $posts) + { + $this->posts[] = $posts; + } + + /** + * Get posts + * + * @return Doctrine\Common\Collections\Collection + */ + public function getPosts() + { + return $this->posts; + } + + /** + * Add comments + * + * @param PSS\Bundle\BlogBundle\Entity\Comment $comments + */ + public function addComment(\PSS\Bundle\BlogBundle\Entity\Comment $comments) + { + $this->comments[] = $comments; + } + + /** + * Get comments + * + * @return Doctrine\Common\Collections\Collection + */ + public function getComments() + { + return $this->comments; + } + + /** + * Add meta + * + * @param PSS\Bundle\BlogBundle\Entity\UserMeta $meta + */ + public function addUserMeta(\PSS\Bundle\BlogBundle\Entity\UserMeta $meta) + { + $this->meta[] = $meta; + } + + /** + * Get meta + * + * @return Doctrine\Common\Collections\Collection + */ + public function getMeta() + { + return $this->meta; + } +} \ No newline at end of file diff --git a/Entity/UserMeta.php b/Entity/UserMeta.php index 05c56a9..caced9d 100755 --- a/Entity/UserMeta.php +++ b/Entity/UserMeta.php @@ -2,8 +2,22 @@ namespace PSS\Bundle\BlogBundle\Entity; + +// Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; + +// Specific + + +// Domain objects + + +// Entities + + + + /** * @ORM\Table(name="wp_usermeta") * @ORM\Entity @@ -40,4 +54,74 @@ class UserMeta * @ORM\Column(name="meta_value", type="text", nullable=true) */ private $value; -} + + /** + * Get id + * + * @return bigint + */ + public function getId() + { + return $this->id; + } + + /** + * Set key + * + * @param string $key + */ + public function setKey($key) + { + $this->key = $key; + } + + /** + * Get key + * + * @return string + */ + public function getKey() + { + return $this->key; + } + + /** + * Set value + * + * @param text $value + */ + public function setValue($value) + { + $this->value = $value; + } + + /** + * Get value + * + * @return text + */ + public function getValue() + { + return $this->value; + } + + /** + * Set user + * + * @param PSS\Bundle\BlogBundle\Entity\User $user + */ + public function setUser(\PSS\Bundle\BlogBundle\Entity\User $user) + { + $this->user = $user; + } + + /** + * Get user + * + * @return PSS\Bundle\BlogBundle\Entity\User + */ + public function getUser() + { + return $this->user; + } +} \ No newline at end of file diff --git a/Repository/CommentRepository.php b/Repository/CommentRepository.php index 14e125f..dda6b30 100644 --- a/Repository/CommentRepository.php +++ b/Repository/CommentRepository.php @@ -2,16 +2,16 @@ namespace PSS\Bundle\BlogBundle\Repository; -# Symfony/Doctrine internal +// Symfony/Doctrine internal -# Specific +// Specific -# Domain objects +// Domain objects -# Entities +// Entities diff --git a/Repository/PostRepository.php b/Repository/PostRepository.php index e55ee07..02f6a23 100755 --- a/Repository/PostRepository.php +++ b/Repository/PostRepository.php @@ -2,24 +2,24 @@ namespace PSS\Bundle\BlogBundle\Repository; -# Symfony/Doctrine internal +// Symfony/Doctrine internal use Doctrine\ORM\EntityRepository; -# Specific +// Specific -# Domain objects +// Domain objects -# Entities +// Entities use PSS\Bundle\BlogBundle\Entity\TermTaxonomy; use PSS\Bundle\BlogBundle\Entity\Post; use PSS\Bundle\BlogBundle\TagCloud\TagInterface; use PSS\Bundle\BlogBundle\Entity\Term; -# Exceptions +// Exceptions use Doctrine\ORM\NoResultException; From 92f9056ad4844343c37611f5462e14abeebdb1f3 Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Mon, 25 Jun 2012 22:39:22 -0400 Subject: [PATCH 08/11] WIP Comment form --- Controller/BlogController.php | 12 +++++++-- Entity/Comment.php | 27 ++++++++++++++----- Entity/Post.php | 32 +++++++++++++++++----- Form/CommentForm.php | 50 +++++++++++++++++++++++++++++++++++ Manager/AbstractManager.php | 50 ++++++++++++++++++++++++++++++++++- Manager/CommentManager.php | 24 ++++++++++++----- 6 files changed, 172 insertions(+), 23 deletions(-) create mode 100644 Form/CommentForm.php diff --git a/Controller/BlogController.php b/Controller/BlogController.php index eac2f6a..ce43fb2 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -7,6 +7,7 @@ use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; +use Symfony\Component\HttpFoundation\Request; # Specific @@ -36,6 +37,12 @@ class BlogController extends Controller { + protected function comment(Request $request, Post $post) + { +# try { +# $cmtMgr = $this->get('pss.blogbundle.manager.comment'); +# $entity = $cmtMgr->entityFactory($request); // Setting the "always required" stuff + } @@ -43,10 +50,11 @@ class BlogController extends Controller * @Route("/{year}/{month}/{slug}", name="blog_show") * @Template() */ - public function showAction(Post $post) + public function showAction(Post $post, Request $request) { return array( - 'post' => $post->onlyIfPublished() + 'post' => $post->onlyIfPublished(), + 'comment_form' => $this->comment($request,$post) ); } diff --git a/Entity/Comment.php b/Entity/Comment.php index 55d5bc3..c1e6f27 100755 --- a/Entity/Comment.php +++ b/Entity/Comment.php @@ -5,6 +5,9 @@ // Symfony/Doctrine internal use Doctrine\ORM\Mapping as ORM; +use Gedmo\Mapping\Annotation as Gedmo; +use Symfony\Component\Validator\Constraints as Assert; +use Doctrine\Common\Collections\ArrayCollection; // Specific @@ -19,8 +22,15 @@ /** + * A Comment represent a note left by a visitor from the web. + * + * Comment can be attached to either a Post or an other Comment. + * + * Comment needs to be validated by blog owner. + * + * @ORM\HasLifecycleCallbacks() * @ORM\Table(name="wp_comments") - * @ORM\Entity + * @ORM\Entity(repositoryClass="PSS\Bundle\BlogBundle\Repository\CommentRepository") */ class Comment { @@ -72,6 +82,8 @@ class Comment /** * @var datetime $createdAt * + * @Gedmo\Timestampable(on="create") + * @Assert\Type(type="\DateTime") * @ORM\Column(name="comment_date", type="datetime", nullable=false) */ private $createdAt; @@ -79,6 +91,8 @@ class Comment /** * @var datetime $createdAtAsGmt * + * @Gedmo\Timestampable(on="create") + * @Assert\Type(type="\DateTime") * @ORM\Column(name="comment_date_gmt", type="datetime", nullable=false) */ private $createdAtAsGmt; @@ -145,8 +159,9 @@ class Comment public function __construct() { - $this->meta = new \Doctrine\Common\Collections\ArrayCollection(); + $this->meta = new ArrayCollection(); } + /** * Get id @@ -321,21 +336,21 @@ public function getKarma() /** * Set approved * - * @param string $approved + * @param boolean $approved */ public function setApproved($approved) { - $this->approved = $approved; + $this->approved = !! $approved; } /** * Get approved * - * @return string + * @return boolean */ public function getApproved() { - return $this->approved; + return !! $this->approved; } /** diff --git a/Entity/Post.php b/Entity/Post.php index 31b0e22..46f24a3 100755 --- a/Entity/Post.php +++ b/Entity/Post.php @@ -4,7 +4,8 @@ // Symfony/Doctrine internal -use Doctrine\ORM\Mapping as ORM; +use \Doctrine\ORM\Mapping as ORM; +use \Doctrine\Common\Collections\ArrayCollection; // Specific @@ -314,9 +315,26 @@ public function onlyIfPublished(){ public function __construct() { - $this->comments = new \Doctrine\Common\Collections\ArrayCollection(); - $this->meta = new \Doctrine\Common\Collections\ArrayCollection(); - $this->termRelationships = new \Doctrine\Common\Collections\ArrayCollection(); + $this->comments = new ArrayCollection(); + $this->meta = new ArrayCollection(); + $this->termRelationships = new ArrayCollection(); + } + + + /** + * Get moderated comments + * + * @return \Doctrine\Common\Collections\ArrayCollection + */ + public function getModeratedComments() + { + $approved = new ArrayCollection(); + foreach ($this->comments as $comment) { + if ($comment->getApproved() === true) { + $approved[] = $comment; + } + } + return $approved; } @@ -724,7 +742,7 @@ public function addComment(\PSS\Bundle\BlogBundle\Entity\Comment $comments) /** * Get comments * - * @return Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\ArrayCollection */ public function getComments() { @@ -744,7 +762,7 @@ public function addPostMeta(\PSS\Bundle\BlogBundle\Entity\PostMeta $meta) /** * Get meta * - * @return Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\ArrayCollection */ public function getMeta() { @@ -764,7 +782,7 @@ public function addTermRelationship(\PSS\Bundle\BlogBundle\Entity\TermRelationsh /** * Get termRelationships * - * @return Doctrine\Common\Collections\Collection + * @return \Doctrine\Common\Collections\ArrayCollection */ public function getTermRelationships() { diff --git a/Form/CommentForm.php b/Form/CommentForm.php new file mode 100644 index 0000000..21d6999 --- /dev/null +++ b/Form/CommentForm.php @@ -0,0 +1,50 @@ +add('authorName', 'text') + ->add('authorUrl', 'text') + ->add('authorEmail', 'text') + ->add('contentt', 'text') + ->add('post', 'text'); + } + + + public function getDefaultOptions(array $options) + { + return array( + 'data_class'=> self::DATA_CLASS, + 'csrf_field_name' => '_comment_intent' + ); + } + + + public function getName() + { + return 'wordpress_comment_form'; + } +} \ No newline at end of file diff --git a/Manager/AbstractManager.php b/Manager/AbstractManager.php index c3ca50b..158d633 100644 --- a/Manager/AbstractManager.php +++ b/Manager/AbstractManager.php @@ -21,6 +21,14 @@ abstract class AbstractManager { + /** + * Fully Qualified Class Name of the entity + * + * @var string + */ + protected $classname; + + /* @var \Doctrine\ORM\EntityManager */ protected $em = null; @@ -29,7 +37,7 @@ abstract class AbstractManager protected $dispatcher = null; - public function __construct(EventDispatcher $dispatcher, EntityManager $em) + public function __construct(EventDispatcher $dispatcher, EntityManager $em, $classname=null) { $this->dispatcher = $dispatcher; $this->em = $em; @@ -42,4 +50,44 @@ public function getRepository($name=null) $repository = $this->em->getRepository($entityName); return $repository; } + + + + + /** + * Returns a new instance of the Form class + * + * Make sure you adjust the form' __construct($inputArray) + * with the proper index. + * + * e.g. $om->formFactory($injectOne,$injectTwo,$injectThree); + * would return a new SomeRandomFormName instance + * + * Inside the SomeRandomFormName::__construct($inputArray), you + * could get $injectOne value by delcaring $inputArray[0] + * + * @return \Symfony\Component\Form\AbstractType form class instance + */ + public function formFactory() + { + $arguments = func_get_args(); + $formClassname = static::FORM_CLASSNAME; + if(count($arguments) >= 1){ + return new $formClassname($arguments); + } + return new $formClassname(); + } + + + + + /** + * Return a _new Entity_ + */ + public function create() + { + $classname = $this->classname; + return new $classname(); + } + } \ No newline at end of file diff --git a/Manager/CommentManager.php b/Manager/CommentManager.php index 486ecca..c6874ec 100644 --- a/Manager/CommentManager.php +++ b/Manager/CommentManager.php @@ -2,30 +2,40 @@ namespace PSS\Bundle\BlogBundle\Manager; -# Symfony/Doctrine internal +// Symfony/Doctrine internal use Doctrine\ORM\EntityManager; use Symfony\Component\EventDispatcher\EventDispatcherInterface; -# Specific +// Specific -# Domain objects +// Domain objects +use PSS\Bundle\BlogBundle\Form\CommentForm; -# Entities +// Entities use PSS\Bundle\BlogBundle\Entity\Comment; +// Exceptions +use \Exception; +use \LogicException; + + + + + /** - * Distribute and manipulate Comments - * - * + * Manages the lifecycle of a Organization */ class CommentManager extends AbstractManager { + const FORM_CLASSNAME = 'PSS\Bundle\BlogBundle\Form\CommentForm'; + const CLASSNAME = 'PSS\Bundle\BlogBundle\Entity\Comment'; + const SHORTCUT = 'PSSBlogBundle:Comment'; } \ No newline at end of file From b10d2c894594f85c876dd541f321923cce1db870 Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Mon, 25 Jun 2012 22:48:34 -0400 Subject: [PATCH 09/11] Code formatting following maste --- Controller/BlogController.php | 13 +++---------- Repository/PostRepository.php | 11 ----------- Resources/config/services.yml | 2 -- 3 files changed, 3 insertions(+), 23 deletions(-) diff --git a/Controller/BlogController.php b/Controller/BlogController.php index ce43fb2..1ddbcbb 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -36,7 +36,9 @@ */ class BlogController extends Controller { - + /** + * Generate a comment form and process + */ protected function comment(Request $request, Post $post) { # try { @@ -44,8 +46,6 @@ protected function comment(Request $request, Post $post) # $entity = $cmtMgr->entityFactory($request); // Setting the "always required" stuff } - - /** * @Route("/{year}/{month}/{slug}", name="blog_show") * @Template() @@ -58,7 +58,6 @@ public function showAction(Post $post, Request $request) ); } - /** * @Route("/", name="blog_index") * @Template() @@ -73,7 +72,6 @@ public function indexAction() ); } - /** * @Route("/tag/{slug}", name="blog_posts_by_tag") * @Template() @@ -96,7 +94,6 @@ public function postsByTagAction(Term $term) ); } - public function recentPostsAction($max) { $entityManager = $this->get('doctrine.orm.entity_manager'); @@ -121,8 +118,6 @@ public function tagCloudAction() return $this->render('PSSBlogBundle:Blog:tagCloud.html.twig', array('tagCloud' => $tagCloud)); } - - /** * Access to Post Manager service * @@ -133,8 +128,6 @@ protected function getPostManager() return $this->get('pss.blog.manager.post'); } - - /** * Create a paginator from a Query * diff --git a/Repository/PostRepository.php b/Repository/PostRepository.php index 02f6a23..9943666 100755 --- a/Repository/PostRepository.php +++ b/Repository/PostRepository.php @@ -27,7 +27,6 @@ class PostRepository extends AbstractRepository { - /** * @return Doctrine\ORM\QueryBuilder */ @@ -51,10 +50,6 @@ public function getPublished( $max = null ) return $this->qb; } - - - - /** * @return Doctrine\ORM\QueryBuilder */ @@ -84,8 +79,6 @@ public function getPublishedPostsQuery() return $qb->getQuery(); } - - /** * @param integer $max * @return PSS\Bundle\BlogBundle\Entity\Post @@ -98,8 +91,6 @@ public function findPublishedPosts($max = 3) return $query->getResult(); } - - /** * @return Doctrine\ORM\Query */ @@ -111,8 +102,6 @@ public function getPublishedPostsByTagQuery($tagSlug) return $this->qb->getQuery(); } - - /** * @param string $slug * @return PSS\Bundle\BlogBundle\Entity\Post diff --git a/Resources/config/services.yml b/Resources/config/services.yml index 72bb5bf..2736268 100755 --- a/Resources/config/services.yml +++ b/Resources/config/services.yml @@ -10,14 +10,12 @@ services: tags: - { name: twig.extension } - pss.blog.manager.entity.abstract: abstract: true arguments: dispatcher: '@event_dispatcher' em: '@doctrine.orm.entity_manager' - pss.blog.manager.post: parent: pss.blog.manager.entity.abstract class: %pss.blog.manager.post.class% From 07bf88013a9d2fbeb81131a6277560e47935b17b Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Tue, 26 Jun 2012 19:36:28 -0400 Subject: [PATCH 10/11] WIP --- Resources/views/Blog/tagCloud.html.twig | 2 +- TagCloud/TagCloud.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Resources/views/Blog/tagCloud.html.twig b/Resources/views/Blog/tagCloud.html.twig index cc8ab59..84f87dd 100644 --- a/Resources/views/Blog/tagCloud.html.twig +++ b/Resources/views/Blog/tagCloud.html.twig @@ -1,6 +1,6 @@ diff --git a/TagCloud/TagCloud.php b/TagCloud/TagCloud.php index ce73a36..40e8a1e 100755 --- a/TagCloud/TagCloud.php +++ b/TagCloud/TagCloud.php @@ -90,6 +90,8 @@ public function __construct(array $tags, array $weights) $this->weights = $weights; + shuffle($tags); + foreach ($tags as $tag) { $this->addTag($tag); } From 31f8be3afa0083c8c61cebcbab2340d5c779288c Mon Sep 17 00:00:00 2001 From: Renoir Boulanger Date: Thu, 28 Jun 2012 08:54:50 -0400 Subject: [PATCH 11/11] Adding some extension and new query builder --- Controller/BlogController.php | 3 +- Repository/PostRepository.php | 61 +++++++++++++++++++++++++++++ Twig/Extension/ContentExtension.php | 3 ++ 3 files changed, 66 insertions(+), 1 deletion(-) diff --git a/Controller/BlogController.php b/Controller/BlogController.php index 1ddbcbb..c77a2b5 100755 --- a/Controller/BlogController.php +++ b/Controller/BlogController.php @@ -90,7 +90,8 @@ public function postsByTagAction(Term $term) } return array( - 'paginator' => $paginator + 'paginator' => $paginator, + 'term' => $term ); } diff --git a/Repository/PostRepository.php b/Repository/PostRepository.php index 9943666..3479f85 100755 --- a/Repository/PostRepository.php +++ b/Repository/PostRepository.php @@ -68,6 +68,67 @@ public function getPublishedByTerm(Term $term=null) return $this->qb; } + /** + * Get three last hilighted + */ + public function getHilighted() + { + $slugs = array('Favourites','Linux'); + + $this->qb = $this->getPublished() + ->innerJoin('p.termRelationships', 'tr') + ->innerJoin('tr.termTaxonomy', 'tt') + ->innerJoin('tt.term','t') + ->andWhere('tt.taxonomy = :taxonomy') + ->andWhere($this->qb->expr()->in('t.slug',$slugs)) + ->orderBy('p.publishedAt','DESC'); + + $this->qb->setParameter('taxonomy', TermTaxonomy::POST_TAG); + $this->qb->setMaxResults(3); + + return $this->qb; + } + + /** + * Get a list of posts by Tag slug + * + * @param array $slugs List of slugs to search in + * @param int $max Limit Max results + * + * @return QueryBuilder + */ + public function getByTagSlugs(array $slugs,$max=3) + { + $this->qb = $this->getPublished() + ->innerJoin('p.termRelationships', 'tr') + ->innerJoin('tr.termTaxonomy', 'tt') + ->innerJoin('tt.term','t') + ->andWhere('tt.taxonomy = :taxonomy') + ->andWhere($this->qb->expr()->in('t.slug',$slugs)) + ->orderBy('p.publishedAt','DESC'); + + $this->qb->setParameter('taxonomy', TermTaxonomy::POST_TAG); + $this->qb->setMaxResults($max); + + return $this->qb; + } + + /** + * Get a list of posts by Category slug + * + * @param array $slugs List of slugs to search in + * @param int $max Limit Max results + * + * @return QueryBuilder + */ + public function getByCategorySlugs(array $slugs,$max=3) + { + $this->qb = $this->getByTagSlugs($slugs,$max); + $this->qb->setParameter('taxonomy', TermTaxonomy::CATEGORY); + + return $this->qb; + } + /** * @return Doctrine\ORM\Query */ diff --git a/Twig/Extension/ContentExtension.php b/Twig/Extension/ContentExtension.php index 2160eae..60b0dc2 100755 --- a/Twig/Extension/ContentExtension.php +++ b/Twig/Extension/ContentExtension.php @@ -6,10 +6,13 @@ class ContentExtension extends \Twig_Extension { public function getFilters() { + //$hilighter = new \PSS\Bundle\BlogBundle\Twig\Extension\Hilighter(); + return array( 'autop' => new \Twig_Filter_Method($this, 'autop'), 'summarize' => new \Twig_Filter_Method($this, 'summarize'), 'more' => new \Twig_Filter_Method($this, 'cutToMoreTag') + //,'geshi', => new \Twig_Filter_Method($hilighter, 'main') ); }