1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
5
|
|
|
* @copyright Aimeos (aimeos.org), 2019-2020 |
6
|
|
|
* @package Client |
7
|
|
|
* @subpackage Html |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
|
11
|
|
|
namespace Aimeos\Client\Html\Account\Review\Todo; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Default implementation of acount review todo HTML client. |
16
|
|
|
* |
17
|
|
|
* @package Client |
18
|
|
|
* @subpackage Html |
19
|
|
|
*/ |
20
|
|
|
class Standard |
21
|
|
|
extends \Aimeos\Client\Html\Common\Client\Summary\Base |
22
|
|
|
implements \Aimeos\Client\Html\Common\Client\Factory\Iface |
23
|
|
|
{ |
24
|
|
|
/** client/html/account/review/todo/standard/subparts |
25
|
|
|
* List of HTML sub-clients rendered within the account review todo section |
26
|
|
|
* |
27
|
|
|
* The output of the frontend is composed of the code generated by the HTML |
28
|
|
|
* clients. Each HTML client can consist of serveral (or none) sub-clients |
29
|
|
|
* that are responsible for rendering certain sub-parts of the output. The |
30
|
|
|
* sub-clients can contain HTML clients themselves and therefore a |
31
|
|
|
* hierarchical tree of HTML clients is composed. Each HTML client creates |
32
|
|
|
* the output that is placed inside the container of its parent. |
33
|
|
|
* |
34
|
|
|
* At first, always the HTML code generated by the parent is printed, then |
35
|
|
|
* the HTML code of its sub-clients. The todo of the HTML sub-clients |
36
|
|
|
* determines the todo of the output of these sub-clients inside the parent |
37
|
|
|
* container. If the configured list of clients is |
38
|
|
|
* |
39
|
|
|
* array( "subclient1", "subclient2" ) |
40
|
|
|
* |
41
|
|
|
* you can easily change the todo of the output by retodoing the subparts: |
42
|
|
|
* |
43
|
|
|
* client/html/<clients>/subparts = array( "subclient1", "subclient2" ) |
44
|
|
|
* |
45
|
|
|
* You can also remove one or more parts if they shouldn't be rendered: |
46
|
|
|
* |
47
|
|
|
* client/html/<clients>/subparts = array( "subclient1" ) |
48
|
|
|
* |
49
|
|
|
* As the clients only generates structural HTML, the layout defined via CSS |
50
|
|
|
* should support adding, removing or retodoing content by a fluid like |
51
|
|
|
* design. |
52
|
|
|
* |
53
|
|
|
* @param array List of sub-client names |
54
|
|
|
* @since 2019.07 |
55
|
|
|
* @category Developer |
56
|
|
|
*/ |
57
|
|
|
private $subPartPath = 'client/html/account/review/todo/standard/subparts'; |
58
|
|
|
private $subPartNames = []; |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Returns the HTML code for insertion into the body. |
63
|
|
|
* |
64
|
|
|
* @param string $uid Unique identifier for the output if the content is placed more than once on the same page |
65
|
|
|
* @return string HTML code |
66
|
|
|
*/ |
67
|
|
|
public function getBody( string $uid = '' ) : string |
68
|
|
|
{ |
69
|
|
|
$view = $this->getView(); |
70
|
|
|
|
71
|
|
|
$html = ''; |
72
|
|
|
foreach( $this->getSubClients() as $subclient ) { |
73
|
|
|
$html .= $subclient->setView( $view )->getBody( $uid ); |
74
|
|
|
} |
75
|
|
|
$view->todoBody = $html; |
76
|
|
|
|
77
|
|
|
/** client/html/account/review/todo/standard/template-body |
78
|
|
|
* Relative path to the HTML body template of the account review todo client. |
79
|
|
|
* |
80
|
|
|
* The template file contains the HTML code and processing instructions |
81
|
|
|
* to generate the result shown in the body of the frontend. The |
82
|
|
|
* configuration string is the path to the template file relative |
83
|
|
|
* to the templates directory (usually in client/html/templates). |
84
|
|
|
* |
85
|
|
|
* You can overwrite the template file configuration in extensions and |
86
|
|
|
* provide alternative templates. These alternative templates should be |
87
|
|
|
* named like the default one but with the string "standard" replaced by |
88
|
|
|
* an unique name. You may use the name of your project for this. If |
89
|
|
|
* you've implemented an alternative client class as well, "standard" |
90
|
|
|
* should be replaced by the name of the new class. |
91
|
|
|
* |
92
|
|
|
* @param string Relative path to the template creating code for the HTML page body |
93
|
|
|
* @since 2019.07 |
94
|
|
|
* @category Developer |
95
|
|
|
* @see client/html/account/review/todo/standard/template-header |
96
|
|
|
*/ |
97
|
|
|
$tplconf = 'client/html/account/review/todo/standard/template-body'; |
98
|
|
|
$default = 'account/review/todo-body-standard'; |
99
|
|
|
|
100
|
|
|
return $view->render( $view->config( $tplconf, $default ) ); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* Returns the sub-client given by its name. |
106
|
|
|
* |
107
|
|
|
* @param string $type Name of the client type |
108
|
|
|
* @param string|null $name Name of the sub-client (Default if null) |
109
|
|
|
* @return \Aimeos\Client\Html\Iface Sub-client object |
110
|
|
|
*/ |
111
|
|
|
public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface |
112
|
|
|
{ |
113
|
|
|
/** client/html/account/review/todo/decorators/excludes |
114
|
|
|
* Excludes decorators added by the "common" option from the account review todo html client |
115
|
|
|
* |
116
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
117
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
118
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
119
|
|
|
* modify what is returned to the caller. |
120
|
|
|
* |
121
|
|
|
* This option allows you to remove a decorator added via |
122
|
|
|
* "client/html/common/decorators/default" before they are wrapped |
123
|
|
|
* around the html client. |
124
|
|
|
* |
125
|
|
|
* client/html/account/review/todo/decorators/excludes = array( 'decorator1' ) |
126
|
|
|
* |
127
|
|
|
* This would remove the decorator named "decorator1" from the list of |
128
|
|
|
* common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via |
129
|
|
|
* "client/html/common/decorators/default" to the html client. |
130
|
|
|
* |
131
|
|
|
* @param array List of decorator names |
132
|
|
|
* @since 2019.07 |
133
|
|
|
* @category Developer |
134
|
|
|
* @see client/html/common/decorators/default |
135
|
|
|
* @see client/html/account/review/todo/decorators/global |
136
|
|
|
* @see client/html/account/review/todo/decorators/local |
137
|
|
|
*/ |
138
|
|
|
|
139
|
|
|
/** client/html/account/review/todo/decorators/global |
140
|
|
|
* Adds a list of globally available decorators only to the account review todo html client |
141
|
|
|
* |
142
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
143
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
144
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
145
|
|
|
* modify what is returned to the caller. |
146
|
|
|
* |
147
|
|
|
* This option allows you to wrap global decorators |
148
|
|
|
* ("\Aimeos\Client\Html\Common\Decorator\*") around the html client. |
149
|
|
|
* |
150
|
|
|
* client/html/account/review/todo/decorators/global = array( 'decorator1' ) |
151
|
|
|
* |
152
|
|
|
* This would add the decorator named "decorator1" defined by |
153
|
|
|
* "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client. |
154
|
|
|
* |
155
|
|
|
* @param array List of decorator names |
156
|
|
|
* @since 2019.07 |
157
|
|
|
* @category Developer |
158
|
|
|
* @see client/html/common/decorators/default |
159
|
|
|
* @see client/html/account/review/todo/decorators/excludes |
160
|
|
|
* @see client/html/account/review/todo/decorators/local |
161
|
|
|
*/ |
162
|
|
|
|
163
|
|
|
/** client/html/account/review/todo/decorators/local |
164
|
|
|
* Adds a list of local decorators only to the account review todo html client |
165
|
|
|
* |
166
|
|
|
* Decorators extend the functionality of a class by adding new aspects |
167
|
|
|
* (e.g. log what is currently done), executing the methods of the underlying |
168
|
|
|
* class only in certain conditions (e.g. only for logged in users) or |
169
|
|
|
* modify what is returned to the caller. |
170
|
|
|
* |
171
|
|
|
* This option allows you to wrap local decorators |
172
|
|
|
* ("\Aimeos\Client\Html\Account\Decorator\*") around the html client. |
173
|
|
|
* |
174
|
|
|
* client/html/account/review/todo/decorators/local = array( 'decorator2' ) |
175
|
|
|
* |
176
|
|
|
* This would add the decorator named "decorator2" defined by |
177
|
|
|
* "\Aimeos\Client\Html\Account\Decorator\Decorator2" only to the html client. |
178
|
|
|
* |
179
|
|
|
* @param array List of decorator names |
180
|
|
|
* @since 2019.07 |
181
|
|
|
* @category Developer |
182
|
|
|
* @see client/html/common/decorators/default |
183
|
|
|
* @see client/html/account/review/todo/decorators/excludes |
184
|
|
|
* @see client/html/account/review/todo/decorators/global |
185
|
|
|
*/ |
186
|
|
|
|
187
|
|
|
return $this->createSubClient( 'account/review/todo/' . $type, $name ); |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* Processes the input, e.g. store given values. |
193
|
|
|
* |
194
|
|
|
* A view must be available and this method doesn't generate any output |
195
|
|
|
* besides setting view variables if necessary. |
196
|
|
|
*/ |
197
|
|
|
public function process() |
198
|
|
|
{ |
199
|
|
|
$view = $this->getView(); |
|
|
|
|
200
|
|
|
|
201
|
|
|
|
202
|
|
|
parent::process(); |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
|
206
|
|
|
/** |
207
|
|
|
* Sets the necessary parameter values in the view. |
208
|
|
|
* |
209
|
|
|
* @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output |
210
|
|
|
* @param array &$tags Result array for the list of tags that are associated to the output |
211
|
|
|
* @param string|null &$expire Result variable for the expiration date of the output (null for no expiry) |
212
|
|
|
* @return \Aimeos\MW\View\Iface Modified view object |
213
|
|
|
*/ |
214
|
|
|
public function addData( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface |
215
|
|
|
{ |
216
|
|
|
$products = []; |
217
|
|
|
$context = $this->getContext(); |
218
|
|
|
|
219
|
|
|
$orders = \Aimeos\Controller\Frontend::create( $context, 'order' ) |
220
|
|
|
->uses( ['order/base', 'order/base/product'] ) |
221
|
|
|
->sort( '-order.base.ctime' ) |
222
|
|
|
->slice( 0, 25 ) |
223
|
|
|
->search(); |
224
|
|
|
|
225
|
|
|
$prodIds = $orders->getBaseItem()->getProducts()->flat()->getProductId()->unique(); |
226
|
|
|
|
227
|
|
|
$exclude = \Aimeos\Controller\Frontend::create( $context, 'review' ) |
228
|
|
|
->for( 'product', $prodIds ) |
229
|
|
|
->slice( 0, $prodIds->count() ) |
230
|
|
|
->list()->getRefId(); |
231
|
|
|
|
232
|
|
|
$productItems = \Aimeos\Controller\Frontend::create( $context, 'product' ) |
233
|
|
|
->product( $prodIds->diff( $exclude )->toArray() ) |
234
|
|
|
->uses( ['text' => ['name'], 'media' => ['default']] ) |
235
|
|
|
->search(); |
236
|
|
|
$productItems->keys()->dump(); |
237
|
|
|
|
238
|
|
|
foreach( $prodIds as $prodId ) { |
239
|
|
|
$products[$prodId] = $productItems->get( $prodId ); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
$view->todoProductItems = map( $products )->filter(); |
243
|
|
|
|
244
|
|
|
return parent::addData( $view, $tags, $expire ); |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Returns the list of sub-client names configured for the client. |
250
|
|
|
* |
251
|
|
|
* @return array List of HTML client names |
252
|
|
|
*/ |
253
|
|
|
protected function getSubClientNames() : array |
254
|
|
|
{ |
255
|
|
|
return $this->getContext()->getConfig()->get( $this->subPartPath, $this->subPartNames ); |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
|