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