1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge\Booking\Strategies; |
4
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
6
|
|
|
use Illuminate\Support\Collection; |
7
|
|
|
use Timegridio\Concierge\Booking\Timetable; |
8
|
|
|
use Timegridio\Concierge\Models\Appointment; |
9
|
|
|
use Timegridio\Concierge\Models\Business; |
10
|
|
|
use Timegridio\Concierge\Models\Contact; |
11
|
|
|
use Timegridio\Concierge\Models\Service; |
12
|
|
|
use Timegridio\Concierge\Models\Vacancy; |
13
|
|
|
|
14
|
|
|
class BookingTimeslotStrategy implements BookingStrategyInterface |
15
|
|
|
{ |
16
|
|
|
private $timetable; |
17
|
|
|
|
18
|
|
|
private $interval = 30; |
19
|
|
|
|
20
|
|
|
public function __construct(Timetable $timetable) |
21
|
|
|
{ |
22
|
|
|
$this->timetable = $timetable; |
23
|
|
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Build timetable. |
27
|
|
|
* |
28
|
|
|
* @param Illuminate\Database\Eloquent\Collection $vacancies |
29
|
|
|
* @param string $starting |
30
|
|
|
* @param int $days |
31
|
|
|
* |
32
|
|
|
* @return array |
33
|
|
|
*/ |
34
|
|
|
public function buildTimetable($vacancies, $starting = 'today', $days = 1) |
35
|
|
|
{ |
36
|
|
|
$this->timetable |
37
|
|
|
->interval($this->interval) |
38
|
|
|
->format('date.service.time') |
39
|
|
|
->from($starting) |
40
|
|
|
->future($days) |
41
|
|
|
->init(); |
42
|
|
|
|
43
|
|
|
foreach ($vacancies as $vacancy) { |
44
|
|
|
$this->updateTimeslots($vacancy, $this->interval); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
return $this->timetable->get(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
protected function updateTimeslots(Vacancy $vacancy, $step = 30) |
51
|
|
|
{ |
52
|
|
|
$fromTime = $vacancy->start_at; |
|
|
|
|
53
|
|
|
$toTime = $fromTime->copy(); |
54
|
|
|
$limit = $vacancy->finish_at; |
|
|
|
|
55
|
|
|
|
56
|
|
|
while ($fromTime <= $limit) { |
57
|
|
|
$toTime->addMinutes($step); |
58
|
|
|
|
59
|
|
|
$capacity = $vacancy->getAvailableCapacityBetween($fromTime->timezone('UTC'), $toTime->timezone('UTC')); |
60
|
|
|
|
61
|
|
|
$time = $fromTime->timezone($vacancy->business->timezone)->format('H:i:s'); |
|
|
|
|
62
|
|
|
|
63
|
|
|
$this->timetable->capacity($vacancy->date, $time, $vacancy->service->slug, $capacity); |
|
|
|
|
64
|
|
|
|
65
|
|
|
$fromTime->addMinutes($step); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
Since your code implements the magic setter
_set
, this function will be called for any write access on an undefined variable. You can add the@property
annotation to your class or interface to document the existence of this variable.Since the property has write access only, you can use the @property-write annotation instead.
Of course, you may also just have mistyped another name, in which case you should fix the error.
See also the PhpDoc documentation for @property.