initial
This commit is contained in:
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
class RsvReservation {
|
||||
public ?int $id;
|
||||
|
||||
public int $form_submit_id;
|
||||
|
||||
public bool|null $is_confirmed;
|
||||
|
||||
public array $timetable_reservations;
|
||||
|
||||
public static function schema(): array {
|
||||
return [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id' => ['type' => 'integer', 'readonly' => true],
|
||||
'form_submit_id' => ['type' => 'integer', 'readonly' => true],
|
||||
'is_confirmed' => ['type' => 'boolean', 'readonly' => true],
|
||||
'timetable_reservations' => [
|
||||
'type' => 'array',
|
||||
'required' => true,
|
||||
'items' => RsvTimetableReservation::schema(),
|
||||
],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function from_array(array $data) : self {
|
||||
return new self(
|
||||
intval($data['id'] ?? null),
|
||||
intval($data['form_submit_id'] ?? null),
|
||||
$data['is_confirmed'] ?? null,
|
||||
array_map(fn($t) =>
|
||||
new RsvTimetableReservation(null, $data['timetable_id'], $t['start'], $t['end']),
|
||||
$data['timetable_reservations'] ?? [])
|
||||
);
|
||||
}
|
||||
|
||||
public function __construct(?int $id, int $form_submit_id, bool|null $is_confirmed, array $timetable_reservations)
|
||||
{
|
||||
$this->id = $id;
|
||||
$this->form_submit_id = $form_submit_id;
|
||||
$this->is_confirmed = $is_confirmed;
|
||||
$this->timetable_reservations = $timetable_reservations;
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'form_submit_id' => $this->form_submit_id,
|
||||
'is_confirmed' => $this->is_confirmed,
|
||||
// 'timetable_reservations' => $this->timetable_reservations,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
class RsvReservationTypeConfigurationStep {
|
||||
public int $index;
|
||||
|
||||
public string $type;
|
||||
|
||||
public array|null $configuration;
|
||||
|
||||
public function __construct(array $data) {
|
||||
$this->index = $data['index'];
|
||||
$this->type = $data['type'];
|
||||
$this->configuration = $data['configuration'] ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
class RsvReservationTypeConfiguration {
|
||||
public array $steps = [];
|
||||
|
||||
public function __construct(array $data) {
|
||||
$this->steps = [];
|
||||
foreach( $data['steps'] as $step ) {
|
||||
array_push( $this->steps, new RsvReservationTypeConfigurationStep($step) );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class RsvReservationType {
|
||||
public int $id;
|
||||
|
||||
public string $name;
|
||||
|
||||
public string $description;
|
||||
|
||||
public $configuration;
|
||||
|
||||
public function __construct(array $data) {
|
||||
$this->id = $data['id'];
|
||||
$this->name = $data['name'];
|
||||
$this->description = $data['description'];
|
||||
$this->configuration = json_decode($data['configuration'], true);
|
||||
}
|
||||
|
||||
public function to_array() {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'description' => $this->description,
|
||||
'configuration' => json_encode($this->configuration)
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
class RsvTimetable {
|
||||
public int|null $id;
|
||||
public string $name;
|
||||
public int $block_size;
|
||||
public ?string $google_calendar_id;
|
||||
public ?string $maintainer_email;
|
||||
|
||||
public static function schema(): array {
|
||||
return [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id' => ['type' => 'integer', 'readonly' => true],
|
||||
'name' => ['type' => 'string', 'required' => true, 'minLength' => 1],
|
||||
'block_size' => ['type' => 'integer', 'required' => true, 'minimum' => 1],
|
||||
'maintainer_email' => ['type' => ['string', 'null'], 'format' => 'email'],
|
||||
'google_calendar_id' => ['type' => ['string', 'null']],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function __construct(array $data) {
|
||||
$this->id = $data['id'] ?? null;
|
||||
$this->name = $data['name'];
|
||||
$this->block_size = $data['block_size'] ?? 0;
|
||||
$this->google_calendar_id = $data['google_calendar_id'] ?? null;
|
||||
$this->maintainer_email = $data['maintainer_email'] ?? null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Number of available seats for each time block
|
||||
*/
|
||||
class RsvTimetableAvailability {
|
||||
/**
|
||||
* @param array<int,int> $occupancy Number of available seats for each time block
|
||||
*/
|
||||
public function __construct(
|
||||
public int $from_minutes,
|
||||
public int $to_minutes,
|
||||
public int $block_size_in_minutes,
|
||||
public array $occupancy
|
||||
) { }
|
||||
|
||||
public function push_block(int $capacity) {
|
||||
$this->occupancy[] = $capacity;
|
||||
$this->to_minutes += $this->block_size_in_minutes;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
class RsvTimetableCapacity {
|
||||
public int|null $id;
|
||||
|
||||
public int $timetable_id;
|
||||
|
||||
public int $capacity;
|
||||
|
||||
public int $min_lead_time_minutes;
|
||||
|
||||
public DateTime $date;
|
||||
public int $start_time;
|
||||
public int $end_time;
|
||||
|
||||
public int $repeat_period_in_days;
|
||||
public int $repeat_times;
|
||||
|
||||
public bool $requires_confirmation;
|
||||
|
||||
public static function schema(): array {
|
||||
return [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id' => ['type' => 'integer', 'readonly' => true],
|
||||
'timetable_id' => ['type' => 'integer', 'readonly' => true],
|
||||
'capacity' => ['type' => 'integer', 'required' => true, 'minimum' => 1],
|
||||
'min_lead_time_minutes' => ['type' => 'integer', 'required' => true, 'minimum' => 0],
|
||||
'date' => ['type' => 'string', 'required' => true, 'format' => 'date'],
|
||||
'start_time' => ['type' => 'integer', 'required' => true, 'minimum' => 0],
|
||||
'end_time' => ['type' => 'integer', 'required' => true, 'minimum' => 0],
|
||||
'repeat_period_in_days' => ['type' => 'integer', 'required' => true, 'minimum' => 0],
|
||||
'repeat_times' => ['type' => 'integer', 'required' => true, 'minimum' => 0],
|
||||
'requires_confirmation' => ['type' => 'boolean'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function from_array(array $data): self {
|
||||
return new self(
|
||||
$data['id'],
|
||||
$data['timetable_id'],
|
||||
$data['capacity'],
|
||||
$data['min_lead_time_minutes'],
|
||||
new DateTime($data['date']),
|
||||
$data['start_time'],
|
||||
$data['end_time'],
|
||||
$data['repeat_period_in_days'],
|
||||
$data['repeat_times'],
|
||||
$data['requires_confirmation'] ?? false
|
||||
);
|
||||
}
|
||||
|
||||
public function __construct(
|
||||
int|null $id,
|
||||
int $timetable_id,
|
||||
int $capacity,
|
||||
int $min_lead_time_minutes,
|
||||
DateTime $date,
|
||||
int $start_time,
|
||||
int $end_time,
|
||||
int|null $repeat_period_in_days,
|
||||
int|null $repeat_times,
|
||||
bool $requires_confirmation
|
||||
) {
|
||||
$this->id = $id;
|
||||
$this->timetable_id = $timetable_id;
|
||||
$this->capacity = $capacity;
|
||||
$this->min_lead_time_minutes = $min_lead_time_minutes;
|
||||
$this->date = $date;
|
||||
$this->start_time = $start_time;
|
||||
$this->end_time = $end_time;
|
||||
$this->repeat_period_in_days = $repeat_period_in_days;
|
||||
$this->repeat_times = $repeat_times;
|
||||
$this->requires_confirmation = $requires_confirmation;
|
||||
// $this->repeat_times = $data['repeat_times'];
|
||||
|
||||
// $this->requires_confirmation = $data['requires_confirmation'] ?? false;
|
||||
}
|
||||
|
||||
public function to_array(): array {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'timetable_id' => $this->timetable_id,
|
||||
'capacity' => $this->capacity,
|
||||
'min_lead_time_minutes' => $this->min_lead_time_minutes,
|
||||
'date' => $this->date->format('Y-m-d'),
|
||||
'start_time' => $this->start_time,
|
||||
'end_time' => $this->end_time,
|
||||
'repeat_period_in_days' => $this->repeat_period_in_days,
|
||||
'repeat_times' => $this->repeat_times,
|
||||
'requires_confirmation' => $this->requires_confirmation,
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
class RsvTimetableReservation {
|
||||
public int|null $id;
|
||||
public int $timetable_id;
|
||||
public DateTime $start_utc; // UTC, 'Y-m-d H:i:s'
|
||||
public DateTime $end_utc; // UTC, 'Y-m-d H:i:s'
|
||||
|
||||
public static function schema(): array {
|
||||
return [
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'id' => ['type' => 'integer', 'readonly' => true],
|
||||
'timetable_id' => ['type' => 'integer', 'required' => true],
|
||||
'start_utc' => ['type' => 'string', 'required' => true, 'format' => 'date-time'],
|
||||
'end_utc' => ['type' => 'string', 'required' => true, 'format' => 'date-time'],
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public function __construct(int|null $id, int $timetable_id, DateTime $start_utc, DateTime $end_utc) {
|
||||
$this->id = $id;
|
||||
$this->timetable_id = $timetable_id;
|
||||
$this->start_utc = $start_utc;
|
||||
$this->end_utc = $end_utc;
|
||||
}
|
||||
|
||||
public static function from_array(array $data): self {
|
||||
$utc = new DateTimeZone('UTC');
|
||||
return new self(
|
||||
$data['id'] ?? null,
|
||||
(int) $data['timetable_id'],
|
||||
new DateTime($data['start_utc'], $utc),
|
||||
new DateTime($data['end_utc'], $utc),
|
||||
);
|
||||
}
|
||||
|
||||
public function to_array(): array {
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'timetable_id' => $this->timetable_id,
|
||||
'start_utc' => $this->start_utc->format('Y-m-d H:i:s'),
|
||||
'end_utc' => $this->end_utc->format('Y-m-d H:i:s'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user