1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Timegridio\Concierge\Timetable\Strategies; |
4
|
|
|
|
5
|
|
|
use Timegridio\Concierge\Models\Business; |
6
|
|
|
use Timegridio\Concierge\Models\Service; |
7
|
|
|
use Timegridio\Concierge\Models\Vacancy; |
8
|
|
|
use Timegridio\Concierge\Timetable\Timetable; |
9
|
|
|
|
10
|
|
|
class TimetableTimeslotStrategy extends BaseTimetableStrategy implements TimetableStrategyInterface |
11
|
|
|
{ |
12
|
|
|
private $interval = 30; |
13
|
|
|
|
14
|
|
|
public function __construct(Timetable $timetable) |
15
|
|
|
{ |
16
|
|
|
$this->timetable = $timetable; |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
protected function initTimetable($starting, $days) |
20
|
|
|
{ |
21
|
|
|
$this->timetable |
22
|
|
|
->interval($this->interval) |
23
|
|
|
->format('date.service.time') |
24
|
|
|
->from($starting) |
25
|
|
|
->future($days) |
26
|
|
|
->init(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Build timetable. |
31
|
|
|
* |
32
|
|
|
* @param \Illuminate\Database\Eloquent\Collection $vacancies |
33
|
|
|
* @param string $starting |
34
|
|
|
* @param int $days |
35
|
|
|
* |
36
|
|
|
* @return array |
37
|
|
|
*/ |
38
|
|
|
public function buildTimetable($vacancies, $starting = 'today', $days = 1) |
39
|
|
|
{ |
40
|
|
|
$this->initTimetable($starting, $days); |
41
|
|
|
|
42
|
|
|
foreach ($vacancies as $vacancy) { |
43
|
|
|
$this->updateTimeslots($vacancy, $this->interval); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
return $this->timetable->get(); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
protected function updateTimeslots(Vacancy $vacancy, $step = 30) |
50
|
|
|
{ |
51
|
|
|
$fromTime = $vacancy->start_at; |
|
|
|
|
52
|
|
|
$toTime = $fromTime->copy(); |
53
|
|
|
$limit = $vacancy->finish_at; |
|
|
|
|
54
|
|
|
|
55
|
|
|
while ($fromTime <= $limit) { |
56
|
|
|
$toTime->addMinutes($step); |
57
|
|
|
|
58
|
|
|
$capacity = $vacancy->getAvailableCapacityBetween($fromTime->timezone('UTC'), $toTime->timezone('UTC')); |
59
|
|
|
|
60
|
|
|
$time = $fromTime->timezone($vacancy->business->timezone)->format('H:i:s'); |
|
|
|
|
61
|
|
|
|
62
|
|
|
$this->timetable->capacity($vacancy->date, $time, $vacancy->service->slug, $capacity); |
|
|
|
|
63
|
|
|
|
64
|
|
|
$fromTime->addMinutes($step); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.