rosavox/source/logic.php

94 lines
1.1 KiB
PHP
Raw Normal View History

2025-05-21 06:05:12 +00:00
<?php
namespace rosavox\logic;
require_once(__DIR__ . '/helpers.php');
/**
*/
class docs_state
{
2025-05-21 20:55:26 +00:00
public static ?\rosavox\helpers\class_crud_jsonfile $crud = null;
2025-05-21 06:05:12 +00:00
}
/**
*/
function docs_list() : array
{
2025-05-21 20:55:26 +00:00
return docs_state::$crud->list_();
2025-05-21 06:05:12 +00:00
}
/**
*/
function docs_read(int $id) : array
{
2025-05-21 20:55:26 +00:00
return docs_state::$crud->read($id);
2025-05-21 06:05:12 +00:00
}
/**
*/
function docs_create(array $doc) : int
{
2025-05-21 20:55:26 +00:00
return docs_state::$crud->create($doc);
2025-05-21 06:05:12 +00:00
}
/**
*/
function docs_update(int $id, array $doc) : void
{
2025-05-21 20:55:26 +00:00
docs_state::$crud->update($id, $doc);
2025-05-21 06:05:12 +00:00
}
/**
*/
function docs_delete(int $id) : void
{
2025-05-21 20:55:26 +00:00
docs_state::$crud->delete($id);
2025-05-21 16:54:14 +00:00
}
2025-05-21 06:05:12 +00:00
/**
*/
function docs_add_examples() : void
{
docs_create(
[
'title' => 'Freibier bei Parteitagen',
'authors' => [
'Björn Biernot',
'Doreen Dauerdurst',
],
'content' => 'Wir haben Durst!',
'reasoning' => null,
]
);
}
2025-05-21 20:55:26 +00:00
/**
*/
function docs_init() : void
{
docs_state::$crud = new \rosavox\helpers\class_crud_jsonfile(
'docs.json',
fn ($id) => \sprintf('%u', $id),
fn ($id_encoded) => \intval($id_encoded)
);
if (empty(docs_state::$crud->list_()))
{
docs_add_examples();
}
else
{
// do nothing
}
}
2025-05-21 06:05:12 +00:00
?>