core/source/model.php

170 lines
2.8 KiB
PHP
Raw Permalink Normal View History

2025-09-09 23:17:19 +02:00
<?php
2025-09-22 23:17:08 +02:00
/*
davina Calendar data CalDAV conditioner
Copyright (C) 2025 Fenris <fenris@folksprak.org>
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied
warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see
<https://www.gnu.org/licenses/>.
*/
2025-09-09 23:17:19 +02:00
2025-09-16 12:05:35 +02:00
namespace davina\model;
2025-09-09 23:17:19 +02:00
/**
*/
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']
)
));
}
2025-09-21 18:49:03 +02:00
/**
*/
class struct_realm
{
/**
*/
public string $name;
/**
*/
public \davina\auths\interface_auth $auth;
/**
*/
public \davina\sources\interface_source $source;
/**
*/
public function __construct(
string $name,
\davina\auths\interface_auth $auth,
\davina\sources\interface_source $source
)
{
$this->name = $name;
$this->auth = $auth;
$this->source = $source;
}
}
2025-09-09 23:17:19 +02:00
?>