1
|
|
|
<?php namespace VojtaSvoboda\Reservations\Mailers; |
2
|
|
|
|
3
|
|
|
use App; |
4
|
|
|
use Mail; |
5
|
|
|
use Request; |
6
|
|
|
use VojtaSvoboda\Reservations\Models\Reservation; |
7
|
|
|
use VojtaSvoboda\Reservations\Models\Settings; |
8
|
|
|
|
9
|
|
|
class ReservationAdminMailer extends BaseMailer |
10
|
|
|
{ |
11
|
|
|
/** |
12
|
|
|
* Send reservation confirmation mail. |
13
|
|
|
* |
14
|
|
|
* @param Reservation $reservation |
15
|
|
|
* @param int $reservationsCount |
16
|
|
|
*/ |
17
|
|
|
public function send(Reservation $reservation, $reservationsCount = 0) |
18
|
|
|
{ |
19
|
|
|
// init |
20
|
|
|
$locale = App::getLocale(); |
21
|
6 |
|
$appUrl = App::make('url')->to('/'); |
22
|
|
|
$enabled = Settings::get('admin_confirmation_enable'); |
23
|
6 |
|
$recipients = $this->initRecipients(); |
24
|
6 |
|
$recipients['email'] = Settings::get('admin_confirmation_email'); |
25
|
|
|
$recipients['name'] = Settings::get('admin_confirmation_name'); |
26
|
|
|
|
27
|
|
|
// skip if disabled or empty email |
28
|
|
|
if (!$enabled || empty($recipients['email'])) { |
29
|
|
|
return; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
$template = $this->getTemplateIdent('reservation-admin'); |
33
|
|
|
|
34
|
|
|
$templateParameters = [ |
35
|
|
|
'site' => $appUrl, |
36
|
|
|
'reservation' => $reservation, |
37
|
|
|
'locale' => $locale, |
38
|
|
|
'reservationsCount' => $reservationsCount, |
39
|
|
|
]; |
40
|
|
|
|
41
|
|
|
if (App::environment() === 'testing') { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
View Code Duplication |
Mail::send($template, $templateParameters, function($message) use ($recipients) |
|
|
|
|
46
|
|
|
{ |
47
|
|
|
$message->to($recipients['email'], $recipients['name']); |
48
|
|
|
|
49
|
|
|
if (!empty($recipients['bcc_email']) && !empty($recipients['bcc_name'])) { |
50
|
|
|
$message->bcc($recipients['bcc_email'], $recipients['bcc_name']); |
51
|
|
|
} |
52
|
|
|
}); |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.