Skip to content

Commit

Permalink
Merge pull request #37 from symfony-cmf/qbv2
Browse files Browse the repository at this point in the history
[WIP] QB refactoring
  • Loading branch information
lsmith77 committed Sep 25, 2013
2 parents d9c6620 + 813b1c2 commit 0fd61d9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 21 deletions.
23 changes: 5 additions & 18 deletions Repository/PostRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
6 changes: 3 additions & 3 deletions Tagging/PHPCRStringStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -44,6 +44,6 @@ public function getWeightedTags($blogId)
$tag['weight'] = $tag['count'] / $max;
}

return $wTags;
return $weightedTags;
}
}

0 comments on commit 0fd61d9

Please sign in to comment.