Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
unioncondition.php
1<?php
10
13
21{
23 protected $subQuery;
24
26 protected $all;
27
34 public function __construct($subQuery, $unionAll = false)
35 {
36 if (!($subQuery instanceof Query) && !($subQuery instanceof SqlExpression))
37 {
38 throw new ArgumentException("Query or SqlExpression expected, `".gettype($subQuery)."` found.");
39 }
40
41 $this->subQuery = $subQuery;
42 $this->all = $unionAll;
43 }
44
48 public function getSubQuery()
49 {
50 return $this->subQuery;
51 }
52
56 public function setSubQuery($subQuery)
57 {
58 $this->subQuery = $subQuery;
59 }
60
64 public function isAll()
65 {
66 return $this->all;
67 }
68
72 public function setAll($all)
73 {
74 $this->all = $all;
75 }
76
84 public function getSql($forceObjectPrimary = false)
85 {
86 $sql = "UNION ";
87
88 if ($this->all)
89 {
90 $sql .= "ALL ";
91 }
92
93 $subQuerySql = $this->getSubQuerySql($forceObjectPrimary);
94
95 if (preg_match('/(\sorder\s+by\s|\slimit\s+\d+)/i', $subQuerySql))
96 {
97 $subQuerySql = "({$subQuerySql})";
98 }
99
100 return $sql . $subQuerySql;
101 }
102
110 public function getSubQuerySql($forceObjectPrimary = false)
111 {
112 if ($this->subQuery instanceof Query)
113 {
114 return $this->subQuery->getQuery($forceObjectPrimary);
115 }
116 elseif ($this->subQuery instanceof SqlExpression)
117 {
118 return $this->subQuery->compile();
119 }
120
121 return null;
122 }
123}
getSql($forceObjectPrimary=false)
getSubQuerySql($forceObjectPrimary=false)
__construct($subQuery, $unionAll=false)