Completed
Push — master ( b9f1e5...5ff555 )
by Aimeos
11:02
created

Standard   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 202
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 202
rs 10
c 0
b 0
f 0

4 Methods

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