PluginProbe
GiveWP – Donation Plugin and Fundraising Platform / 4.15.2
GiveWP – Donation Plugin and Fundraising Platform v4.15.2
4.16.8 4.16.7.2 4.16.7.1 4.16.7 4.16.6.1 4.16.6 4.16.5.1 4.16.5 4.16.4 4.16.3 4.16.2 4.16.1 4.16.0 4.15.5 4.15.4 4.15.3 4.15.2 4.15.1 4.15.0 2.3.0 2.3.1 2.3.2 2.30.0 2.31.0 2.31.1 All 253 releases
give / src / Framework / QueryBuilder / Concerns / UnionOperator.php
UnionOperator.php
60 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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