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
}
2025-05-21 21:56:49 +00:00
/**
*/
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' ],
]
)
)
]
)
);
}
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
}
/**
2025-05-21 21:56:49 +00:00
* @ todo async generating
2025-05-21 06:05:12 +00:00
*/
function docs_create ( array $doc ) : int
{
2025-05-21 21:56:49 +00:00
$id = docs_state :: $crud -> create ( $doc );
docs_generate_audio ( $id , $doc );
return $id ;
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 21:56:49 +00:00
docs_generate_audio ( $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' ,
],
2025-05-21 21:56:49 +00:00
'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!' ,
2025-05-21 06:05:12 +00:00
]
);
}
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
?>