| 1 |
<?php |
| 2 |
namespace Booktics\Appointment\Schedule; |
| 3 |
|
| 4 |
use JsonSerializable; |
| 5 |
|
| 6 |
/** |
| 7 |
* Timeslot class |
| 8 |
*/ |
| 9 |
class Time_Slot implements JsonSerializable { |
| 10 |
/** |
| 11 |
* Store start time |
| 12 |
* |
| 13 |
* @var string |
| 14 |
*/ |
| 15 |
public $start; |
| 16 |
|
| 17 |
/** |
| 18 |
* Store end time |
| 19 |
* |
| 20 |
* @var string |
| 21 |
*/ |
| 22 |
public $end; |
| 23 |
|
| 24 |
/** |
| 25 |
* Store time slot status |
| 26 |
* |
| 27 |
* @var bool |
| 28 |
*/ |
| 29 |
public $is_available; |
| 30 |
|
| 31 |
/** |
| 32 |
* Store maximum capacity |
| 33 |
* |
| 34 |
* @var int |
| 35 |
*/ |
| 36 |
public $max_capacity; |
| 37 |
|
| 38 |
/** |
| 39 |
* Store booked count |
| 40 |
* |
| 41 |
* @var int |
| 42 |
*/ |
| 43 |
public $booked_count; |
| 44 |
|
| 45 |
/** |
| 46 |
* Store available spots |
| 47 |
* |
| 48 |
* @var int |
| 49 |
*/ |
| 50 |
public $available_spots; |
| 51 |
|
| 52 |
/** |
| 53 |
* Team members who can take this slot. |
| 54 |
* |
| 55 |
* Only filled in when an extension merges several members' slots into one |
| 56 |
* set, so it can remember who is behind a merged slot. Deliberately left |
| 57 |
* out of to_array(): for a service that assigns automatically, which |
| 58 |
* member is free is scheduling detail the customer does not need. |
| 59 |
* |
| 60 |
* Declared here rather than set dynamically, which PHP 8.2 deprecates and |
| 61 |
* PHP 9 refuses. |
| 62 |
* |
| 63 |
* @var int[] |
| 64 |
*/ |
| 65 |
public $available_member_ids = []; |
| 66 |
|
| 67 |
/** |
| 68 |
* Constructor timeslot class |
| 69 |
* |
| 70 |
* @param string $start Start time for a time slot |
| 71 |
* @param string $end End time for a time slot |
| 72 |
* @param bool $is_available Status for time slot |
| 73 |
* @param true |
| 74 |
* |
| 75 |
* @return void |
| 76 |
*/ |
| 77 |
public function __construct( string $start, string $end, bool $is_available = true, int $max_capacity = 1, int $available_spots = 1, int $booked_count = 0 ) { |
| 78 |
$this->start = $start; |
| 79 |
$this->end = $end; |
| 80 |
$this->is_available = $is_available; |
| 81 |
$this->max_capacity = $max_capacity; |
| 82 |
$this->booked_count = $booked_count; |
| 83 |
$this->available_spots = $available_spots; |
| 84 |
} |
| 85 |
|
| 86 |
/** |
| 87 |
* Get time slot data as an array |
| 88 |
* |
| 89 |
* @return array Timeslot data |
| 90 |
*/ |
| 91 |
public function to_array(): array { |
| 92 |
return [ |
| 93 |
'start' => $this->start, |
| 94 |
'end' => $this->end, |
| 95 |
'is_available' => $this->is_available, |
| 96 |
'max_capacity' => $this->max_capacity, |
| 97 |
'booked_count' => $this->booked_count, |
| 98 |
'available_spots' => $this->available_spots, |
| 99 |
]; |
| 100 |
} |
| 101 |
|
| 102 |
/** |
| 103 |
* Specify data which should be serialized to JSON. |
| 104 |
* |
| 105 |
* @return array |
| 106 |
*/ |
| 107 |
public function jsonSerialize(): array { |
| 108 |
return $this->to_array(); |
| 109 |
} |
| 110 |
} |
| 111 |
|