|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use McCool\LaravelAutoPresenter\BasePresenter; |
|
6
|
|
|
use Timegridio\Concierge\Duration; |
|
7
|
|
|
use Timegridio\Concierge\Models\Appointment; |
|
8
|
|
|
|
|
9
|
|
|
class AppointmentPresenter extends BasePresenter |
|
10
|
|
|
{ |
|
11
|
9 |
|
protected function timezone() |
|
12
|
|
|
{ |
|
13
|
9 |
|
$userTimezone = auth()->user()->pref('timezone'); |
|
|
|
|
|
|
14
|
9 |
|
|
|
15
|
|
|
return ($userTimezone) ?: $this->wrappedObject->business->timezone; |
|
16
|
1 |
|
} |
|
17
|
|
|
|
|
18
|
1 |
|
public function __construct(Appointment $resource) |
|
19
|
|
|
{ |
|
20
|
1 |
|
$this->wrappedObject = $resource; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
1 |
|
public function code() |
|
24
|
|
|
{ |
|
25
|
|
|
$length = $this->wrappedObject->business->pref('appointment_code_length'); |
|
26
|
|
|
|
|
27
|
|
|
return strtoupper(substr($this->wrappedObject->hash, 0, $length)); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function date($format = 'Y-m-d') |
|
31
|
|
|
{ |
|
32
|
|
|
// Translated text for friendly date should not be resposibility of this class |
|
33
|
|
|
|
|
34
|
|
|
// if ($this->wrappedObject->start_at->isToday()) { |
|
|
|
|
|
|
35
|
1 |
|
// return studly_case(trans('Concierge::appointments.text.today')); |
|
|
|
|
|
|
36
|
|
|
// } |
|
37
|
1 |
|
|
|
38
|
1 |
|
// if ($this->wrappedObject->start_at->isTomorrow()) { |
|
|
|
|
|
|
39
|
1 |
|
// return studly_case(trans('Concierge::appointments.text.tomorrow')); |
|
|
|
|
|
|
40
|
1 |
|
// } |
|
41
|
|
|
|
|
42
|
|
|
$dateFormat = $this->dateFormat($format); |
|
43
|
1 |
|
|
|
44
|
|
|
return $this->wrappedObject |
|
45
|
1 |
|
->start_at |
|
46
|
|
|
->timezone($this->timezone()) |
|
47
|
1 |
|
->format($dateFormat); |
|
48
|
1 |
|
} |
|
49
|
1 |
|
|
|
50
|
1 |
|
public function time() |
|
51
|
|
|
{ |
|
52
|
|
|
$timeFormat = $this->timeFormat(); |
|
53
|
2 |
|
|
|
54
|
|
|
return $this->wrappedObject |
|
55
|
2 |
|
->start_at |
|
56
|
|
|
->timezone($this->timezone()) |
|
57
|
2 |
|
->format($timeFormat); |
|
58
|
1 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function arriveAt() |
|
61
|
1 |
|
{ |
|
62
|
1 |
|
$timeFormat = $this->timeFormat(); |
|
63
|
1 |
|
|
|
64
|
1 |
|
if (!$this->wrappedObject->business->pref('appointment_flexible_arrival')) { |
|
65
|
1 |
|
return ['at' => $this->time]; |
|
|
|
|
|
|
66
|
|
|
} |
|
67
|
1 |
|
|
|
68
|
1 |
|
$fromTime = $this->wrappedObject |
|
69
|
1 |
|
->vacancy |
|
70
|
1 |
|
->start_at |
|
71
|
1 |
|
->timezone($this->timezone()) |
|
72
|
|
|
->format($timeFormat); |
|
73
|
1 |
|
|
|
74
|
|
|
$toTime = $this->wrappedObject |
|
75
|
|
|
->vacancy |
|
76
|
|
|
->finish_at |
|
77
|
|
|
->timezone($this->timezone()) |
|
78
|
|
|
->format($timeFormat); |
|
79
|
|
|
|
|
80
|
|
|
return ['from' => $fromTime, 'to' => $toTime]; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
public function finishTime() |
|
84
|
|
|
{ |
|
85
|
|
|
$timeFormat = $this->timeFormat(); |
|
86
|
1 |
|
|
|
87
|
|
|
return $this->wrappedObject |
|
88
|
1 |
|
->finish_at |
|
89
|
|
|
->timezone($this->timezone()) |
|
90
|
1 |
|
->format($timeFormat); |
|
91
|
1 |
|
} |
|
92
|
1 |
|
|
|
93
|
|
|
public function duration() |
|
94
|
1 |
|
{ |
|
95
|
|
|
$duration = new Duration(intval($this->wrappedObject->duration()) * 60000); |
|
96
|
1 |
|
$format = [ |
|
97
|
|
|
'template'=>'{hours} {minutes} {seconds}', |
|
98
|
|
|
'{hours}'=>'{hours} hours', |
|
99
|
1 |
|
'{minutes}'=>'{minutes} minutes', |
|
100
|
|
|
'{seconds}'=>'{seconds} seconds' |
|
101
|
1 |
|
]; |
|
102
|
|
|
|
|
103
|
|
|
return $duration->format($format); |
|
104
|
1 |
|
} |
|
105
|
|
|
|
|
106
|
1 |
|
public function phone() |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->wrappedObject->business->phone; |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
public function location() |
|
112
|
|
|
{ |
|
113
|
|
|
return $this->wrappedObject->business->postal_address; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
public function statusLetter() |
|
117
|
|
|
{ |
|
118
|
|
|
return substr(trans('appointments.status.'.$this->wrappedObject->statusLabel), 0, 1); |
|
119
|
1 |
|
} |
|
120
|
|
|
|
|
121
|
1 |
|
public function status() |
|
122
|
1 |
|
{ |
|
123
|
1 |
|
return trans('appointments.status.'.$this->wrappedObject->statusLabel); |
|
124
|
|
|
} |
|
125
|
1 |
|
|
|
126
|
1 |
|
public function statusToCssClass() |
|
127
|
|
|
{ |
|
128
|
1 |
|
switch ($this->wrappedObject->status) { |
|
129
|
1 |
|
case Appointment::STATUS_CANCELED: |
|
130
|
|
|
return 'danger'; |
|
131
|
1 |
|
break; |
|
|
|
|
|
|
132
|
1 |
|
case Appointment::STATUS_CONFIRMED: |
|
133
|
1 |
|
return 'success'; |
|
134
|
|
|
break; |
|
|
|
|
|
|
135
|
|
|
case Appointment::STATUS_RESERVED: |
|
136
|
|
|
return 'warning'; |
|
137
|
|
|
break; |
|
|
|
|
|
|
138
|
|
|
case Appointment::STATUS_SERVED: |
|
139
|
|
|
default: |
|
140
|
|
|
return 'default'; |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
|
144
|
|
|
public function panel() |
|
145
|
|
|
{ |
|
146
|
|
|
return view('widgets.appointment.panel._body', ['appointment' => $this, 'user' => auth()->user()])->render(); |
|
|
|
|
|
|
147
|
2 |
|
} |
|
148
|
|
|
|
|
149
|
2 |
|
public function row() |
|
150
|
|
|
{ |
|
151
|
|
|
return view('widgets.appointment.row._body', ['appointment' => $this, 'user' => auth()->user()])->render(); |
|
|
|
|
|
|
152
|
1 |
|
} |
|
153
|
|
|
|
|
154
|
1 |
|
protected function timeFormat() |
|
155
|
|
|
{ |
|
156
|
|
|
return $this->wrappedObject->business->pref('time_format') ?: 'h:i a'; |
|
157
|
|
|
} |
|
158
|
|
|
|
|
159
|
|
|
protected function dateFormat($defaultFormat = 'Y-m-d') |
|
160
|
|
|
{ |
|
161
|
|
|
return $this->wrappedObject->business->pref('date_format') ?: $defaultFormat; |
|
162
|
|
|
} |
|
163
|
|
|
} |
|
164
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.