Passed
Push — master ( fd781a...b1eaa4 )
by Aimeos
08:26
created

Standard::data()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 2
nop 3
dl 0
loc 19
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 * @package Client
7
 * @subpackage Html
8
 */
9
10
11
namespace Aimeos\Client\Html\Email\Account;
12
13
14
/**
15
 * Default implementation of the account creation e-mails
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/email/account/subparts
25
	 * List of HTML sub-clients rendered within the account creation e-mail
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 order of the HTML sub-clients
36
	 * determines the order 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 order of the output by reordering 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 reordering content by a fluid like
51
	 * design.
52
	 *
53
	 * @param array List of sub-client names
54
	 * @since 2015.09
55
	 * @category Developer
56
	 */
57
	private $subPartPath = 'client/html/email/account/subparts';
58
59
	/** client/html/email/account/text/name
60
	 * Name of the text part used by the account creation e-mail client implementation
61
	 *
62
	 * Use "Myname" if your class is named "\Aimeos\Client\Html\Email\Account\Text\Myname".
63
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
64
	 *
65
	 * @param string Last part of the client class name
66
	 * @since 2015.09
67
	 * @category Developer
68
	 */
69
70
	/** client/html/email/account/html/name
71
	 * Name of the html part used by the account creation e-mail client implementation
72
	 *
73
	 * Use "Myname" if your class is named "\Aimeos\Client\Html\Email\Account\Html\Myname".
74
	 * The name is case-sensitive and you should avoid camel case names like "MyName".
75
	 *
76
	 * @param string Last part of the client class name
77
	 * @since 2015.09
78
	 * @category Developer
79
	 */
80
	private $subPartNames = array( 'text', 'html' );
81
82
83
	/**
84
	 * Returns the HTML code for insertion into the body.
85
	 *
86
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
87
	 * @return string HTML code
88
	 */
89
	public function body( string $uid = '' ) : string
90
	{
91
		$view = $this->object()->data( $this->view() );
92
93
		$content = '';
94
		foreach( $this->getSubClients() as $subclient ) {
95
			$content .= $subclient->setView( $view )->body( $uid );
96
		}
97
		$view->accountBody = $content;
98
99
		/** client/html/email/account/template-body
100
		 * Relative path to the HTML body template of the account creation e-mail client.
101
		 *
102
		 * The template file contains the HTML code and processing instructions
103
		 * to generate the result shown in the body of the frontend. The
104
		 * configuration string is the path to the template file relative
105
		 * to the templates directory (usually in client/html/templates).
106
		 *
107
		 * You can overwrite the template file configuration in extensions and
108
		 * provide alternative templates. These alternative templates should be
109
		 * named like the default one but suffixed by
110
		 * an unique name. You may use the name of your project for this. If
111
		 * you've implemented an alternative client class as well, it
112
		 * should be suffixed by the name of the new class.
113
		 *
114
		 * The product notification e-mail HTML client allows to use a different template for
115
		 * each account status value. You can create a template for each account
116
		 * status and store it in the "email/account/<status number>/" directory
117
		 * below the "templates" directory (usually in client/html/templates). If no
118
		 * specific layout template is found, the common template in the
119
		 * "email/account/" directory is used.
120
		 *
121
		 * @param string Relative path to the template creating code for the HTML page body
122
		 * @since 2015.09
123
		 * @category Developer
124
		 * @see client/html/email/account/template-header
125
		 */
126
		$tplconf = 'client/html/email/account/template-body';
127
128
		return $view->render( $view->config( $tplconf, 'email/account/body' ) );
129
	}
130
131
132
	/**
133
	 * Returns the HTML string for insertion into the header.
134
	 *
135
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
136
	 * @return string|null String including HTML tags for the header on error
137
	 */
138
	public function header( string $uid = '' ) : string
