|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Timegridio\Concierge\Booking\Strategies\BookingStrategy; |
|
7
|
|
|
use Timegridio\Concierge\Calendar\VacancyCalendar; |
|
8
|
|
|
use Timegridio\Concierge\Models\Business; |
|
9
|
|
|
use Timegridio\Concierge\Models\Service; |
|
10
|
|
|
|
|
11
|
|
|
/******************************************************************************* |
|
12
|
|
|
* Concierge Service Layer |
|
13
|
|
|
* High level booking manager |
|
14
|
|
|
******************************************************************************/ |
|
15
|
|
|
class Concierge extends Workspace |
|
16
|
|
|
{ |
|
17
|
|
|
protected $strategy = null; |
|
18
|
|
|
|
|
19
|
|
|
protected $vacancyCalendar = null; |
|
20
|
|
|
|
|
21
|
|
|
protected function strategy() |
|
22
|
|
|
{ |
|
23
|
|
|
if ($this->strategy === null) { |
|
24
|
|
|
$this->strategy = new BookingStrategy($this->business->strategy); |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
return $this->strategy; |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
protected function vacancyCalendar() |
|
31
|
|
|
{ |
|
32
|
|
|
if ($this->vacancyCalendar === null) { |
|
33
|
|
|
$this->vacancyCalendar = new VacancyCalendar($this->strategy, $this->business->vacancies()); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
return $this->vacancyCalendar; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function takeReservation($request) |
|
|
|
|
|
|
40
|
|
|
{ |
|
41
|
|
|
// $datetime = $this->makeDateTimeUTC($request['date'], $request['time'], $request['timezone']); |
|
|
|
|
|
|
42
|
|
|
// |
|
43
|
|
|
// $appointment = $this->strategy()->generateAppointment( |
|
44
|
|
|
// $request['issuer'], |
|
45
|
|
|
// $this->business, |
|
46
|
|
|
// $request['contact'], |
|
47
|
|
|
// $request['service'], |
|
48
|
|
|
// $datetime, |
|
49
|
|
|
// $request['comments'] |
|
50
|
|
|
// ); |
|
51
|
|
|
// |
|
52
|
|
|
// if ($appointment->duplicates()) { |
|
53
|
|
|
// return $appointment; |
|
54
|
|
|
// // throw new \Exception('Duplicated Appointment Attempted'); |
|
55
|
|
|
// } |
|
56
|
|
|
// |
|
57
|
|
|
// $vacancy = $this->vacancyCalendar()->getSlotFor($appointment->start_at, $appointment->finish_at, $appointment->service->id); |
|
58
|
|
|
// |
|
59
|
|
|
// if ($vacancy != null) { |
|
60
|
|
|
// $appointment->vacancy()->associate($vacancy); |
|
61
|
|
|
// $appointment->save(); |
|
62
|
|
|
// |
|
63
|
|
|
// return $appointment; |
|
64
|
|
|
// } |
|
65
|
|
|
// |
|
66
|
|
|
// return false; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
protected function makeDateTimeUTC($date, $time, $timezone = null) |
|
70
|
|
|
{ |
|
71
|
|
|
if ($timezone === null) { |
|
72
|
|
|
$timezone = $this->business->timezone; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return Carbon::parse("{$date} {$time} {$timezone}")->timezone('UTC'); |
|
76
|
|
|
} |
|
77
|
|
|
} |
|
78
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.