Passed
Push — master ( 161248...6634a3 )
by Aimeos
06:49 queued 03:48
created

Standard   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 286
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
eloc 57
c 3
b 0
f 1
dl 0
loc 286
rs 10
wmc 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A header() 0 35 2
A body() 0 59 2
A domains() 0 18 1
A getAddressStrings() 0 48 2
A supplier() 0 20 2
A data() 0 10 1
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2020-2025
6
 * @package Client
7
 * @subpackage Html
8
 */
9
10
11
namespace Aimeos\Client\Html\Supplier\Detail;
12
13
14
/**
15
 * Default implementation of supplier detail section HTML clients.
16
 *
17
 * @package Client
18
 * @subpackage Html
19
 */
20
class Standard
21
	extends \Aimeos\Client\Html\Common\Client\Factory\Base
22
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface
23
{
24
	/** client/html/supplier/detail/name
25
	 * Class name of the used supplier detail client implementation
26
	 *
27
	 * Each default HTML client can be replace by an alternative imlementation.
28
	 * To use this implementation, you have to set the last part of the class
29
	 * name as configuration value so the client factory knows which class it
30
	 * has to instantiate.
31
	 *
32
	 * For example, if the name of the default class is
33
	 *
34
	 *  \Aimeos\Client\Html\Supplier\Detail\Standard
35
	 *
36
	 * and you want to replace it with your own version named
37
	 *
38
	 *  \Aimeos\Client\Html\Supplier\Detail\Mydetail
39
	 *
40
	 * then you have to set the this configuration option:
41
	 *
42
	 *  client/html/supplier/detail/name = Mydetail
43
	 *
44
	 * The value is the last part of your own class name and it's case sensitive,
45
	 * so take care that the configuration value is exactly named like the last
46
	 * part of the class name.
47
	 *
48
	 * The allowed characters of the class name are A-Z, a-z and 0-9. No other
49
	 * characters are possible! You should always start the last part of the class
50
	 * name with an upper case character and continue only with lower case characters
51
	 * or numbers. Avoid chamel case names like "MyDetail"!
52
	 *
53
	 * @param string Last part of the class name
54
	 * @since 2020.10
55
	 */
56
57
58
	private array $tags = [];
59
	private ?string $expire = null;
60
	private ?\Aimeos\Base\View\Iface $view = null;
61
62
63
	/**
64
	 * Returns the HTML code for insertion into the body.
65
	 *
66
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
67
	 * @return string HTML code
68
	 */
69
	public function body( string $uid = '' ) : string
70
	{
71
		$prefixes = ['f_supid'];
72
73
		/** client/html/supplier/detail/cache
74
		 * Enables or disables caching only for the supplier detail component
75
		 *
76
		 * Disable caching for components can be useful if you would have too much
77
		 * entries to cache or if the component contains non-cacheable parts that
78
		 * can't be replaced using the modify() method.
79
		 *
80
		 * @param boolean True to enable caching, false to disable
81
		 * @since 2020.10
82
		 * @see client/html/supplier/detail/cache
83
		 * @see client/html/supplier/filter/cache
84
		 * @see client/html/supplier/lists/cache
85
		 */
86
87
		/** client/html/supplier/detail
88
		 * All parameters defined for the supplier detail component and its subparts
89
		 *
90
		 * This returns all settings related to the detail component.
91
		 * Please refer to the single settings for details.
92
		 *
93
		 * @param array Associative list of name/value settings
94
		 * @since 2020.10
95
		 * @see client/html/supplier#detail
96
		 */
97
		$confkey = 'client/html/supplier/detail';
98
99
		if( $html = $this->cached( 'body', $uid, $prefixes, $confkey ) ) {
100
			return $this->modify( $html, $uid );
101
		}
102
103
		/** client/html/supplier/detail/template-body
104
		 * Relative path to the HTML body template of the supplier detail client.
105
		 *
106
		 * The template file contains the HTML code and processing instructions
107
		 * to generate the result shown in the body of the frontend. The
108
		 * configuration string is the path to the template file relative
109
		 * to the templates directory (usually in templates/client/html).
110
		 *
111
		 * You can overwrite the template file configuration in extensions and
112
		 * provide alternative templates. These alternative templates should be
113
		 * named like the default one but suffixed by
114
		 * an unique name. You may use the name of your project for this. If
115
		 * you've implemented an alternative client class as well, it
116
		 * should be suffixed by the name of the new class.
117
		 *
118
		 * @param string Relative path to the template creating code for the HTML page body
119
		 * @since 2020.10
120
		 * @see client/html/supplier/detail/template-header
121
		 */
122
		$template = $this->context()->config()->get( 'client/html/supplier/detail/template-body', 'supplier/detail/body' );
123
124
		$view = $this->view = $this->view ?? $this->object()->data( $this->view(), $this->tags, $this->expire );
125
		$html = $this->modify( $view->render( $template ), $uid );
126
127
		return $this->cache( 'body', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire );
128
	}
129
130
131
	/**
132
	 * Returns the HTML string for insertion into the header.
133
	 *
134
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
135
	 * @return string|null String including HTML tags for the header on error
136
	 */
137
	public function header( string $uid = '' ) : ?string
138
	{
139
		$prefixes = ['f_supid'];
140
		$confkey = 'client/html/supplier/detail';
141
142
		if( $html = $this->cached( 'header', $uid, $prefixes, $confkey ) ) {
143
			return $this->modify( $html, $uid );
144
		}
145
146
		/** client/html/supplier/detail/template-header
147
		 * Relative path to the HTML header template of the supplier detail client.
148
		 *
149
		 * The template file contains the HTML code and processing instructions
150
		 * to generate the HTML code that is inserted into the HTML page header
151
		 * of the rendered page in the frontend. The configuration string is the
152
		 * path to the template file relative to the templates directory (usually
153
		 * in templates/client/html).
154
		 *
155
		 * You can overwrite the template file configuration in extensions and
156
		 * provide alternative templates. These alternative templates should be
157
		 * named like the default one but suffixed by
158
		 * an unique name. You may use the name of your project for this. If
159
		 * you've implemented an alternative client class as well, it
160
		 * should be suffixed by the name of the new class.
161
		 *
162
		 * @param string Relative path to the template creating code for the HTML page head
163
		 * @since 2020.10
164
		 * @see client/html/supplier/detail/template-body
165
		 */
166
		$template = $this->context()->config()->get( 'client/html/supplier/detail/template-header', 'supplier/detail/header' );
167
168
		$view = $this->view = $this->view ?? $this->object()->data( $this->view(), $this->tags, $this->expire );
169
		$html = $view->render( $template );
170
171
		return $this->cache( 'header', $uid, $prefixes, $confkey, $html, $this->tags, $this->expire );
172
	}
173
174
175
	/**
176
	 * Sets the necessary parameter values in the view.
177
	 *
178
	 * @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output
179
	 * @param array &$tags Result array for the list of tags that are associated to the output
180
	 * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
181
	 * @return \Aimeos\Base\View\Iface Modified view object
182
	 */
183
	public function data( \Aimeos\Base\View\Iface $view, array &$tags = [], ?string &$expire = null ) : \Aimeos\Base\View\Iface
184
	{
185
		$supplier = $this->supplier( $view );
186
187
		$this->addMetaItems( $supplier, $expire, $tags );
188
189
		$view->detailSupplierItem = $supplier;
190
		$view->detailSupplierAddresses = $this->getAddressStrings( $view, $supplier->getAddressItems() );
191
192
		return parent::data( $view, $tags, $expire );
193
	}
194
195
196
	/**
197
	 * Returns the data domains fetched along with the supplier
198
	 *
199
	 * @return array List of domain names
200
	 */
201
	protected function domains() : array
202
	{
203
		$domains = ['supplier/address', 'media', 'text'];
204
205
		/** client/html/supplier/detail/domains
206
		 * A list of domain names whose items should be available in the supplier detail view template
207
		 *
208
		 * The templates rendering the supplier detail section use the texts and
209
		 * maybe images and attributes associated to the categories. You can
210
		 * configure your own list of domains (attribute, media, price, product,
211
		 * text, etc. are domains) whose items are fetched from the storage.
212
		 * Please keep in mind that the more domains you add to the configuration,
213
		 * the more time is required for fetching the content!
214
		 *
215
		 * @param array List of domain names
216
		 * @since 2020.10
217
		 */
218
		return $this->context()->config()->get( 'client/html/supplier/detail/domains', $domains );
219
	}
220
221
222
	/**
223
	 * Returns the addresses as list of strings
224
	 *
225
	 * @param \Aimeos\Base\View\Iface $view View object
226
	 * @param iterable $addresses List of address items implementing \Aimeos\MShop\Common\Item\Address\Iface
227
	 * @return \Aimeos\Map List of address strings
228
	 */
229
	protected function getAddressStrings( \Aimeos\Base\View\Iface $view, iterable $addresses ) : \Aimeos\Map
230
	{
231
		$list = [];
232
233
		foreach( $addresses as $id => $addr )
234
		{
235
			$list[$id] = preg_replace( "/\n+/m", "\n", trim( sprintf(
236
				/// Address format with company (%1$s), salutation (%2$s), title (%3$s), first name (%4$s), last name (%5$s),
237
				/// address part one (%6$s, e.g street), address part two (%7$s, e.g house number), address part three (%8$s, e.g additional information),
238
				/// postal/zip code (%9$s), city (%10$s), state (%11$s), country (%12$s), language (%13$s),
239
				/// e-mail (%14$s), phone (%15$s), facsimile/telefax (%16$s), web site (%17$s), vatid (%18$s)
240
				$view->translate( 'client', '%1$s
241
%2$s %3$s %4$s %5$s
242
%6$s %7$s
243
%8$s
244
%9$s %10$s
245
%11$s
246
%12$s
247
%13$s
248
%14$s
249
%15$s
250
%16$s
251
%17$s
252
%18$s
253
'
254
				),
255
				$addr->getCompany(),
256
				$view->translate( 'mshop/code', (string) $addr->getSalutation() ),
257
				$addr->getTitle(),
258
				$addr->getFirstName(),
259
				$addr->getLastName(),
260
				$addr->getAddress1(),
261
				$addr->getAddress2(),
262
				$addr->getAddress3(),
263
				$addr->getPostal(),
264
				$addr->getCity(),
265
				$addr->getState(),
266
				$view->translate( 'country', (string) $addr->getCountryId() ),
267
				$view->translate( 'language', (string) $addr->getLanguageId() ),
268
				$addr->getEmail(),
269
				$addr->getTelephone(),
270
				$addr->getTelefax(),
271
				$addr->getWebsite(),
272
				$addr->getVatID()
273
			) ) );
274
		}
275
276
		return map( $list );
277
	}
278
279
280
	/**
281
	 * Returns the supplier item
282
	 *
283
	 * @param \Aimeos\Base\View\Iface $view The view object which generates the HTML output
284
	 * @return \Aimeos\MShop\Supplier\Item\Iface Supplier item
285
	 */
286
	protected function supplier( \Aimeos\Base\View\Iface $view ) : \Aimeos\MShop\Supplier\Item\Iface
287
	{
288
		$context = $this->context();
289
		$config = $context->config();
290
291
		/** client/html/supplier/detail/supid-default
292
		 * The default supplier ID used if none is given as parameter
293
		 *
294
		 * You can configure the default supplier ID if no ID is passed in the
295
		 * URL using this configuration.
296
		 *
297
		 * @param string Supplier ID
298
		 * @since 2021.01
299
		 * @see client/html/catalog/lists/catid-default
300
		 * @see client/html/catalog/detail/prodid-default
301
		 */
302
		$id = $supid = $view->param( 'f_supid', $config->get( 'client/html/supplier/detail/supid-default' ) );
0 ignored issues
show
Unused Code introduced by
The assignment to $supid is dead and can be removed.
Loading history...
303
304
		$cntl = \Aimeos\Controller\Frontend::create( $context, 'supplier' )->uses( $this->domains() );
305
		return $id ? $cntl->get( $id ) : $cntl->resolve( $view->param( 's_name' ) );
306
	}
307
308
309
	/** client/html/supplier/detail/decorators/excludes
310
	 * Excludes decorators added by the "common" option from the supplier detail html client
311
	 *
312
	 * Decorators extend the functionality of a class by adding new aspects
313
	 * (e.g. log what is currently done), executing the methods of the underlying
314
	 * class only in certain conditions (e.g. only for logged in users) or
315
	 * modify what is returned to the caller.
316
	 *
317
	 * This option allows you to remove a decorator added via
318
	 * "client/html/common/decorators/default" before they are wrapped
319
	 * around the html client.
320
	 *
321
	 *  client/html/supplier/detail/decorators/excludes = array( 'decorator1' )
322
	 *
323
	 * This would remove the decorator named "decorator1" from the list of
324
	 * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via
325
	 * "client/html/common/decorators/default" to the html client.
326
	 *
327
	 * @param array List of decorator names
328
	 * @since 2020.10
329
	 * @see client/html/common/decorators/default
330
	 * @see client/html/supplier/detail/decorators/global
331
	 * @see client/html/supplier/detail/decorators/local
332
	 */
333
334
	/** client/html/supplier/detail/decorators/global
335
	 * Adds a list of globally available decorators only to the supplier detail html client
336
	 *
337
	 * Decorators extend the functionality of a class by adding new aspects
338
	 * (e.g. log what is currently done), executing the methods of the underlying
339
	 * class only in certain conditions (e.g. only for logged in users) or
340
	 * modify what is returned to the caller.
341
	 *
342
	 * This option allows you to wrap global decorators
343
	 * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client.
344
	 *
345
	 *  client/html/supplier/detail/decorators/global = array( 'decorator1' )
346
	 *
347
	 * This would add the decorator named "decorator1" defined by
348
	 * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client.
349
	 *
350
	 * @param array List of decorator names
351
	 * @since 2020.10
352
	 * @see client/html/common/decorators/default
353
	 * @see client/html/supplier/detail/decorators/excludes
354
	 * @see client/html/supplier/detail/decorators/local
355
	 */
356
357
	/** client/html/supplier/detail/decorators/local
358
	 * Adds a list of local decorators only to the supplier detail html client
359
	 *
360
	 * Decorators extend the functionality of a class by adding new aspects
361
	 * (e.g. log what is currently done), executing the methods of the underlying
362
	 * class only in certain conditions (e.g. only for logged in users) or
363
	 * modify what is returned to the caller.
364
	 *
365
	 * This option allows you to wrap local decorators
366
	 * ("\Aimeos\Client\Html\Supplier\Decorator\*") around the html client.
367
	 *
368
	 *  client/html/supplier/detail/decorators/local = array( 'decorator2' )
369
	 *
370
	 * This would add the decorator named "decorator2" defined by
371
	 * "\Aimeos\Client\Html\Supplier\Decorator\Decorator2" only to the html client.
372
	 *
373
	 * @param array List of decorator names
374
	 * @since 2020.10
375
	 * @see client/html/common/decorators/default
376
	 * @see client/html/supplier/detail/decorators/excludes
377
	 * @see client/html/supplier/detail/decorators/global
378
	 */
379
}
380