| @@ 23-65 (lines=43) @@ | ||
| 20 | /** |
|
| 21 | * @author Tobias Nyholm |
|
| 22 | */ |
|
| 23 | class CountOf implements Specification |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * @var Filter|QueryModifier child |
|
| 27 | */ |
|
| 28 | private $child; |
|
| 29 | ||
| 30 | /** |
|
| 31 | * @param Filter|QueryModifier $child |
|
| 32 | */ |
|
| 33 | public function __construct($child) |
|
| 34 | { |
|
| 35 | $this->child = $child; |
|
| 36 | } |
|
| 37 | ||
| 38 | /** |
|
| 39 | * @param QueryBuilder $qb |
|
| 40 | * @param string $dqlAlias |
|
| 41 | * |
|
| 42 | * @return string |
|
| 43 | */ |
|
| 44 | public function getFilter(QueryBuilder $qb, $dqlAlias) |
|
| 45 | { |
|
| 46 | $qb->select(sprintf('COUNT(%s)', $dqlAlias)); |
|
| 47 | ||
| 48 | if ($this->child instanceof Filter) { |
|
| 49 | return $this->child->getFilter($qb, $dqlAlias); |
|
| 50 | } |
|
| 51 | ||
| 52 | return ''; |
|
| 53 | } |
|
| 54 | ||
| 55 | /** |
|
| 56 | * @param QueryBuilder $qb |
|
| 57 | * @param string $dqlAlias |
|
| 58 | */ |
|
| 59 | public function modify(QueryBuilder $qb, $dqlAlias) |
|
| 60 | { |
|
| 61 | if ($this->child instanceof QueryModifier) { |
|
| 62 | $this->child->modify($qb, $dqlAlias); |
|
| 63 | } |
|
| 64 | } |
|
| 65 | } |
|
| 66 | ||
| @@ 25-67 (lines=43) @@ | ||
| 22 | /** |
|
| 23 | * @deprecated This class is deprecated since version 1.1 and will be removed in 2.0, use \Happyr\DoctrineSpecification\Query\Having instead. |
|
| 24 | */ |
|
| 25 | class Having implements Specification |
|
| 26 | { |
|
| 27 | /** |
|
| 28 | * @var Filter|QueryModifier|string |
|
| 29 | */ |
|
| 30 | protected $child; |
|
| 31 | ||
| 32 | /** |
|
| 33 | * @param Filter|QueryModifier|string $child |
|
| 34 | */ |
|
| 35 | public function __construct($child) |
|
| 36 | { |
|
| 37 | $this->child = $child; |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * @param QueryBuilder $qb |
|
| 42 | * @param string $dqlAlias |
|
| 43 | */ |
|
| 44 | public function modify(QueryBuilder $qb, $dqlAlias) |
|
| 45 | { |
|
| 46 | if ($this->child instanceof QueryModifier) { |
|
| 47 | $this->child->modify($qb, $dqlAlias); |
|
| 48 | } |
|
| 49 | ||
| 50 | if ($this->child instanceof Filter) { |
|
| 51 | $qb->having($this->child->getFilter($qb, $dqlAlias)); |
|
| 52 | } else { |
|
| 53 | $qb->having($this->child); |
|
| 54 | } |
|
| 55 | } |
|
| 56 | ||
| 57 | /** |
|
| 58 | * @param QueryBuilder $qb |
|
| 59 | * @param string $dqlAlias |
|
| 60 | * |
|
| 61 | * @return string |
|
| 62 | */ |
|
| 63 | public function getFilter(QueryBuilder $qb, $dqlAlias) |
|
| 64 | { |
|
| 65 | return ''; |
|
| 66 | } |
|
| 67 | } |
|
| 68 | ||