1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge\Presenters; |
4
|
|
|
|
5
|
|
|
use McCool\LaravelAutoPresenter\BasePresenter; |
6
|
|
|
use Timegridio\Concierge\Models\Appointment; |
7
|
|
|
|
8
|
|
|
class AppointmentPresenter extends BasePresenter |
9
|
|
|
{ |
10
|
10 |
|
public function __construct(Appointment $resource) |
11
|
|
|
{ |
12
|
10 |
|
$this->wrappedObject = $resource; |
13
|
10 |
|
} |
14
|
|
|
|
15
|
1 |
|
public function code() |
16
|
|
|
{ |
17
|
1 |
|
$length = $this->wrappedObject->business->pref('appointment_code_length'); |
18
|
|
|
|
19
|
1 |
|
return strtoupper(substr($this->wrappedObject->hash, 0, $length)); |
20
|
|
|
} |
21
|
|
|
|
22
|
3 |
|
public function date($format = 'Y-m-d') |
23
|
|
|
{ |
24
|
3 |
|
if ($this->wrappedObject->start_at->isToday()) { |
25
|
1 |
|
return studly_case(trans('Concierge::appointments.text.today')); |
|
|
|
|
26
|
|
|
} |
27
|
|
|
|
28
|
2 |
|
if ($this->wrappedObject->start_at->isTomorrow()) { |
29
|
1 |
|
return studly_case(trans('Concierge::appointments.text.tomorrow')); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
1 |
|
return $this->wrappedObject |
33
|
1 |
|
->start_at |
34
|
1 |
|
->timezone($this->wrappedObject->business->timezone) |
35
|
1 |
|
->format($format); |
36
|
|
|
} |
37
|
|
|
|
38
|
1 |
|
public function time() |
39
|
|
|
{ |
40
|
1 |
|
$timeFormat = $this->timeFormat(); |
41
|
|
|
|
42
|
1 |
|
return $this->wrappedObject |
43
|
1 |
|
->start_at |
44
|
1 |
|
->timezone($this->wrappedObject->business->timezone) |
45
|
1 |
|
->format($timeFormat); |
46
|
|
|
} |
47
|
|
|
|
48
|
2 |
|
public function arriveAt() |
49
|
|
|
{ |
50
|
2 |
|
$timeFormat = $this->timeFormat(); |
51
|
|
|
|
52
|
2 |
|
if (!$this->wrappedObject->business->pref('appointment_flexible_arrival')) { |
53
|
1 |
|
return ['at' => $this->time]; |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
$fromTime = $this->wrappedObject |
57
|
1 |
|
->vacancy |
58
|
1 |
|
->start_at |
59
|
1 |
|
->timezone($this->wrappedObject->business->timezone) |
60
|
1 |
|
->format($timeFormat); |
61
|
|
|
|
62
|
1 |
|
$toTime = $this->wrappedObject |
63
|
1 |
|
->vacancy |
64
|
1 |
|
->finish_at |
65
|
1 |
|
->timezone($this->wrappedObject->business->timezone) |
66
|
1 |
|
->format($timeFormat); |
67
|
|
|
|
68
|
1 |
|
return ['from' => $fromTime, 'to' => $toTime]; |
69
|
|
|
} |
70
|
|
|
|
71
|
1 |
|
public function finishTime() |
72
|
|
|
{ |
73
|
1 |
|
$timeFormat = $this->timeFormat(); |
74
|
|
|
|
75
|
|
|
return $this->wrappedObject |
76
|
1 |
|
->finish_at |
77
|
|
|
->timezone($this->wrappedObject->business->timezone) |
78
|
1 |
|
->format($timeFormat); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
public function phone() |
82
|
|
|
{ |
83
|
|
|
return $this->wrappedObject->business->phone; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
public function location() |
87
|
|
|
{ |
88
|
|
|
return $this->wrappedObject->business->postal_address; |
89
|
|
|
} |
90
|
|
|
|
91
|
1 |
|
public function statusLetter() |
92
|
|
|
{ |
93
|
1 |
|
return substr(trans('appointments.status.'.$this->wrappedObject->statusLabel), 0, 1); |
94
|
1 |
|
} |
95
|
1 |
|
|
96
|
|
|
public function status() |
97
|
1 |
|
{ |
98
|
1 |
|
return trans('appointments.status.'.$this->wrappedObject->statusLabel); |
99
|
|
|
} |
100
|
1 |
|
|
101
|
1 |
|
public function statusToCssClass() |
102
|
|
|
{ |
103
|
1 |
|
switch ($this->wrappedObject->status) { |
104
|
1 |
|
case Appointment::STATUS_ANNULATED: |
105
|
1 |
|
return 'danger'; |
106
|
|
|
break; |
|
|
|
|
107
|
|
|
case Appointment::STATUS_CONFIRMED: |
108
|
|
|
return 'success'; |
109
|
|
|
break; |
|
|
|
|
110
|
|
|
case Appointment::STATUS_RESERVED: |
111
|
|
|
return 'warning'; |
112
|
|
|
break; |
|
|
|
|
113
|
|
|
case Appointment::STATUS_SERVED: |
114
|
|
|
default: |
115
|
|
|
return 'default'; |
116
|
|
|
} |
117
|
|
|
} |
118
|
|
|
|
119
|
2 |
|
public function panel() |
120
|
|
|
{ |
121
|
2 |
|
return view('widgets.appointment.panel._body', ['appointment' => $this, 'user' => auth()->user()])->render(); |
|
|
|
|
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
public function row() |
125
|
|
|
{ |
126
|
|
|
return view('widgets.appointment.row._body', ['appointment' => $this, 'user' => auth()->user()])->render(); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
protected function timeFormat() |
130
|
|
|
{ |
131
|
|
|
return $this->wrappedObject->business->pref('time_format') ?: 'H:i a'; |
132
|
|
|
} |
133
|
|
|
} |
134
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.