|
1
|
|
|
<?php |
|
2
|
|
|
/*************************************************************************************/ |
|
3
|
|
|
/* This file is part of the module AttributeType */ |
|
4
|
|
|
/* */ |
|
5
|
|
|
/* For the full copyright and license information, please view the LICENSE.txt */ |
|
6
|
|
|
/* file that was distributed with this source code. */ |
|
7
|
|
|
/*************************************************************************************/ |
|
8
|
|
|
|
|
9
|
|
|
namespace AttributeType\Loop; |
|
10
|
|
|
|
|
11
|
|
|
use AttributeType\Model\AttributeType; |
|
12
|
|
|
use AttributeType\Model\AttributeTypeQuery; |
|
13
|
|
|
use AttributeType\Model\Map\AttributeAttributeTypeTableMap; |
|
14
|
|
|
use AttributeType\Model\Map\AttributeTypeTableMap; |
|
15
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
|
16
|
|
|
use Propel\Runtime\ActiveQuery\Join; |
|
17
|
|
|
use Thelia\Core\Template\Element\BaseI18nLoop; |
|
18
|
|
|
use Thelia\Core\Template\Element\LoopResult; |
|
19
|
|
|
use Thelia\Core\Template\Element\LoopResultRow; |
|
20
|
|
|
use Thelia\Core\Template\Element\PropelSearchLoopInterface; |
|
21
|
|
|
use Thelia\Core\Template\Loop\Argument\Argument; |
|
22
|
|
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Class AttributeTypeLoop |
|
26
|
|
|
* @package AttributeType\Loop |
|
27
|
|
|
* @author Gilles Bourgeat <[email protected]> |
|
28
|
|
|
* |
|
29
|
|
|
* @method int[] getId() |
|
30
|
|
|
* @method int[] getExcludeId() |
|
31
|
|
|
* @method string getSlug() |
|
32
|
|
|
* @method int[] getAttributeId() |
|
33
|
|
|
* @method string[] getOrder() |
|
34
|
|
|
*/ |
|
35
|
|
|
class AttributeTypeLoop extends BaseI18nLoop implements PropelSearchLoopInterface |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* Definition of loop arguments |
|
39
|
|
|
* |
|
40
|
|
|
* example : |
|
41
|
|
|
* |
|
42
|
|
|
* public function getArgDefinitions() |
|
43
|
|
|
* { |
|
44
|
|
|
* return new ArgumentCollection( |
|
45
|
|
|
* |
|
46
|
|
|
* Argument::createIntListTypeArgument('id'), |
|
47
|
|
|
* new Argument( |
|
48
|
|
|
* 'ref', |
|
49
|
|
|
* new TypeCollection( |
|
50
|
|
|
* new Type\AlphaNumStringListType() |
|
51
|
|
|
* ) |
|
52
|
|
|
* ), |
|
53
|
|
|
* Argument::createIntListTypeArgument('category'), |
|
54
|
|
|
* Argument::createBooleanTypeArgument('new'), |
|
55
|
|
|
* ... |
|
56
|
|
|
* ); |
|
57
|
|
|
* } |
|
58
|
|
|
* |
|
59
|
|
|
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection |
|
60
|
|
|
*/ |
|
61
|
|
|
protected function getArgDefinitions() |
|
62
|
|
|
{ |
|
63
|
|
|
return new ArgumentCollection( |
|
64
|
|
|
Argument::createIntListTypeArgument("id"), |
|
65
|
|
|
Argument::createIntListTypeArgument("exclude_id"), |
|
66
|
|
|
Argument::createAnyTypeArgument('slug'), |
|
67
|
|
|
Argument::createIntListTypeArgument("attribute_id"), |
|
68
|
|
|
Argument::createEnumListTypeArgument( |
|
69
|
|
|
"order", |
|
70
|
|
|
[ |
|
71
|
|
|
"id", |
|
72
|
|
|
"id-reverse", |
|
73
|
|
|
"attribute_type", |
|
74
|
|
|
"attribute_type-reverse", |
|
75
|
|
|
], |
|
76
|
|
|
"id" |
|
77
|
|
|
) |
|
78
|
|
|
); |
|
79
|
|
|
} |
|
80
|
|
|
/** |
|
81
|
|
|
* this method returns a Propel ModelCriteria |
|
82
|
|
|
* |
|
83
|
|
|
* @return \Propel\Runtime\ActiveQuery\ModelCriteria |
|
84
|
|
|
*/ |
|
85
|
|
|
public function buildModelCriteria() |
|
86
|
|
|
{ |
|
87
|
|
|
$query = new AttributeTypeQuery(); |
|
88
|
|
|
|
|
89
|
|
|
/* manage translations */ |
|
90
|
|
|
$this->configureI18nProcessing($query, array('TITLE', 'DESCRIPTION')); |
|
91
|
|
|
|
|
92
|
|
|
if (null !== $id = $this->getId()) { |
|
93
|
|
|
$query->filterById($id); |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
if (null !== $id = $this->getExcludeId()) { |
|
97
|
|
|
$query->filterById($id, Criteria::NOT_IN); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
if (null !== $slug = $this->getSlug()) { |
|
101
|
|
|
$query->filterBySlug($slug); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
if (null !== $attributeId = $this->getAttributeId()) { |
|
105
|
|
|
$join = new Join(); |
|
106
|
|
|
|
|
107
|
|
|
$join->addExplicitCondition( |
|
108
|
|
|
AttributeTypeTableMap::TABLE_NAME, |
|
109
|
|
|
'ID', |
|
110
|
|
|
null, |
|
111
|
|
|
AttributeAttributeTypeTableMap::TABLE_NAME, |
|
112
|
|
|
'ATTRIBUTE_TYPE_ID', |
|
113
|
|
|
null |
|
114
|
|
|
); |
|
115
|
|
|
|
|
116
|
|
|
$join->setJoinType(Criteria::JOIN); |
|
117
|
|
|
|
|
118
|
|
|
$query |
|
119
|
|
|
->addJoinObject($join, 'attribute_type_join') |
|
120
|
|
|
->addJoinCondition( |
|
121
|
|
|
'attribute_type_join', |
|
122
|
|
|
'`attribute_attribute_type`.`attribute_id` IN (?)', |
|
123
|
|
|
implode(',', $attributeId), |
|
124
|
|
|
null, |
|
125
|
|
|
\PDO::PARAM_INT |
|
126
|
|
|
); |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
foreach ($this->getOrder() as $order) { |
|
130
|
|
|
switch ($order) { |
|
131
|
|
|
case "id": |
|
132
|
|
|
$query->orderById(); |
|
133
|
|
|
break; |
|
134
|
|
|
case "id-reverse": |
|
135
|
|
|
$query->orderById(Criteria::DESC); |
|
136
|
|
|
break; |
|
137
|
|
|
case "slug": |
|
138
|
|
|
$query->orderBySlug(); |
|
139
|
|
|
break; |
|
140
|
|
|
case "slug-reverse": |
|
141
|
|
|
$query->orderBySlug(Criteria::DESC); |
|
142
|
|
|
break; |
|
143
|
|
|
} |
|
144
|
|
|
} |
|
145
|
|
|
return $query; |
|
146
|
|
|
} |
|
147
|
|
|
|
|
148
|
|
|
/** |
|
149
|
|
|
* @param LoopResult $loopResult |
|
150
|
|
|
* |
|
151
|
|
|
* @return LoopResult |
|
152
|
|
|
*/ |
|
153
|
|
|
public function parseResults(LoopResult $loopResult) |
|
154
|
|
|
{ |
|
155
|
|
|
/** @var AttributeType $entry */ |
|
156
|
|
|
foreach ($loopResult->getResultDataCollection() as $entry) { |
|
157
|
|
|
$row = new LoopResultRow($entry); |
|
158
|
|
|
$row |
|
159
|
|
|
->set("ID", $entry->getId()) |
|
160
|
|
|
->set("SLUG", $entry->getSlug()) |
|
161
|
|
|
->set("TITLE", $entry->getVirtualColumn('i18n_TITLE')) |
|
162
|
|
|
->set("DESCRIPTION", $entry->getVirtualColumn('i18n_DESCRIPTION')) |
|
163
|
|
|
->set("CSS_CLASS", $entry->getCssClass()) |
|
164
|
|
|
->set("PATTERN", $entry->getPattern()) |
|
165
|
|
|
->set("INPUT_TYPE", $entry->getInputType()) |
|
166
|
|
|
->set("MIN", $entry->getMin()) |
|
167
|
|
|
->set("MAX", $entry->getMax()) |
|
168
|
|
|
->set("STEP", $entry->getStep()) |
|
169
|
|
|
->set("IMAGE_MAX_WIDTH", $entry->getImageMaxWidth()) |
|
170
|
|
|
->set("IMAGE_MAX_HEIGHT", $entry->getImageMaxHeight()) |
|
171
|
|
|
->set("IMAGE_RATIO", $entry->getImageRatio()) |
|
172
|
|
|
->set("IS_MULTILINGUAL_ATTRIBUTE_AV_VALUE", $entry->getIsMultilingualAttributeAvValue()) |
|
173
|
|
|
->set("HAS_ATTRIBUTE_AV_VALUE", $entry->getHasAttributeAvValue()) |
|
174
|
|
|
; |
|
175
|
|
|
|
|
176
|
|
|
$this->addOutputFields($row, $entry); |
|
177
|
|
|
|
|
178
|
|
|
$loopResult->addRow($row); |
|
179
|
|
|
} |
|
180
|
|
|
|
|
181
|
|
|
return $loopResult; |
|
182
|
|
|
} |
|
183
|
|
|
} |
|
184
|
|
|
|