Files
timebank-cc-public/app/Models/PollLedgerEntry.php
T

51 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use LogicException;
/**
* One entry in a poll's append-only ballot ledger. Holds no voter identity.
* Entries are only ever inserted, through App\Polls\Ledger.
*/
class PollLedgerEntry extends Model
{
public const CAST = 'cast';
public const CHANGE = 'change';
public const WITHDRAW = 'withdraw';
public const SEAL = 'seal';
protected $table = 'poll_ledger';
public $timestamps = false;
protected $fillable = [
'poll_id', 'sequence', 'format_version', 'entry_type', 'fingerprint', 'refers_to_sequence',
'payload', 'recorded_at', 'previous_hash', 'hash',
];
protected $casts = [
'sequence' => 'integer',
'format_version' => 'integer',
'refers_to_sequence' => 'integer',
'payload' => 'array',
];
protected static function booted(): void
{
static::updating(fn () => throw new LogicException('Poll ledger entries cannot be changed.'));
static::deleting(fn () => throw new LogicException('Poll ledger entries cannot be deleted.'));
}
public function poll()
{
return $this->belongsTo(Poll::class);
}
public function isBallot(): bool
{
return in_array($this->entry_type, [self::CAST, self::CHANGE], true);
}
}