From 813b1c2af65f0ff509e252ca9305940c34740b9b Mon Sep 17 00:00:00 2001 From: Lukas Kahwe Smith Date: Wed, 11 Sep 2013 10:30:01 +0200 Subject: [PATCH] initial steps for the QB refactoring --- Repository/PostRepository.php | 23 +++++------------------ Tagging/PHPCRStringStrategy.php | 6 +++--- 2 files changed, 8 insertions(+), 21 deletions(-) diff --git a/Repository/PostRepository.php b/Repository/PostRepository.php index e184485..f09d5b2 100644 --- a/Repository/PostRepository.php +++ b/Repository/PostRepository.php @@ -11,32 +11,19 @@ public function searchQuery($options) $options = array_merge(array( 'blog_uuid' => null, ), $options); - $qb = $this->createQueryBuilder(); - - $criterias = array(); + $qb = $this->createQueryBuilder('a'); if ($options['blog_id']) { - $criterias[] = $qb->expr()->descendant($options['blog_id']); - } - - if (count($criterias) == 2) { - $qb->where( - $qb->expr()->andX($criterias[0], $criterias[1]) - ); - } elseif (count($criterias) == 1) { - $qb->where(current($criterias)); + $qb->where()->descendant('a.' . $options['blog_id']); } - $qb->orderBy('date', 'DESC'); - $q = $qb->getQuery(); - - return $q; + $qb->orderBy()->descending()->field('a.date'); + return $qb->getQuery(); } public function search($options) { $q = $this->searchQuery($options); - $res = $q->execute(); - return $res; + return $q->execute(); } } diff --git a/Tagging/PHPCRStringStrategy.php b/Tagging/PHPCRStringStrategy.php index 1b8021b..c5f5338 100644 --- a/Tagging/PHPCRStringStrategy.php +++ b/Tagging/PHPCRStringStrategy.php @@ -16,9 +16,9 @@ class PHPCRStringStrategy implements StrategyInterface */ public function getWeightedTags($blogId) { - $qb = $this->postRep->createQueryBuilder(); + $qb = $this->postRep->createQueryBuilder('a'); $qb->select('tags'); - $qb->descendant($blogId); // select only children of given blog + $qb->where()->descendant('a', $blogId); // select only children of given blog $q = $qb->getQuery(); $res = $q->getPhpcrNodeResult(); $rows = $res->getRows(); @@ -44,6 +44,6 @@ public function getWeightedTags($blogId) $tag['weight'] = $tag['count'] / $max; } - return $wTags; + return $weightedTags; } }