forked from tastyigniter/ti-ext-reservation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtension.php
100 lines (83 loc) · 3.68 KB
/
Extension.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
namespace Igniter\Reservation;
use Admin\Models\Reservations_model;
use Admin\Models\Status_history_model;
use Igniter\Reservation\Listeners\MaxGuestSizePerTimeslotReached;
use Illuminate\Support\Facades\Event;
class Extension extends \System\Classes\BaseExtension
{
public function boot()
{
$this->bindReservationEvent();
}
public function registerComponents()
{
return [
'Igniter\Reservation\Components\Booking' => [
'code' => 'booking',
'name' => 'lang:igniter.reservation::default.text_component_title',
'description' => 'lang:igniter.reservation::default.text_component_desc',
],
'Igniter\Reservation\Components\Reservations' => [
'code' => 'accountReservations',
'name' => 'lang:igniter.reservation::default.reservations.component_title',
'description' => 'lang:igniter.reservation::default.reservations.component_desc',
],
];
}
public function registerMailTemplates()
{
return [
'igniter.reservation::mail.reservation' => 'Reservation confirmation email to customer',
'igniter.reservation::mail.reservation_alert' => 'New reservation alert email to admin',
];
}
public function registerActivityTypes()
{
return [
ActivityTypes\ReservationCreated::class => 'reservationCreated',
];
}
public function registerAutomationRules()
{
return [
'events' => [
'igniter.reservation.confirmed' => \Igniter\Reservation\AutomationRules\Events\NewReservation::class,
'igniter.reservation.statusAdded' => \Igniter\Reservation\AutomationRules\Events\NewReservationStatus::class,
'igniter.reservation.assigned' => \Igniter\Reservation\AutomationRules\Events\ReservationAssigned::class,
],
'actions' => [],
'conditions' => [
\Igniter\Reservation\AutomationRules\Conditions\ReservationAttribute::class,
\Igniter\Reservation\AutomationRules\Conditions\ReservationStatusAttribute::class,
],
];
}
protected function bindReservationEvent()
{
Event::subscribe(MaxGuestSizePerTimeslotReached::class);
Event::listen('igniter.reservation.confirmed', function (Reservations_model $model) {
ActivityTypes\ReservationCreated::log($model);
$model->mailSend('igniter.reservation::mail.reservation', 'customer');
$model->mailSend('igniter.reservation::mail.reservation_alert', 'location');
$model->mailSend('igniter.reservation::mail.reservation_alert', 'admin');
});
Event::listen('admin.statusHistory.beforeAddStatus', function ($model, $object, $statusId, $previousStatus) {
if (!$object instanceof Reservations_model)
return;
if (Status_history_model::alreadyExists($object, $statusId))
return;
Event::fire('igniter.reservation.beforeAddStatus', [$model, $object, $statusId, $previousStatus], TRUE);
});
Event::listen('admin.statusHistory.added', function ($model, $statusHistory) {
if (!$model instanceof Reservations_model)
return;
Event::fire('igniter.reservation.statusAdded', [$model, $statusHistory], TRUE);
});
Event::listen('admin.assignable.assigned', function ($model, $assignableLog) {
if (!$model instanceof Reservations_model)
return;
Event::fire('igniter.reservation.assigned', [$model, $assignableLog], TRUE);
});
}
}