139
	{
140
		$config = $this->context()->config();
141
		$view = $this->object()->data( $this->view() );
142
143
144
		$addr = $view->extAddressItem;
145
146
		$msg = $view->mail();
147
		$msg->header( 'X-MailGenerator', 'Aimeos' );
148
		$msg->to( $addr->getEMail(), $addr->getFirstName() . ' ' . $addr->getLastName() );
149
150
151
		$fromName = $config->get( 'resource/email/from-name' );
152
153
		/** client/html/email/from-name
154
		 * @see client/html/email/account/from-email
155
		 */
156
		$fromName = $config->get( 'client/html/email/from-name', $fromName );
157
158
		/** client/html/email/account/from-name
159
		 * Name used when sending account creation e-mails
160
		 *
161
		 * The name of the person or e-mail account that is used for sending all
162
		 * shop related account e-mails to customers. This configuration option
163
		 * overwrite the name set in "client/html/email/from-name".
164
		 *
165
		 * @param string Name shown in the e-mail
166
		 * @since 2015.09
167
		 * @category User
168
		 * @see client/html/email/from-name
169
		 * @see client/html/email/from-email
170
		 * @see client/html/email/reply-email
171
		 * @see client/html/email/bcc-email
172
		 */
173
		$fromNameAccount = $config->get( 'client/html/email/account/from-name', $fromName );
174
175
		$fromEmail = $config->get( 'resource/email/from-email' );
176
177
		/** client/html/email/from-email
178
		 * @see client/html/email/account/from-email
179
		 */
180
		$fromEmail = $config->get( 'client/html/email/from-email', $fromEmail );
181
182
		/** client/html/email/account/from-email
183
		 * E-Mail address used when sending account creation e-mails
184
		 *
185
		 * The e-mail address of the person or account that is used for sending
186
		 * all shop related product notification e-mails to customers. This configuration option
187
		 * overwrites the e-mail address set via "client/html/email/from-email".
188
		 *
189
		 * @param string E-mail address
190
		 * @since 2015.09
191
		 * @category User
192
		 * @see client/html/email/account/from-name
193
		 * @see client/html/email/from-email
194
		 * @see client/html/email/reply-email
195
		 * @see client/html/email/bcc-email
196
		 */
197
		if( ( $fromEmailAccount = $config->get( 'client/html/email/account/from-email', $fromEmail ) ) != null ) {
198
			$msg->from( $fromEmailAccount, $fromNameAccount );
199
		}
200
201
202
		/** client/html/email/reply-name
203
		 * @see client/html/email/account/reply-email
204
		 */
205
		$replyName = $config->get( 'client/html/email/reply-name', $fromName );
206
207
		/** client/html/email/account/reply-name
208
		 * Recipient name displayed when the customer replies to account creation e-mails
209
		 *
210
		 * The name of the person or e-mail account the customer should
211
		 * reply to in case of account related questions or problems. This
212
		 * configuration option overwrites the name set via
213
		 * "client/html/email/reply-name".
214
		 *
215
		 * @param string Name shown in the e-mail
216
		 * @since 2015.09
217
		 * @category User
218
		 * @see client/html/email/account/reply-email
219
		 * @see client/html/email/reply-name
220
		 * @see client/html/email/reply-email
221
		 * @see client/html/email/from-email
222
		 * @see client/html/email/bcc-email
223
		 */
224
		$replyNameAccount = $config->get( 'client/html/email/account/reply-name', $replyName );
225
226
		/** client/html/email/reply-email
227
		 * @see client/html/email/account/reply-email
228
		 */
229
		$replyEmail = $config->get( 'client/html/email/reply-email', $fromEmail );
230
231
		/** client/html/email/account/reply-email
232
		 * E-Mail address used by the customer when replying to account creation e-mails
233
		 *
234
		 * The e-mail address of the person or e-mail account the customer
235
		 * should reply to in case of account related questions or problems.
236
		 * This configuration option overwrites the e-mail address set via
237
		 * "client/html/email/reply-email".
238
		 *
239
		 * @param string E-mail address
240
		 * @since 2015.09
241
		 * @category User
242
		 * @see client/html/email/account/reply-name
243
		 * @see client/html/email/reply-email
244
		 * @see client/html/email/from-email
245
		 * @see client/html/email/bcc-email
246
		 */
247
		if( ( $replyEmailAccount = $config->get( 'client/html/email/account/reply-email', $replyEmail ) ) != null ) {
248
			$msg->replyTo( $replyEmailAccount, $replyNameAccount );
249
		}
250
251
252
		/** client/html/email/bcc-email
253
		 * @see client/html/email/account/bcc-email
254
		 */
255
		$bccEmail = $config->get( 'client/html/email/bcc-email' );
256
257
		/** client/html/email/account/bcc-email
258
		 * E-Mail address all account creation e-mails should be also sent to
259
		 *
260
		 * Using this option you can send a copy of all account related e-mails
261
		 * to a second e-mail account. This can be handy for testing and checking
262
		 * the e-mails sent to customers.
263
		 *
264
		 * It also allows shop owners with a very small volume of orders to be
265
		 * notified about account changes. Be aware that this isn't useful if the
266
		 * order volumne is high or has peeks!
267
		 *
268
		 * This configuration option overwrites the e-mail address set via
269
		 * "client/html/email/bcc-email".
270
		 *
271
		 * @param string|array E-mail address or list of e-mail addresses
272
		 * @since 2015.09
273
		 * @category User
274
		 * @category Developer
275
		 * @see client/html/email/bcc-email
276
		 * @see client/html/email/reply-email
277
		 * @see client/html/email/from-email
278
		 */
279
		if( ( $bccEmailAccount = $config->get( 'client/html/email/account/bcc-email', $bccEmail ) ) != null )
280
		{
281
			foreach( (array) $bccEmailAccount as $emailAddr ) {
282
				$msg->Bcc( $emailAddr );
283
			}
284
		}
285
286
287
		/** client/html/email/account/template-header
288
		 * Relative path to the HTML header template of the account creation e-mail client.
289
		 *
290
		 * The template file contains the HTML code and processing instructions
291
		 * to generate the HTML code that is inserted into the HTML page header
292
		 * of the rendered page in the frontend. The configuration string is the
293
		 * path to the template file relative to the templates directory (usually
294
		 * in client/html/templates).
295
		 *
296
		 * You can overwrite the template file configuration in extensions and
297
		 * provide alternative templates. These alternative templates should be
298
		 * named like the default one but suffixed by
299
		 * an unique name. You may use the name of your project for this. If
300
		 * you've implemented an alternative client class as well, it
301
		 * should be suffixed by the name of the new class.
302
		 *
303
		 * The product notification e-mail HTML client allows to use a different template for
304
		 * each account status value. You can create a template for each account
305
		 * status and store it in the "email/account/<status number>/" directory
306
		 * below the "templates" directory (usually in client/html/templates). If no
307
		 * specific layout template is found, the common template in the
308
		 * "email/account/" directory is used.
309
		 *
310
		 * @param string Relative path to the template creating code for the HTML page head
311
		 * @since 2015.09
312
		 * @category Developer
313
		 * @see client/html/email/account/template-body
314
		 */
315
		$tplconf = 'client/html/email/account/template-header';
316
317
		return $view->render( $view->config( $tplconf, 'email/account/header' ) ); ;
318
	}
