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
|
5 |
|
public function send(Reservation $reservation, $reservationsCount = 0) |
18
|
|
|
{ |
19
|
|
|
// init |
20
|
5 |
|
$locale = App::getLocale(); |
21
|
5 |
|
$appUrl = App::make('url')->to('/'); |
22
|
5 |
|
$enabled = Settings::get('admin_confirmation_enable'); |
23
|
5 |
|
$templateLocale = Settings::get('admin_confirmation_locale'); |
24
|
5 |
|
$recipients = $this->initRecipients(); |
25
|
5 |
|
$recipients['email'] = Settings::get('admin_confirmation_email'); |
26
|
5 |
|
$recipients['name'] = Settings::get('admin_confirmation_name'); |
27
|
|
|
|
28
|
|
|
// skip if disabled or empty email |
29
|
5 |
|
if (!$enabled || empty($recipients['email'])) { |
30
|
5 |
|
return; |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
$template = $this->getTemplateIdent('reservation-admin', $templateLocale); |
34
|
|
|
|
35
|
|
|
$templateParameters = [ |
36
|
|
|
'site' => $appUrl, |
37
|
|
|
'reservation' => $reservation, |
38
|
|
|
'locale' => $locale, |
39
|
|
|
'reservationsCount' => $reservationsCount, |
40
|
|
|
]; |
41
|
|
|
|
42
|
|
|
if (App::environment() === 'testing') { |
43
|
|
|
return; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
View Code Duplication |
Mail::send($template, $templateParameters, function($message) use ($recipients) |
47
|
|
|
{ |
48
|
|
|
$message->to($recipients['email'], $recipients['name']); |
49
|
|
|
|
50
|
|
|
if (!empty($recipients['bcc_email']) && !empty($recipients['bcc_name'])) { |
51
|
|
|
$message->bcc($recipients['bcc_email'], $recipients['bcc_name']); |
52
|
|
|
} |
53
|
|
|
}); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|