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 22
33namespace WikibaseSolutions \CypherDSL \Clauses ;
44
5+ use WikibaseSolutions \CypherDSL \Query ;
6+
57/**
68 * This class represents the union clause.
79 *
@@ -20,6 +22,30 @@ public function __construct(bool $all = false)
2022 $ this ->all = $ all ;
2123 }
2224
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+
2349 /**
2450 * Returns whether the union includes all results or removes the duplicates instead.
2551 *
You can’t perform that action at this time.
0 commit comments