Aggregate.php
4 years ago
CRUD.php
4 years ago
FromClause.php
4 years ago
GroupByStatement.php
4 years ago
HavingClause.php
4 years ago
JoinClause.php
4 years ago
LimitStatement.php
4 years ago
MetaQuery.php
4 years ago
OffsetStatement.php
4 years ago
OrderByStatement.php
4 years ago
SelectStatement.php
4 years ago
TablePrefix.php
4 years ago
UnionOperator.php
4 years ago
WhereClause.php
3 years ago
UnionOperator.php
60 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\QueryBuilder\Concerns; |
| 4 | |
| 5 | use Give\Framework\QueryBuilder\Clauses\Union; |
| 6 | use Give\Framework\QueryBuilder\QueryBuilder; |
| 7 | |
| 8 | /** |
| 9 | * @since 2.19.0 |
| 10 | */ |
| 11 | trait UnionOperator |
| 12 | { |
| 13 | /** |
| 14 | * @var int |
| 15 | */ |
| 16 | protected $unions = []; |
| 17 | |
| 18 | /** |
| 19 | * @param QueryBuilder $union |
| 20 | * |
| 21 | * @return $this |
| 22 | */ |
| 23 | public function union(...$union) |
| 24 | { |
| 25 | $this->unions = array_map(function (QueryBuilder $builder) { |
| 26 | return new Union($builder); |
| 27 | }, $union); |
| 28 | |
| 29 | return $this; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @param QueryBuilder $union |
| 34 | * |
| 35 | * @return $this |
| 36 | */ |
| 37 | public function unionAll(...$union) |
| 38 | { |
| 39 | $this->unions = array_map(function (QueryBuilder $builder) { |
| 40 | return new Union($builder, true); |
| 41 | }, $union); |
| 42 | |
| 43 | return $this; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * @return array|string[] |
| 48 | */ |
| 49 | protected function getUnionSQL() |
| 50 | { |
| 51 | if (empty($this->unions)) { |
| 52 | return []; |
| 53 | } |
| 54 | |
| 55 | return array_map(function (Union $union) { |
| 56 | return ( $union->all ? 'UNION ALL ' : 'UNION ' ) . $union->builder->getSQL(); |
| 57 | }, $this->unions); |
| 58 | } |
| 59 | } |
| 60 |