319
320
321
	/**
322
	 * Returns the sub-client given by its name.
323
	 *
324
	 * @param string $type Name of the client type
325
	 * @param string|null $name Name of the sub-client (Default if null)
326
	 * @return \Aimeos\Client\Html\Iface Sub-client object
327
	 */
328
	public function getSubClient( string $type, string $name = null ) : \Aimeos\Client\Html\Iface
329
	{
330
		/** client/html/email/account/decorators/excludes
331
		 * Excludes decorators added by the "common" option from the email account html client
332
		 *
333
		 * Decorators extend the functionality of a class by adding new aspects
334
		 * (e.g. log what is currently done), executing the methods of the underlying
335
		 * class only in certain conditions (e.g. only for logged in users) or
336
		 * modify what is returned to the caller.
337
		 *
338
		 * This option allows you to remove a decorator added via
339
		 * "client/html/common/decorators/default" before they are wrapped
340
		 * around the html client.
341
		 *
342
		 *  client/html/email/account/decorators/excludes = array( 'decorator1' )
343
		 *
344
		 * This would remove the decorator named "decorator1" from the list of
345
		 * common decorators ("\Aimeos\Client\Html\Common\Decorator\*") added via
346
		 * "client/html/common/decorators/default" to the html client.
347
		 *
348
		 * @param array List of decorator names
349
		 * @since 2015.09
350
		 * @category Developer
351
		 * @see client/html/common/decorators/default
352
		 * @see client/html/email/account/decorators/global
353
		 * @see client/html/email/account/decorators/local
354
		 */
355
356
		/** client/html/email/account/decorators/global
357
		 * Adds a list of globally available decorators only to the email account html client
358
		 *
359
		 * Decorators extend the functionality of a class by adding new aspects
360
		 * (e.g. log what is currently done), executing the methods of the underlying
361
		 * class only in certain conditions (e.g. only for logged in users) or
362
		 * modify what is returned to the caller.
363
		 *
364
		 * This option allows you to wrap global decorators
365
		 * ("\Aimeos\Client\Html\Common\Decorator\*") around the html client.
366
		 *
367
		 *  client/html/email/account/decorators/global = array( 'decorator1' )
368
		 *
369
		 * This would add the decorator named "decorator1" defined by
370
		 * "\Aimeos\Client\Html\Common\Decorator\Decorator1" only to the html client.
371
		 *
372
		 * @param array List of decorator names
373
		 * @since 2015.09
374
		 * @category Developer
375
		 * @see client/html/common/decorators/default
376
		 * @see client/html/email/account/decorators/excludes
377
		 * @see client/html/email/account/decorators/local
378
		 */
379
380
		/** client/html/email/account/decorators/local
381
		 * Adds a list of local decorators only to the email account html client
382
		 *
383
		 * Decorators extend the functionality of a class by adding new aspects
384
		 * (e.g. log what is currently done), executing the methods of the underlying
385
		 * class only in certain conditions (e.g. only for logged in users) or
386
		 * modify what is returned to the caller.
387
		 *
388
		 * This option allows you to wrap local decorators
389
		 * ("\Aimeos\Client\Html\Email\Decorator\*") around the html client.
390
		 *
391
		 *  client/html/email/account/decorators/local = array( 'decorator2' )
392
		 *
393
		 * This would add the decorator named "decorator2" defined by
394
		 * "\Aimeos\Client\Html\Email\Decorator\Decorator2" only to the html client.
395
		 *
396
		 * @param array List of decorator names
397
		 * @since 2015.09
398
		 * @category Developer
399
		 * @see client/html/common/decorators/default
400
		 * @see client/html/email/account/decorators/excludes
401
		 * @see client/html/email/account/decorators/global
402
		 */
403
404
		return $this->createSubClient( 'email/account/' . $type, $name );
405
	}
