FieldType::class, 'purpose' => FieldPurpose::class, 'options' => 'array', 'settings' => 'array', 'active' => 'boolean', 'archived_at' => 'datetime', ]; } public function scopeOffered(Builder $query): Builder { return $query->where('active', true)->whereNull('archived_at'); } /** * Auswahlwerte als Liste [{key, label}] in der gepflegten Reihenfolge. * * @return list */ public function optionList(): array { if ($this->type === FieldType::Boolean) { return [['key' => 'ja', 'label' => 'Ja'], ['key' => 'nein', 'label' => 'Nein']]; } if (! $this->type->hasOptions()) { return []; } $list = []; foreach ((array) $this->options as $option) { if (is_array($option) && Keys::valid($option['key'] ?? null) && filled($option['label'] ?? null)) { $list[] = ['key' => $option['key'], 'label' => (string) $option['label']]; } } return $list; } /** * Die Beschreibung des Feldes, wie sie in eine Fassung übernommen wird. * * @return array */ public function snapshot(): array { return [ 'key' => $this->key, 'label' => $this->label, 'help' => $this->help, 'type' => $this->type->value, 'options' => $this->optionList(), 'settings' => (array) $this->settings, 'purpose' => $this->purpose?->value, ]; } }