146 lines
2.3 KiB
PHP
146 lines
2.3 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_audio_name(int $id) : string
|
|
{
|
|
return \sprintf('%04u', $id);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_audio_path(int $id) : string
|
|
{
|
|
return \sprintf('%s.ogg', docs_audio_name($id));
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_generate_audio(int $id, $doc) : void
|
|
{
|
|
$pause = ' . ';
|
|
\rosavox\helpers\generate_audio(
|
|
docs_audio_name($id),
|
|
\rosavox\helpers\string_coin(
|
|
"{{title}}{{pause}}Autoren: {{authors}}{{pause}}Formulierung: {{content}}{{macro_reasoning}}",
|
|
[
|
|
'pause' => $pause,
|
|
'title' => $doc['title'],
|
|
'authors' => implode(', ', $doc['authors']),
|
|
'content' => $doc['content'],
|
|
'macro_reasoning' => (
|
|
($doc['reasoning'] === null)
|
|
?
|
|
''
|
|
:
|
|
\rosavox\helpers\string_coin(
|
|
"{{pause}}Begründung: {{reasoning}}",
|
|
[
|
|
'pause' => $pause,
|
|
'reasoning' => $doc['reasoning'],
|
|
]
|
|
)
|
|
)
|
|
]
|
|
)
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_list() : array
|
|
{
|
|
return docs_state::$crud->list_();
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_read(int $id) : array
|
|
{
|
|
return docs_state::$crud->read($id);
|
|
}
|
|
|
|
|
|
/**
|
|
* @todo async generating
|
|
*/
|
|
function docs_create(array $doc) : int
|
|
{
|
|
$id = docs_state::$crud->create($doc);
|
|
docs_generate_audio($id, $doc);
|
|
return $id;
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
function docs_update(int $id, array $doc) : void
|
|
{
|
|
docs_state::$crud->update($id, $doc);
|
|
docs_generate_audio($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' => 'Der Landesverband möge beschließen, dass zu Beginn eines jeden Parteitags für jeden Deligierten mindestens zwei Flaschen Bier auf den zugehörigen Platz zu stellen sind.',
|
|
'reasoning' => 'Wir haben Durst!',
|
|
]
|
|
);
|
|
}
|
|
|
|
|
|
/**
|
|
*/
|
|
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
|
|
}
|
|
}
|
|
|
|
?>
|