File tree Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Expand file tree Collapse file tree 1 file changed +26
-0
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace WikibaseSolutions \CypherDSL \Clauses ;
4
4
5
+ use WikibaseSolutions \CypherDSL \Query ;
6
+
5
7
/**
6
8
* This class represents the union clause.
7
9
*
@@ -20,6 +22,30 @@ public function __construct(bool $all = false)
20
22
$ this ->all = $ all ;
21
23
}
22
24
25
+ /**
26
+ * Combines two queries with a union.
27
+ *
28
+ * @param Query $left The query preceding the union clause.
29
+ * @param Query $right The query after the union clause.
30
+ * @param bool $all Whether the union should include all results or remove the duplicates instead.
31
+ */
32
+ public static function union (Query $ left , Query $ right , bool $ all = false ): Query
33
+ {
34
+ $ tbr = Query::new ();
35
+
36
+ foreach ($ left ->getClauses () as $ clause ) {
37
+ $ tbr ->addClause ($ clause );
38
+ }
39
+
40
+ $ tbr ->addClause (new self ($ all ));
41
+
42
+ foreach ($ right ->getClauses () as $ clause ) {
43
+ $ tbr ->addClause ($ clause );
44
+ }
45
+
46
+ return $ tbr ;
47
+ }
48
+
23
49
/**
24
50
* Returns whether the union includes all results or removes the duplicates instead.
25
51
*
You can’t perform that action at this time.
0 commit comments