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\DealerContact; |
17
|
|
|
use Dealer\Model\DealerContactQuery; |
18
|
|
|
use Propel\Runtime\ActiveQuery\Criteria; |
19
|
|
|
use Thelia\Core\Template\Element\BaseI18nLoop; |
20
|
|
|
use Thelia\Core\Template\Element\LoopResult; |
21
|
|
|
use Thelia\Core\Template\Element\LoopResultRow; |
22
|
|
|
use Thelia\Core\Template\Element\PropelSearchLoopInterface; |
23
|
|
|
use Thelia\Core\Template\Loop\Argument\Argument; |
24
|
|
|
use Thelia\Core\Template\Loop\Argument\ArgumentCollection; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Class ContactLoop |
28
|
|
|
* @package Dealer\Loop |
29
|
|
|
*/ |
30
|
|
|
class ContactLoop extends BaseI18nLoop implements PropelSearchLoopInterface |
31
|
|
|
{ |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param LoopResult $loopResult |
35
|
|
|
* |
36
|
|
|
* @return LoopResult |
37
|
|
|
*/ |
38
|
|
|
public function parseResults(LoopResult $loopResult) |
39
|
|
|
{ |
40
|
|
|
/** @var DealerContact $contact */ |
41
|
|
|
foreach ($loopResult->getResultDataCollection() as $contact) { |
42
|
|
|
$loopResultRow = new LoopResultRow($contact); |
43
|
|
|
|
44
|
|
|
$loopResultRow |
45
|
|
|
->set('ID', $contact->getId()) |
46
|
|
|
->set('DEALER_ID', $contact->getDealerId()) |
47
|
|
|
->set('IS_DEFAULT', $contact->getIsDefault()); |
48
|
|
|
|
49
|
|
|
if ($contact->hasVirtualColumn('i18n_LABEL')) { |
50
|
|
|
$loopResultRow->set("LABEL", $contact->getVirtualColumn('i18n_LABEL')); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$loopResult->addRow($loopResultRow); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
return $loopResult; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Definition of loop arguments |
61
|
|
|
* |
62
|
|
|
* example : |
63
|
|
|
* |
64
|
|
|
* public function getArgDefinitions() |
65
|
|
|
* { |
66
|
|
|
* return new ArgumentCollection( |
67
|
|
|
* |
68
|
|
|
* Argument::createIntListTypeArgument('id'), |
69
|
|
|
* new Argument( |
70
|
|
|
* 'ref', |
71
|
|
|
* new TypeCollection( |
72
|
|
|
* new Type\AlphaNumStringListType() |
73
|
|
|
* ) |
74
|
|
|
* ), |
75
|
|
|
* Argument::createIntListTypeArgument('category'), |
76
|
|
|
* Argument::createBooleanTypeArgument('new'), |
77
|
|
|
* ... |
78
|
|
|
* ); |
79
|
|
|
* } |
80
|
|
|
* |
81
|
|
|
* @return \Thelia\Core\Template\Loop\Argument\ArgumentCollection |
82
|
|
|
*/ |
83
|
|
|
protected function getArgDefinitions() |
84
|
|
|
{ |
85
|
|
|
return new ArgumentCollection( |
86
|
|
|
|
87
|
|
|
Argument::createIntListTypeArgument('id'), |
88
|
|
|
Argument::createIntListTypeArgument('dealer_id'), |
89
|
|
|
Argument::createBooleanTypeArgument("default", null), |
90
|
|
|
Argument::createEnumListTypeArgument('order', [ |
91
|
|
|
'id', |
92
|
|
|
'id-reverse', |
93
|
|
|
'label', |
94
|
|
|
'label-reverse', |
95
|
|
|
'default-first' |
96
|
|
|
], 'id') |
97
|
|
|
|
98
|
|
|
); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* this method returns a Propel ModelCriteria |
103
|
|
|
* |
104
|
|
|
* @return \Propel\Runtime\ActiveQuery\ModelCriteria |
105
|
|
|
*/ |
106
|
|
|
public function buildModelCriteria() |
107
|
|
|
{ |
108
|
|
|
$query = DealerContactQuery::create(); |
109
|
|
|
|
110
|
|
|
// manage translations |
111
|
|
|
$this->configureI18nProcessing( |
112
|
|
|
$query, |
113
|
|
|
[ |
114
|
|
|
'LABEL', |
115
|
|
|
], |
116
|
|
|
null, |
117
|
|
|
'ID', |
118
|
|
|
$this->getForceReturn() |
119
|
|
|
); |
120
|
|
|
|
121
|
|
|
if (null != $default = $this->getDefault()) { |
122
|
|
|
$query->filterByIsDefault($default); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
if ($id = $this->getId()) { |
126
|
|
|
$query->filterById($id); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if ($dealer_id = $this->getDealerId()) { |
130
|
|
|
$query->filterByDealerId($dealer_id); |
131
|
|
|
} |
132
|
|
|
|
133
|
|
|
foreach ($this->getOrder() as $order) { |
134
|
|
|
switch ($order) { |
135
|
|
|
case 'id': |
136
|
|
|
$query->orderById(); |
137
|
|
|
break; |
138
|
|
|
case 'id-reverse': |
139
|
|
|
$query->orderById(Criteria::DESC); |
140
|
|
|
break; |
141
|
|
|
case 'label': |
142
|
|
|
$query->orderByLabel(); |
143
|
|
|
break; |
144
|
|
|
case 'label-reverse': |
145
|
|
|
$query->orderByLabel(Criteria::DESC); |
146
|
|
|
break; |
147
|
|
|
case 'default-first': |
148
|
|
|
$query->orderByIsDefault(Criteria::DESC); |
149
|
|
|
break; |
150
|
|
|
default: |
151
|
|
|
break; |
152
|
|
|
} |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
return $query; |
156
|
|
|
} |
157
|
|
|
} |
158
|
|
|
|