Skip to content

Commit 0fd61d9

Browse files
committed
Merge pull request #37 from symfony-cmf/qbv2
[WIP] QB refactoring
2 parents d9c6620 + 813b1c2 commit 0fd61d9

File tree

2 files changed

+8
-21
lines changed

2 files changed

+8
-21
lines changed

Repository/PostRepository.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,19 @@ public function searchQuery($options)
1111
$options = array_merge(array(
1212
'blog_uuid' => null,
1313
), $options);
14-
$qb = $this->createQueryBuilder();
15-
16-
$criterias = array();
14+
$qb = $this->createQueryBuilder('a');
1715

1816
if ($options['blog_id']) {
19-
$criterias[] = $qb->expr()->descendant($options['blog_id']);
20-
}
21-
22-
if (count($criterias) == 2) {
23-
$qb->where(
24-
$qb->expr()->andX($criterias[0], $criterias[1])
25-
);
26-
} elseif (count($criterias) == 1) {
27-
$qb->where(current($criterias));
17+
$qb->where()->descendant('a.' . $options['blog_id']);
2818
}
2919

30-
$qb->orderBy('date', 'DESC');
31-
$q = $qb->getQuery();
32-
33-
return $q;
20+
$qb->orderBy()->descending()->field('a.date');
21+
return $qb->getQuery();
3422
}
3523

3624
public function search($options)
3725
{
3826
$q = $this->searchQuery($options);
39-
$res = $q->execute();
40-
return $res;
27+
return $q->execute();
4128
}
4229
}

Tagging/PHPCRStringStrategy.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ class PHPCRStringStrategy implements StrategyInterface
1616
*/
1717
public function getWeightedTags($blogId)
1818
{
19-
$qb = $this->postRep->createQueryBuilder();
19+
$qb = $this->postRep->createQueryBuilder('a');
2020
$qb->select('tags');
21-
$qb->descendant($blogId); // select only children of given blog
21+
$qb->where()->descendant('a', $blogId); // select only children of given blog
2222
$q = $qb->getQuery();
2323
$res = $q->getPhpcrNodeResult();
2424
$rows = $res->getRows();
@@ -44,6 +44,6 @@ public function getWeightedTags($blogId)
4444
$tag['weight'] = $tag['count'] / $max;
4545
}
4646

47-
return $wTags;
47+
return $weightedTags;
4848
}
4949
}

0 commit comments

Comments
 (0)