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
|
|
|
namespace Thelia\Core\Template\Loop; |
14
|
|
|
|
15
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
16
|
|
|
use Thelia\Core\Template\Element\BaseI18nLoop; |
17
|
|
|
use Thelia\Core\Template\Element\LoopResult; |
18
|
|
|
use Thelia\Core\Template\Element\LoopResultRow; |
19
|
|
|
use Thelia\Core\Template\Element\PropelSearchLoopInterface; |
20
|
|
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; |
21
|
|
|
use Thelia\Core\Template\Loop\Argument\Argument; |
22
|
|
|
use Thelia\Model\CurrencyQuery; |
23
|
|
|
use Thelia\Type\TypeCollection; |
24
|
|
|
use Thelia\Type\EnumListType; |
25
|
|
|
use Thelia\Model\Currency as CurrencyModel; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* |
29
|
|
|
* Currency loop |
30
|
|
|
* |
31
|
|
|
* |
32
|
|
|
* Class Currency |
33
|
|
|
* @package Thelia\Core\Template\Loop |
34
|
|
|
* @author Etienne Roudeix <[email protected]> |
35
|
|
|
* |
36
|
|
|
* {@inheritdoc} |
37
|
|
|
* @method int[] getId() |
38
|
|
|
* @method int[] getExclude() |
39
|
|
|
* @method bool getDefaultOnly() |
40
|
|
|
* @method bool|string getVisible() |
41
|
|
|
* @method string[] getOrder() |
42
|
|
|
*/ |
43
|
|
|
class Currency extends BaseI18nLoop implements PropelSearchLoopInterface |
44
|
|
|
{ |
45
|
|
|
protected $timestampable = true; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @return ArgumentCollection |
49
|
|
|
*/ |
50
|
|
|
protected function getArgDefinitions() |
51
|
|
|
{ |
52
|
|
|
return new ArgumentCollection( |
53
|
|
|
Argument::createIntListTypeArgument('id'), |
54
|
|
|
Argument::createIntListTypeArgument('exclude'), |
55
|
|
|
Argument::createBooleanTypeArgument('default_only', false), |
56
|
|
|
Argument::createBooleanOrBothTypeArgument('visible', true), |
57
|
|
|
new Argument( |
58
|
|
|
'order', |
59
|
|
|
new TypeCollection( |
60
|
|
|
new EnumListType( |
61
|
|
|
array( |
62
|
|
|
'id', 'id_reverse', |
63
|
|
|
'name', 'name_reverse', |
64
|
|
|
'code', 'code_reverse', |
65
|
|
|
'symbol', 'symbol_reverse', |
66
|
|
|
'rate', 'rate_reverse', |
67
|
|
|
'visible', 'visible_reverse', |
68
|
|
|
'is_default', 'is_default_reverse', |
69
|
|
|
'manual', 'manual_reverse') |
70
|
|
|
) |
71
|
|
|
), |
72
|
|
|
'manual' |
73
|
|
|
) |
74
|
|
|
); |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
public function buildModelCriteria() |
78
|
|
|
{ |
79
|
|
|
$search = CurrencyQuery::create(); |
80
|
|
|
|
81
|
|
|
/* manage translations */ |
82
|
|
|
$this->configureI18nProcessing($search, array('NAME')); |
83
|
|
|
|
84
|
|
|
if (null !== $id = $this->getId()) { |
85
|
|
|
$search->filterById($id, Criteria::IN); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
if (null !== $exclude = $this->getExclude()) { |
89
|
|
|
$search->filterById($exclude, Criteria::NOT_IN); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
if ($this->getDefaultOnly() === true) { |
93
|
|
|
$search->filterByByDefault(true); |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
if ('*' !== $visible = $this->getVisible()) { |
97
|
|
|
$search->filterByVisible($visible); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
$orders = $this->getOrder(); |
101
|
|
|
|
102
|
|
|
foreach ($orders as $order) { |
103
|
|
|
switch ($order) { |
104
|
|
|
case 'id': |
105
|
|
|
$search->orderById(Criteria::ASC); |
106
|
|
|
break; |
107
|
|
|
case 'id_reverse': |
108
|
|
|
$search->orderById(Criteria::DESC); |
109
|
|
|
break; |
110
|
|
|
|
111
|
|
|
case 'name': |
112
|
|
|
$search->addAscendingOrderByColumn('i18n_NAME'); |
113
|
|
|
break; |
114
|
|
|
case 'name_reverse': |
115
|
|
|
$search->addDescendingOrderByColumn('i18n_NAME'); |
116
|
|
|
break; |
117
|
|
|
|
118
|
|
|
case 'code': |
119
|
|
|
$search->orderByCode(Criteria::ASC); |
120
|
|
|
break; |
121
|
|
|
case 'code_reverse': |
122
|
|
|
$search->orderByCode(Criteria::DESC); |
123
|
|
|
break; |
124
|
|
|
|
125
|
|
|
case 'symbol': |
126
|
|
|
$search->orderBySymbol(Criteria::ASC); |
127
|
|
|
break; |
128
|
|
|
case 'symbol_reverse': |
129
|
|
|
$search->orderBySymbol(Criteria::DESC); |
130
|
|
|
break; |
131
|
|
|
|
132
|
|
|
case 'rate': |
133
|
|
|
$search->orderByRate(Criteria::ASC); |
134
|
|
|
break; |
135
|
|
|
case 'rate_reverse': |
136
|
|
|
$search->orderByRate(Criteria::DESC); |
137
|
|
|
break; |
138
|
|
|
|
139
|
|
|
case 'visible': |
140
|
|
|
$search->orderByVisible(Criteria::ASC); |
141
|
|
|
break; |
142
|
|
|
case 'visible_reverse': |
143
|
|
|
$search->orderByVisible(Criteria::DESC); |
144
|
|
|
break; |
145
|
|
|
|
146
|
|
|
case 'is_default': |
147
|
|
|
$search->orderByByDefault(Criteria::ASC); |
148
|
|
|
break; |
149
|
|
|
case 'is_default_reverse': |
150
|
|
|
$search->orderByByDefault(Criteria::DESC); |
151
|
|
|
break; |
152
|
|
|
|
153
|
|
|
case 'manual': |
154
|
|
|
$search->orderByPosition(Criteria::ASC); |
155
|
|
|
break; |
156
|
|
|
case 'manual_reverse': |
157
|
|
|
$search->orderByPosition(Criteria::DESC); |
158
|
|
|
break; |
159
|
|
|
} |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
return $search; |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
public function parseResults(LoopResult $loopResult) |
166
|
|
|
{ |
167
|
|
|
/** @var CurrencyModel $currency */ |
168
|
|
|
foreach ($loopResult->getResultDataCollection() as $currency) { |
169
|
|
|
$loopResultRow = new LoopResultRow($currency); |
170
|
|
|
$loopResultRow |
171
|
|
|
->set("ID", $currency->getId()) |
172
|
|
|
->set("IS_TRANSLATED", $currency->getVirtualColumn('IS_TRANSLATED')) |
173
|
|
|
->set("LOCALE", $this->locale) |
174
|
|
|
->set("NAME", $currency->getVirtualColumn('i18n_NAME')) |
175
|
|
|
->set("ISOCODE", $currency->getCode()) |
176
|
|
|
->set("SYMBOL", $currency->getSymbol()) |
177
|
|
|
->set("FORMAT", $currency->getFormat()) |
178
|
|
|
->set("RATE", $currency->getRate()) |
179
|
|
|
->set("VISIBLE", $currency->getVisible()) |
180
|
|
|
->set("POSITION", $currency->getPosition()) |
181
|
|
|
->set("IS_DEFAULT", $currency->getByDefault()) |
182
|
|
|
; |
183
|
|
|
$this->addOutputFields($loopResultRow, $currency); |
184
|
|
|
|
185
|
|
|
$loopResult->addRow($loopResultRow); |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
return $loopResult; |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|