406
407
408
	/**
409
	 * Returns the list of sub-client names configured for the client.
410
	 *
411
	 * @return array List of HTML client names
412
	 */
413
	protected function getSubClientNames() : array
414
	{
415
		return $this->context()->config()->get( $this->subPartPath, $this->subPartNames );
416
	}
417
418
419
	/**
420
	 * Sets the necessary parameter values in the view.
421
	 *
422
	 * @param \Aimeos\MW\View\Iface $view The view object which generates the HTML output
423
	 * @param array &$tags Result array for the list of tags that are associated to the output
424
	 * @param string|null &$expire Result variable for the expiration date of the output (null for no expiry)
425
	 * @return \Aimeos\MW\View\Iface Modified view object
426
	 */
427
	public function data( \Aimeos\MW\View\Iface $view, array &$tags = [], string &$expire = null ) : \Aimeos\MW\View\Iface
428
	{
429
		$addr = $view->get( 'extAddressItem' );
430
		$list = [
431
			/// E-mail intro with first name (%1$s) and last name (%2$s)
432
			\Aimeos\MShop\Common\Item\Address\Base::SALUTATION_UNKNOWN => $view->translate( 'client', 'Dear %1$s %2$s' ),
433
			/// E-mail intro with first name (%1$s) and last name (%2$s)
434
			\Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MR => $view->translate( 'client', 'Dear Mr %1$s %2$s' ),
435
			/// E-mail intro with first name (%1$s) and last name (%2$s)
436
			\Aimeos\MShop\Common\Item\Address\Base::SALUTATION_MS => $view->translate( 'client', 'Dear Ms %1$s %2$s' ),
437
		];
438
439
		if( $addr && isset( $list[$addr->getSalutation()] ) ) {
440
			$view->emailIntro = sprintf( $list[$addr->getSalutation()], $addr->getFirstName(), $addr->getLastName() );
441
		} else {
442
			$view->emailIntro = $view->translate( 'client', 'Dear customer' );
443
		}
444
445
		return parent::data( $view, $tags, $expire );
446
	}
447
}
448