1
|
|
|
<?php |
2
|
|
|
/*************************************************************************************/ |
3
|
|
|
/* This file is part of the Thelia package. */ |
4
|
|
|
/* */ |
5
|
|
|
/* Copyright (c) OpenStudio */ |
6
|
|
|
/* email : [email protected] */ |
7
|
|
|
/* web : http://www.thelia.net */ |
8
|
|
|
/* */ |
9
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
10
|
|
|
/* file that was distributed with this source code. */ |
11
|
|
|
/*************************************************************************************/ |
12
|
|
|
/*************************************************************************************/ |
13
|
|
|
|
14
|
|
|
namespace Dealer\Loop; |
15
|
|
|
|
16
|
|
|
use Dealer\Model\Dealer; |
17
|
|
|
use Dealer\Model\DealerQuery; |
18
|
|
|
use Dealer\Model\Map\DealerBrandTableMap; |
19
|
|
|
use Dealer\Model\Map\DealerContentTableMap; |
20
|
|
|
use Dealer\Model\Map\DealerFolderTableMap; |
21
|
|
|
use Dealer\Model\Map\DealerProductTableMap; |
22
|
|
|
use Dealer\Model\Map\DealerTableMap; |
23
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
24
|
|
|
use Propel\Runtime\ActiveQuery\Join; |
25
|
|
|
use Thelia\Core\Template\Element\BaseI18nLoop; |
26
|
|
|
use Thelia\Core\Template\Element\LoopResult; |
27
|
|
|
use Thelia\Core\Template\Element\LoopResultRow; |
28
|
|
|
use Thelia\Core\Template\Element\PropelSearchLoopInterface; |
29
|
|
|
use Thelia\Core\Template\Loop\Argument\Argument; |
30
|
|
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* Class DealerLoop |
34
|
|
|
* @package Dealer\Loop |
35
|
|
|
*/ |
36
|
|
|
class DealerLoop extends BaseI18nLoop implements PropelSearchLoopInterface |
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @param LoopResult $loopResult |
41
|
|
|
* |
42
|
|
|
* @return LoopResult |
43
|
|
|
*/ |
44
|
|
|
public function parseResults(LoopResult $loopResult) |
45
|
|
|
{ |
46
|
|
|
/** @var Dealer $dealer */ |
47
|
|
|
foreach ($loopResult->getResultDataCollection() as $dealer) { |
48
|
|
|
$loopResultRow = new LoopResultRow($dealer); |
49
|
|
|
|
50
|
|
|
$loopResultRow |
51
|
|
|
->set('ID', $dealer->getId()) |
52
|
|
|
->set("ADDRESS1", $dealer->getAddress1()) |
53
|
|
|
->set("ADDRESS2", $dealer->getAddress2()) |
54
|
|
|
->set("ADDRESS3", $dealer->getAddress3()) |
55
|
|
|
->set("ZIPCODE", $dealer->getZipcode()) |
56
|
|
|
->set("CITY", $dealer->getCity()) |
57
|
|
|
->set("COUNTRY_ID", $dealer->getCountryId()) |
58
|
|
|
->set("LAT", $dealer->getLatitude()) |
59
|
|
|
->set("LON", $dealer->getLongitude()) |
60
|
|
|
->set("CREATE_DATE", $dealer->getCreatedAt()) |
61
|
|
|
->set("UPDATE_DATE", $dealer->getUpdatedAt()) |
62
|
|
|
->set("VISIBLE", $dealer->getVisible()) |
63
|
|
|
; |
64
|
|
|
|
65
|
|
|
if ($dealer->hasVirtualColumn('i18n_TITLE')) { |
66
|
|
|
$loopResultRow->set("TITLE", $dealer->getVirtualColumn('i18n_TITLE')); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
if ($dealer->hasVirtualColumn('i18n_ACCESS')) { |
70
|
|
|
$loopResultRow->set("ACCESS", $dealer->getVirtualColumn('i18n_ACCESS')); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
if ($dealer->hasVirtualColumn('i18n_DESCRIPTION')) { |
74
|
|
|
$loopResultRow->set("DESCRIPTION", $dealer->getVirtualColumn('i18n_DESCRIPTION')); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
if ($this->getWithPrevNextInfo()) { |
78
|
|
|
|
79
|
|
|
$previous = $this->getPrevious($dealer); |
80
|
|
|
$next = $this->getNext($dealer); |
81
|
|
|
$loopResultRow |
82
|
|
|
->set("HAS_PREVIOUS", $previous != null ? 1 : 0) |
83
|
|
|
->set("HAS_NEXT", $next != null ? 1 : 0) |
84
|
|
|
->set("PREVIOUS", $previous != null ? $previous->getId() : -1) |
85
|
|
|
->set("NEXT", $next != null ? $next->getId() : -1); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
$loopResult->addRow($loopResultRow); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
return $loopResult; |
92
|
|
|
} |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @inheritdoc |
96
|
|
|
*/ |
97
|
|
|
protected function getArgDefinitions() |
98
|
|
|
{ |
99
|
|
|
return new ArgumentCollection( |
100
|
|
|
Argument::createIntListTypeArgument('id'), |
101
|
|
|
Argument::createIntListTypeArgument('country_id'), |
102
|
|
|
Argument::createIntListTypeArgument('content_id'), |
103
|
|
|
Argument::createIntListTypeArgument('folder_id'), |
104
|
|
|
Argument::createIntListTypeArgument('brand_id'), |
105
|
|
|
Argument::createIntListTypeArgument('product_id'), |
106
|
|
|
Argument::createAnyListTypeArgument('city'), |
107
|
|
|
Argument::createBooleanTypeArgument('with_prev_next_info', false), |
108
|
|
|
Argument::createEnumListTypeArgument('order', [ |
109
|
|
|
'id', |
110
|
|
|
'id-reverse', |
111
|
|
|
'date', |
112
|
|
|
'date-reverse' |
113
|
|
|
], 'id') |
114
|
|
|
); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @inheritdoc |
119
|
|
|
*/ |
120
|
|
|
public function buildModelCriteria() |
121
|
|
|
{ |
122
|
|
|
$query = DealerQuery::create(); |
123
|
|
|
|
124
|
|
|
// manage translations |
125
|
|
|
$this->configureI18nProcessing( |
126
|
|
|
$query, |
127
|
|
|
[ |
128
|
|
|
'TITLE', |
129
|
|
|
'DESCRIPTION', |
130
|
|
|
'ACCESS' |
131
|
|
|
], |
132
|
|
|
null, |
133
|
|
|
'ID', |
134
|
|
|
$this->getForceReturn() |
135
|
|
|
); |
136
|
|
|
|
137
|
|
|
if ($id = $this->getId()) { |
138
|
|
|
$query->filterById($id); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
if ($country_id = $this->getCountryId()) { |
142
|
|
|
$query->filterByCountryId($country_id); |
143
|
|
|
} |
144
|
|
|
|
145
|
|
|
if ($city = $this->getCity()) { |
146
|
|
|
$query->filterByCity($city); |
147
|
|
|
} |
148
|
|
|
|
149
|
|
|
if($content = $this->getContentId()){ |
150
|
|
|
if(is_array($content)){ |
151
|
|
|
$content = implode(",", $content); |
152
|
|
|
} |
153
|
|
|
$contentJoin = new Join(DealerTableMap::ID,DealerContentTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
154
|
|
|
$query |
155
|
|
|
->addJoinObject($contentJoin) |
156
|
|
|
->where(DealerContentTableMap::CONTENT_ID." ".Criteria::IN." (".$content.")"); |
157
|
|
|
; |
158
|
|
|
|
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
if($folder = $this->getFolderId()){ |
162
|
|
|
if(is_array($folder)){ |
163
|
|
|
$folder = implode(",", $folder); |
164
|
|
|
} |
165
|
|
|
$contentJoin = new Join(DealerTableMap::ID,DealerFolderTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
166
|
|
|
$query |
167
|
|
|
->addJoinObject($contentJoin) |
168
|
|
|
->where(DealerFolderTableMap::FOLDER_ID." ".Criteria::IN." (".$folder.")"); |
169
|
|
|
; |
170
|
|
|
|
171
|
|
|
} |
172
|
|
|
|
173
|
|
|
if($brand = $this->getBrandId()){ |
174
|
|
|
if(is_array($brand)){ |
175
|
|
|
$brand = implode(",", $brand); |
176
|
|
|
} |
177
|
|
|
$contentJoin = new Join(DealerTableMap::ID,DealerBrandTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
178
|
|
|
$query |
179
|
|
|
->addJoinObject($contentJoin) |
180
|
|
|
->where(DealerBrandTableMap::BRAND_ID." ".Criteria::IN." (".$brand.")"); |
181
|
|
|
; |
182
|
|
|
|
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
if($product = $this->getProductId()){ |
186
|
|
|
if(is_array($product)){ |
187
|
|
|
$product = implode(",", $product); |
188
|
|
|
} |
189
|
|
|
$contentJoin = new Join(DealerTableMap::ID,DealerProductTableMap::DEALER_ID,Criteria::LEFT_JOIN); |
190
|
|
|
$query |
191
|
|
|
->addJoinObject($contentJoin) |
192
|
|
|
->where(DealerProductTableMap::PRODUCT_ID." ".Criteria::IN." (".$product.")"); |
193
|
|
|
; |
194
|
|
|
|
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
foreach ($this->getOrder() as $order) { |
198
|
|
|
switch ($order) { |
199
|
|
|
case 'id' : |
|
|
|
|
200
|
|
|
$query->orderById(); |
201
|
|
|
break; |
202
|
|
|
case 'id-reverse' : |
|
|
|
|
203
|
|
|
$query->orderById(Criteria::DESC); |
204
|
|
|
break; |
205
|
|
|
case 'date' : |
|
|
|
|
206
|
|
|
$query->orderByCreatedAt(); |
207
|
|
|
break; |
208
|
|
|
case 'date-reverse' : |
|
|
|
|
209
|
|
|
$query->orderByCreatedAt(Criteria::DESC); |
210
|
|
|
break; |
211
|
|
|
default: |
212
|
|
|
break; |
213
|
|
|
} |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
return $query; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
/** |
220
|
|
|
* @param Dealer $dealer |
221
|
|
|
* @return Dealer |
222
|
|
|
*/ |
223
|
|
|
protected function getPrevious($dealer) |
224
|
|
|
{ |
225
|
|
|
$query = DealerQuery::create(); |
226
|
|
|
|
227
|
|
|
foreach ($this->getOrder() as $order) { |
228
|
|
|
switch ($order) { |
229
|
|
|
case 'id' : |
|
|
|
|
230
|
|
|
$query->orderById(Criteria::DESC); |
231
|
|
|
$query->filterById($dealer->getId(),Criteria::LESS_THAN); |
232
|
|
|
break; |
233
|
|
|
case 'id-reverse' : |
|
|
|
|
234
|
|
|
$query->orderById(); |
235
|
|
|
$query->filterById($dealer->getId(),Criteria::GREATER_THAN); |
236
|
|
|
break; |
237
|
|
|
default: |
238
|
|
|
$query->orderById(Criteria::DESC); |
239
|
|
|
$query->filterById($dealer->getId(),Criteria::LESS_THAN); |
240
|
|
|
break; |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
return $query->findOne(); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* @param Dealer $dealer |
249
|
|
|
* @return Dealer |
250
|
|
|
*/ |
251
|
|
|
protected function getNext($dealer) |
252
|
|
|
{ |
253
|
|
|
$query = DealerQuery::create(); |
254
|
|
|
|
255
|
|
|
foreach ($this->getOrder() as $order) { |
256
|
|
|
switch ($order) { |
257
|
|
|
case 'id' : |
|
|
|
|
258
|
|
|
$query->orderById(); |
259
|
|
|
$query->filterById($dealer->getId(),Criteria::GREATER_THAN); |
260
|
|
|
break; |
261
|
|
|
case 'id-reverse' : |
|
|
|
|
262
|
|
|
$query->orderById(Criteria::DESC); |
263
|
|
|
$query->filterById($dealer->getId(),Criteria::LESS_THAN); |
264
|
|
|
break; |
265
|
|
|
default: |
266
|
|
|
$query->orderById(); |
267
|
|
|
$query->filterById($dealer->getId(),Criteria::GREATER_THAN); |
268
|
|
|
break; |
269
|
|
|
} |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
return $query->findOne(); |
273
|
|
|
} |
274
|
|
|
} |
As per the PSR-2 coding standard, there must not be a space in front of the colon in case statements.
To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.