1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2017 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
namespace Eccube\Doctrine\Query; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
use Doctrine\ORM\QueryBuilder; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* JOIN句を組み立てるクラス |
31
|
|
|
*/ |
32
|
|
|
class JoinClause |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
private $join; |
36
|
|
|
|
37
|
|
|
private $alias; |
38
|
|
|
|
39
|
|
|
private $conditionType; |
40
|
|
|
|
41
|
|
|
private $condition; |
42
|
|
|
|
43
|
|
|
private $indexBy; |
44
|
|
|
|
45
|
|
|
private $leftJoin = false; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var JoinClauseWhereCustomizer $whereCustomizer |
49
|
|
|
*/ |
50
|
|
|
private $whereCustomizer; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var JoinClauseOrderByCustomizer $orderByCustomizer |
54
|
|
|
*/ |
55
|
|
|
private $orderByCustomizer; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* JoinClause constructor. |
59
|
|
|
* @param $leftJoin |
60
|
|
|
* @param $join |
61
|
|
|
* @param $alias |
62
|
|
|
* @param $conditionType |
63
|
|
|
* @param $condition |
64
|
|
|
* @param $indexBy |
65
|
|
|
*/ |
66
|
|
|
private function __construct($leftJoin, $join, $alias, $conditionType = null, $condition = null, $indexBy = null) |
67
|
|
|
{ |
68
|
|
|
$this->leftJoin = $leftJoin; |
69
|
|
|
$this->join = $join; |
70
|
|
|
$this->alias = $alias; |
71
|
|
|
$this->conditionType = $conditionType; |
72
|
|
|
$this->condition = $condition; |
73
|
|
|
$this->indexBy = $indexBy; |
74
|
|
|
$this->whereCustomizer = new JoinClauseWhereCustomizer(); |
75
|
|
|
$this->orderByCustomizer = new JoinClauseOrderByCustomizer(); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
|
|
|
|
79
|
|
|
* INNER JOIN用のファクトリメソッド。 |
80
|
|
|
* |
81
|
|
|
* @see QueryBuilder::innerJoin() |
82
|
|
|
* @param $join |
|
|
|
|
83
|
|
|
* @param $alias |
|
|
|
|
84
|
|
|
* @param $conditionType |
|
|
|
|
85
|
|
|
* @param $condition |
|
|
|
|
86
|
|
|
* @param $indexBy |
|
|
|
|
87
|
|
|
* @return JoinClause |
88
|
|
|
*/ |
89
|
|
|
public static function innerJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) |
90
|
|
|
{ |
91
|
|
|
return new JoinClause(false, $join, $alias, $conditionType, $condition, $indexBy); |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
|
|
|
|
95
|
|
|
* LEFT JOIN用のファクトリメソッド。 |
96
|
|
|
* |
97
|
|
|
* @see QueryBuilder::leftJoin() |
98
|
|
|
* @param $join |
|
|
|
|
99
|
|
|
* @param $alias |
|
|
|
|
100
|
|
|
* @param $conditionType |
|
|
|
|
101
|
|
|
* @param $condition |
|
|
|
|
102
|
|
|
* @param $indexBy |
|
|
|
|
103
|
|
|
* @return JoinClause |
104
|
|
|
*/ |
105
|
|
|
public static function leftJoin($join, $alias, $conditionType = null, $condition = null, $indexBy = null) |
106
|
|
|
{ |
107
|
|
|
return new JoinClause(true, $join, $alias, $conditionType, $condition, $indexBy); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* WHERE句を追加します。 |
112
|
|
|
* |
113
|
|
|
* @param WhereClause $whereClause |
114
|
|
|
* @return $this |
115
|
|
|
*/ |
116
|
|
|
public function addWhere(WhereClause $whereClause) |
117
|
|
|
{ |
118
|
|
|
$this->whereCustomizer->add($whereClause); |
119
|
|
|
return $this; |
|
|
|
|
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* ORDER BY句を追加します。 |
124
|
|
|
* @param OrderByClause $orderByClause |
125
|
|
|
* @return $this |
126
|
|
|
*/ |
127
|
|
|
public function addOrderBy(OrderByClause $orderByClause) |
128
|
|
|
{ |
129
|
|
|
$this->orderByCustomizer->add($orderByClause); |
130
|
|
|
return $this; |
|
|
|
|
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
public function build(QueryBuilder $builder) { |
|
|
|
|
134
|
|
|
if ($this->leftJoin) { |
135
|
|
|
$builder->leftJoin($this->join, $this->alias, $this->conditionType, $this->condition, $this->indexBy); |
136
|
|
|
} else { |
137
|
|
|
$builder->innerJoin($this->join, $this->alias, $this->conditionType, $this->condition, $this->indexBy); |
138
|
|
|
} |
139
|
|
|
$this->whereCustomizer->customize($builder, null, ''); |
|
|
|
|
140
|
|
|
$this->orderByCustomizer->customize($builder, null, ''); |
|
|
|
|
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
class JoinClauseWhereCustomizer extends WhereCustomizer |
|
|
|
|
145
|
|
|
{ |
146
|
|
|
/** |
147
|
|
|
* @var WhereClause[] |
148
|
|
|
*/ |
149
|
|
|
private $whereClauses = []; |
150
|
|
|
|
151
|
|
|
public function add(WhereClause $whereClause) |
|
|
|
|
152
|
|
|
{ |
153
|
|
|
$this->whereClauses[] = $whereClause; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* @param array $params |
158
|
|
|
* @param $queryKey |
159
|
|
|
* @return WhereClause[] |
160
|
|
|
*/ |
161
|
|
|
protected function createStatements($params, $queryKey) |
162
|
|
|
{ |
163
|
|
|
return $this->whereClauses; |
164
|
|
|
} |
165
|
|
|
} |
166
|
|
|
|
167
|
|
|
class JoinClauseOrderByCustomizer extends OrderByCustomizer |
|
|
|
|
168
|
|
|
{ |
169
|
|
|
/** |
170
|
|
|
* @var OrderByClause[] |
171
|
|
|
*/ |
172
|
|
|
private $orderByClauses = []; |
173
|
|
|
|
174
|
|
|
public function add(OrderByClause $orderByClause) |
|
|
|
|
175
|
|
|
{ |
176
|
|
|
$this->orderByClauses[] = $orderByClause; |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* @param array $params |
181
|
|
|
* @param $queryKey |
182
|
|
|
* @return OrderByClause[] |
183
|
|
|
*/ |
184
|
|
|
protected function createStatements($params, $queryKey) |
185
|
|
|
{ |
186
|
|
|
return $this->orderByClauses; |
187
|
|
|
} |
188
|
|
|
} |