|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Rinvex\Bookings\Traits; |
|
6
|
|
|
|
|
7
|
|
|
use Carbon\Carbon; |
|
8
|
|
|
use Illuminate\Database\Eloquent\Relations\MorphMany; |
|
9
|
|
|
|
|
10
|
|
|
trait BookingScopes |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* Get past bookings. |
|
14
|
|
|
* |
|
15
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
16
|
|
|
*/ |
|
17
|
|
|
public function pastBookings(): MorphMany |
|
18
|
|
|
{ |
|
19
|
|
|
return $this->bookings() |
|
|
|
|
|
|
20
|
|
|
->whereNull('canceled_at') |
|
21
|
|
|
->whereNotNull('ends_at') |
|
22
|
|
|
->where('ends_at', '<', now()); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Get future bookings. |
|
27
|
|
|
* |
|
28
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
29
|
|
|
*/ |
|
30
|
|
|
public function futureBookings(): MorphMany |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->bookings() |
|
|
|
|
|
|
33
|
|
|
->whereNull('canceled_at') |
|
34
|
|
|
->whereNotNull('starts_at') |
|
35
|
|
|
->where('starts_at', '>', now()); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get current bookings. |
|
40
|
|
|
* |
|
41
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
42
|
|
|
*/ |
|
43
|
|
|
public function currentBookings(): MorphMany |
|
44
|
|
|
{ |
|
45
|
|
|
return $this->bookings() |
|
|
|
|
|
|
46
|
|
|
->whereNull('canceled_at') |
|
47
|
|
|
->whereNotNull('starts_at') |
|
48
|
|
|
->whereNotNull('ends_at') |
|
49
|
|
|
->where('starts_at', '<', now()) |
|
50
|
|
|
->where('ends_at', '>', now()); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get cancelled bookings. |
|
55
|
|
|
* |
|
56
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
57
|
|
|
*/ |
|
58
|
|
|
public function cancelledBookings(): MorphMany |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->bookings() |
|
|
|
|
|
|
61
|
|
|
->whereNotNull('canceled_at'); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* Get bookings starts before the given date. |
|
66
|
|
|
* |
|
67
|
|
|
* @param string $date |
|
68
|
|
|
* |
|
69
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
70
|
|
|
*/ |
|
71
|
|
|
public function bookingsStartsBefore(string $date): MorphMany |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->bookings() |
|
|
|
|
|
|
74
|
|
|
->whereNull('canceled_at') |
|
75
|
|
|
->whereNotNull('starts_at') |
|
76
|
|
|
->where('starts_at', '<', new Carbon($date)); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Get bookings starts after the given date. |
|
81
|
|
|
* |
|
82
|
|
|
* @param string $date |
|
83
|
|
|
* |
|
84
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
85
|
|
|
*/ |
|
86
|
|
|
public function bookingsStartsAfter(string $date): MorphMany |
|
87
|
|
|
{ |
|
88
|
|
|
return $this->bookings() |
|
|
|
|
|
|
89
|
|
|
->whereNull('canceled_at') |
|
90
|
|
|
->whereNotNull('starts_at') |
|
91
|
|
|
->where('starts_at', '>', new Carbon($date)); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get bookings starts between the given dates. |
|
96
|
|
|
* |
|
97
|
|
|
* @param string $startsAt |
|
98
|
|
|
* @param string $endsAt |
|
99
|
|
|
* |
|
100
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
101
|
|
|
*/ |
|
102
|
|
|
public function bookingsStartsBetween(string $startsAt, string $endsAt): MorphMany |
|
103
|
|
|
{ |
|
104
|
|
|
return $this->bookings() |
|
|
|
|
|
|
105
|
|
|
->whereNull('canceled_at') |
|
106
|
|
|
->whereNotNull('starts_at') |
|
107
|
|
|
->where('starts_at', '>', new Carbon($startsAt)) |
|
108
|
|
|
->where('starts_at', '<', new Carbon($endsAt)); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Get bookings ends before the given date. |
|
113
|
|
|
* |
|
114
|
|
|
* @param string $date |
|
115
|
|
|
* |
|
116
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
117
|
|
|
*/ |
|
118
|
|
|
public function bookingsEndsBefore(string $date): MorphMany |
|
119
|
|
|
{ |
|
120
|
|
|
return $this->bookings() |
|
|
|
|
|
|
121
|
|
|
->whereNull('canceled_at') |
|
122
|
|
|
->whereNotNull('ends_at') |
|
123
|
|
|
->where('ends_at', '<', new Carbon($date)); |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get bookings ends after the given date. |
|
128
|
|
|
* |
|
129
|
|
|
* @param string $date |
|
130
|
|
|
* |
|
131
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
132
|
|
|
*/ |
|
133
|
|
|
public function bookingsEndsAfter(string $date): MorphMany |
|
134
|
|
|
{ |
|
135
|
|
|
return $this->bookings() |
|
|
|
|
|
|
136
|
|
|
->whereNull('canceled_at') |
|
137
|
|
|
->whereNotNull('ends_at') |
|
138
|
|
|
->where('ends_at', '>', new Carbon($date)); |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* Get bookings ends between the given dates. |
|
143
|
|
|
* |
|
144
|
|
|
* @param string $startsAt |
|
145
|
|
|
* @param string $endsAt |
|
146
|
|
|
* |
|
147
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
148
|
|
|
*/ |
|
149
|
|
|
public function bookingsEndsBetween(string $startsAt, string $endsAt): MorphMany |
|
150
|
|
|
{ |
|
151
|
|
|
return $this->bookings() |
|
|
|
|
|
|
152
|
|
|
->whereNull('canceled_at') |
|
153
|
|
|
->whereNotNull('ends_at') |
|
154
|
|
|
->where('ends_at', '>', new Carbon($startsAt)) |
|
155
|
|
|
->where('ends_at', '<', new Carbon($endsAt)); |
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
/** |
|
159
|
|
|
* Get bookings cancelled before the given date. |
|
160
|
|
|
* |
|
161
|
|
|
* @param string $date |
|
162
|
|
|
* |
|
163
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
164
|
|
|
*/ |
|
165
|
|
|
public function bookingsCancelledBefore(string $date): MorphMany |
|
166
|
|
|
{ |
|
167
|
|
|
return $this->bookings() |
|
|
|
|
|
|
168
|
|
|
->whereNotNull('canceled_at') |
|
169
|
|
|
->where('canceled_at', '<', new Carbon($date)); |
|
170
|
|
|
} |
|
171
|
|
|
|
|
172
|
|
|
/** |
|
173
|
|
|
* Get bookings cancelled after the given date. |
|
174
|
|
|
* |
|
175
|
|
|
* @param string $date |
|
176
|
|
|
* |
|
177
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
178
|
|
|
*/ |
|
179
|
|
|
public function bookingsCancelledAfter(string $date): MorphMany |
|
180
|
|
|
{ |
|
181
|
|
|
return $this->bookings() |
|
|
|
|
|
|
182
|
|
|
->whereNotNull('canceled_at') |
|
183
|
|
|
->where('canceled_at', '>', new Carbon($date)); |
|
184
|
|
|
} |
|
185
|
|
|
|
|
186
|
|
|
/** |
|
187
|
|
|
* Get bookings cancelled between the given dates. |
|
188
|
|
|
* |
|
189
|
|
|
* @param string $startsAt |
|
190
|
|
|
* @param string $endsAt |
|
191
|
|
|
* |
|
192
|
|
|
* @return \Illuminate\Database\Eloquent\Relations\MorphMany |
|
193
|
|
|
*/ |
|
194
|
|
|
public function bookingsCancelledBetween(string $startsAt, string $endsAt): MorphMany |
|
195
|
|
|
{ |
|
196
|
|
|
return $this->bookings() |
|
|
|
|
|
|
197
|
|
|
->whereNotNull('canceled_at') |
|
198
|
|
|
->where('canceled_at', '>', new Carbon($startsAt)) |
|
199
|
|
|
->where('canceled_at', '<', new Carbon($endsAt)); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.