93 lines
1.1 KiB
PHP
93 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace rosavox\logic;
|
|
|
|
require_once(__DIR__ . '/helpers.php');
|
|
|
|
|
|
/**
|
|
*/
|
|
class docs_state
|
|
{
|
|
public static ?\rosavox\helpers\class_crud_jsonfile $crud = null;
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_list() : array
|
|
{
|
|
return docs_state::$crud->list_();
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_read(int $id) : array
|
|
{
|
|
return docs_state::$crud->read($id);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_create(array $doc) : int
|
|
{
|
|
return docs_state::$crud->create($doc);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_update(int $id, array $doc) : void
|
|
{
|
|
docs_state::$crud->update($id, $doc);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_delete(int $id) : void
|
|
{
|
|
docs_state::$crud->delete($id);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_add_examples() : void
|
|
{
|
|
docs_create(
|
|
[
|
|
'title' => 'Freibier bei Parteitagen',
|
|
'authors' => [
|
|
'Björn Biernot',
|
|
'Doreen Dauerdurst',
|
|
],
|
|
'content' => 'Wir haben Durst!',
|
|
'reasoning' => null,
|
|
]
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
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
|
|
}
|
|
}
|
|
|
|
?>
|