120 lines
1.7 KiB
PHP
120 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace davina\model;
|
|
|
|
|
|
/**
|
|
*/
|
|
class struct_event
|
|
{
|
|
public string $id;
|
|
public string $title;
|
|
public /*type_unix_timestamp*/int $begin;
|
|
public /*type_unix_timestamp*/?int $end;
|
|
public ?string $location;
|
|
public ?string $description;
|
|
public array $tags;
|
|
|
|
public function __construct(
|
|
string $id,
|
|
string $title,
|
|
/*type_unix_timestamp*/int $begin,
|
|
/*type_unix_timestamp*/?int $end,
|
|
?string $location,
|
|
?string $description,
|
|
array $tags
|
|
)
|
|
{
|
|
$this->id = $id;
|
|
$this->title = $title;
|
|
$this->begin = $begin;
|
|
$this->end = $end;
|
|
$this->location = $location;
|
|
$this->description = $description;
|
|
$this->tags = $tags;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function event_to_raw(
|
|
struct_event $event
|
|
)
|
|
{
|
|
return [
|
|
'id' => $event->id,
|
|
'title' => $event->title,
|
|
'begin' => $event->begin,
|
|
'end' => $event->end,
|
|
'location' => $event->location,
|
|
'description' => $event->description,
|
|
'tags' => $event->tags,
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function event_from_raw(
|
|
$event_raw
|
|
) : struct_event
|
|
{
|
|
return (new struct_event(
|
|
$event_raw['id'],
|
|
$event_raw['title'],
|
|
$event_raw['begin'],
|
|
$event_raw['end'],
|
|
$event_raw['location'],
|
|
$event_raw['description'],
|
|
$event_raw['tags'],
|
|
));
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
class struct_calendar
|
|
{
|
|
public array $events;
|
|
|
|
public function __construct(
|
|
array $events
|
|
)
|
|
{
|
|
$this->events = $events;
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function calendar_to_raw(
|
|
struct_calendar $calendar
|
|
)
|
|
{
|
|
return [
|
|
'events' => \array_map(
|
|
fn($event) => event_to_raw($event),
|
|
$calendar->events
|
|
),
|
|
];
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function calendar_from_raw(
|
|
$calendar_raw
|
|
) : struct_calendar
|
|
{
|
|
return (new struct_calendar(
|
|
\array_map(
|
|
fn($event_raw) => event_from_raw($event_raw),
|
|
$calendar_raw['events']
|
|
)
|
|
));
|
|
}
|
|
|
|
?>
|