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
|
|
|
protected $timezone = null; |
12
|
|
|
|
13
|
10 |
|
public function __construct(Appointment $resource) |
14
|
|
|
{ |
15
|
10 |
|
$this->wrappedObject = $resource; |
16
|
|
|
|
17
|
10 |
|
$this->setTimezone(session()->get('timezone')); |
18
|
10 |
|
} |
19
|
|
|
|
20
|
10 |
|
public function setTimezone($timezone = false) |
21
|
|
|
{ |
22
|
10 |
|
$this->timezone = $timezone; |
23
|
|
|
|
24
|
10 |
|
return $this; |
25
|
|
|
} |
26
|
|
|
|
27
|
1 |
|
public function timezone() |
28
|
|
|
{ |
29
|
1 |
|
if ($this->timezone === null) { |
30
|
|
|
$this->timezone = $this->wrappedObject->business->timezone; |
31
|
|
|
} |
32
|
|
|
|
33
|
1 |
|
return $this->timezone; |
34
|
|
|
} |
35
|
|
|
|
36
|
1 |
|
public function code() |
37
|
|
|
{ |
38
|
1 |
|
$length = $this->wrappedObject->business->pref('appointment_code_length'); |
39
|
|
|
|
40
|
1 |
|
return strtoupper(substr($this->wrappedObject->hash, 0, $length)); |
41
|
|
|
} |
42
|
|
|
|
43
|
1 |
|
public function date($format = 'Y-m-d') |
44
|
|
|
{ |
45
|
|
|
// Translated text for friendly date should not be resposibility of this class |
46
|
|
|
|
47
|
|
|
// if ($this->wrappedObject->start_at->isToday()) { |
|
|
|
|
48
|
|
|
// return studly_case(trans('Concierge::appointments.text.today')); |
|
|
|
|
49
|
|
|
// } |
50
|
|
|
|
51
|
|
|
// if ($this->wrappedObject->start_at->isTomorrow()) { |
|
|
|
|
52
|
|
|
// return studly_case(trans('Concierge::appointments.text.tomorrow')); |
|
|
|
|
53
|
|
|
// } |
54
|
|
|
|
55
|
1 |
|
$dateFormat = $this->dateFormat($format); |
56
|
|
|
|
57
|
1 |
|
return $this->wrappedObject |
58
|
1 |
|
->start_at |
59
|
1 |
|
->timezone($this->timezone) |
60
|
1 |
|
->format($dateFormat); |
61
|
|
|
} |
62
|
|
|
|
63
|
1 |
|
public function time() |
64
|
|
|
{ |
65
|
1 |
|
$timeFormat = $this->timeFormat(); |
66
|
|
|
|
67
|
1 |
|
return $this->wrappedObject |
68
|
1 |
|
->start_at |
69
|
1 |
|
->timezone($this->timezone) |
70
|
1 |
|
->format($timeFormat); |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
public function arriveAt() |
74
|
|
|
{ |
75
|
2 |
|
$timeFormat = $this->timeFormat(); |
76
|
|
|
|
77
|
2 |
|
if (!$this->wrappedObject->business->pref('appointment_flexible_arrival')) { |
78
|
1 |
|
return ['at' => $this->time]; |
|
|
|
|
79
|
|
|
} |
80
|
|
|
|
81
|
1 |
|
$fromTime = $this->wrappedObject |
82
|
1 |
|
->vacancy |
83
|
1 |
|
->start_at |
84
|
1 |
|
->timezone($this->timezone) |
85
|
1 |
|
->format($timeFormat); |
86
|
|
|
|
87
|
1 |
|
$toTime = $this->wrappedObject |
88
|
1 |
|
->vacancy |
89
|
1 |
|
->finish_at |
90
|
1 |
|
->timezone($this->timezone) |
91
|
1 |
|
->format($timeFormat); |
92
|
|
|
|
93
|
1 |
|
return ['from' => $fromTime, 'to' => $toTime]; |
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
public function finishTime() |
97
|
|
|
{ |
98
|
|
|
$timeFormat = $this->timeFormat(); |
99
|
|
|
|
100
|
|
|
return $this->wrappedObject |
101
|
|
|
->finish_at |
102
|
|
|
->timezone($this->timezone) |
103
|
|
|
->format($timeFormat); |
104
|
|
|
} |
105
|
|
|
|
106
|
1 |
|
public function duration() |
107
|
|
|
{ |
108
|
1 |
|
$duration = new Duration(intval($this->wrappedObject->duration()) * 60000); |
109
|
|
|
$format = [ |
110
|
1 |
|
'template' => '{hours} {minutes} {seconds}', |
111
|
|
|
'{hours}' => '{hours} hours', |
112
|
|
|
'{minutes}' => '{minutes} minutes', |
113
|
|
|
'{seconds}' => '{seconds} seconds', |
114
|
|
|
]; |
115
|
|
|
|
116
|
1 |
|
return $duration->format($format); |
117
|
|
|
} |
118
|
|
|
|
119
|
1 |
|
public function phone() |
120
|
|
|
{ |
121
|
1 |
|
return $this->wrappedObject->business->phone; |
122
|
|
|
} |
123
|
|
|
|
124
|
1 |
|
public function location() |
125
|
|
|
{ |
126
|
1 |
|
return $this->wrappedObject->business->postal_address; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
public function statusLetter() |
130
|
|
|
{ |
131
|
|
|
return substr(trans('appointments.status.'.$this->wrappedObject->statusLabel), 0, 1); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
public function status() |
135
|
|
|
{ |
136
|
|
|
return trans('appointments.status.'.$this->wrappedObject->statusLabel); |
137
|
|
|
} |
138
|
|
|
|
139
|
1 |
|
public function statusToCssClass() |
140
|
|
|
{ |
141
|
1 |
|
switch ($this->wrappedObject->status) { |
142
|
|
|
case Appointment::STATUS_CANCELED: |
143
|
1 |
|
return 'danger'; |
144
|
|
|
break; |
|
|
|
|
145
|
|
|
case Appointment::STATUS_CONFIRMED: |
146
|
1 |
|
return 'success'; |
147
|
|
|
break; |
|
|
|
|
148
|
|
|
case Appointment::STATUS_RESERVED: |
149
|
1 |
|
return 'warning'; |
150
|
|
|
break; |
|
|
|
|
151
|
|
|
case Appointment::STATUS_SERVED: |
152
|
|
|
default: |
153
|
1 |
|
return 'default'; |
154
|
|
|
} |
155
|
|
|
} |
156
|
|
|
|
157
|
|
|
public function panel() |
158
|
|
|
{ |
159
|
|
|
return view('widgets.appointment.panel._body', ['appointment' => $this, 'user' => auth()->user()])->render(); |
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
public function row() |
163
|
|
|
{ |
164
|
|
|
return view('widgets.appointment.row._body', ['appointment' => $this, 'user' => auth()->user()])->render(); |
|
|
|
|
165
|
|
|
} |
166
|
|
|
|
167
|
2 |
|
protected function timeFormat() |
168
|
|
|
{ |
169
|
2 |
|
return $this->wrappedObject->business->pref('time_format') ?: 'h:i a'; |
170
|
|
|
} |
171
|
|
|
|
172
|
1 |
|
protected function dateFormat($defaultFormat = 'Y-m-d') |
173
|
|
|
{ |
174
|
1 |
|
return $this->wrappedObject->business->pref('date_format') ?: $defaultFormat; |
175
|
|
|
} |
176
|
|
|
} |
177
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.