*/ final class question extends core { /** * File * * @var string $database Path to the database file */ protected string $file = DATABASES . DIRECTORY_SEPARATOR . 'questions.baza'; /** * Database * * @var database $database The database */ public protected(set) database $database; /** * Constructor * * @return void */ public function __construct() { // Initializing the database $this->database = new database() ->encoding(encoding::ascii) ->columns( new column('identifier', type::long_long_unsigned), new column('active', type::char), new column('updated', type::integer_unsigned), new column('created', type::integer_unsigned) ) ->connect($this->file); } /** * Create * * Creates the record in the database * * @param bool $active Is the question active? * * @return int|false The record identifier, if created */ public function create(bool $active = false): int|false { // Initializing the identifier $identifier ??= $this->database->count() + 1; // Initializing the record $record = $this->database->record( $identifier, (int) $active, svoboda::timestamp(), svoboda::timestamp() ); // Creating the record in the database $created = $this->database->write($record); // Exit (success) return $created ? $identifier : false; } }