mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-04-25 21:03:46 +00:00
35 lines
804 B
PHP
35 lines
804 B
PHP
<?php
|
|
|
|
namespace BookStack\Sorting;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* @property int $id
|
|
* @property string $name
|
|
* @property string $sequence
|
|
* @property Carbon $created_at
|
|
* @property Carbon $updated_at
|
|
*/
|
|
class SortSet extends Model
|
|
{
|
|
/**
|
|
* @return SortSetOption[]
|
|
*/
|
|
public function getOptions(): array
|
|
{
|
|
$strOptions = explode(',', $this->sequence);
|
|
$options = array_map(fn ($val) => SortSetOption::tryFrom($val), $strOptions);
|
|
return array_filter($options);
|
|
}
|
|
|
|
/**
|
|
* @param SortSetOption[] $options
|
|
*/
|
|
public function setOptions(array $options): void
|
|
{
|
|
$values = array_map(fn (SortSetOption $opt) => $opt->value, $options);
|
|
$this->sequence = implode(',', $values);
|
|
}
|
|
}
|