2025-01-31 01:49:19 +08:00
|
|
|
<?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
|
|
|
|
{
|
|
|
|
/**
|
2025-02-04 23:14:22 +08:00
|
|
|
* @return SortSetOperation[]
|
2025-01-31 01:49:19 +08:00
|
|
|
*/
|
2025-02-04 23:14:22 +08:00
|
|
|
public function getOperations(): array
|
2025-01-31 01:49:19 +08:00
|
|
|
{
|
|
|
|
$strOptions = explode(',', $this->sequence);
|
2025-02-04 23:14:22 +08:00
|
|
|
$options = array_map(fn ($val) => SortSetOperation::tryFrom($val), $strOptions);
|
2025-01-31 01:49:19 +08:00
|
|
|
return array_filter($options);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2025-02-04 23:14:22 +08:00
|
|
|
* @param SortSetOperation[] $options
|
2025-01-31 01:49:19 +08:00
|
|
|
*/
|
2025-02-04 23:14:22 +08:00
|
|
|
public function setOperations(array $options): void
|
2025-01-31 01:49:19 +08:00
|
|
|
{
|
2025-02-04 23:14:22 +08:00
|
|
|
$values = array_map(fn (SortSetOperation $opt) => $opt->value, $options);
|
2025-01-31 01:49:19 +08:00
|
|
|
$this->sequence = implode(',', $values);
|
|
|
|
}
|
|
|
|
}
|