]> BookStack Code Mirror - bookstack/blobdiff - app/Sorting/SortSet.php
Sorting: Finished main sort set CRUD work
[bookstack] / app / Sorting / SortSet.php
index 42e1e0951c7903305bba0ee51ec2d6e90248c1e7..971b3e29aae243dddfe675da74cbe3c7f0addcc4 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace BookStack\Sorting;
 
+use BookStack\Activity\Models\Loggable;
 use Carbon\Carbon;
 use Illuminate\Database\Eloquent\Model;
 
@@ -12,24 +13,32 @@ use Illuminate\Database\Eloquent\Model;
  * @property Carbon $created_at
  * @property Carbon $updated_at
  */
-class SortSet extends Model
+class SortSet extends Model implements Loggable
 {
     /**
-     * @return SortSetOption[]
+     * @return SortSetOperation[]
      */
-    public function getOptions(): array
+    public function getOperations(): array
     {
-        $strOptions = explode(',', $this->sequence);
-        $options = array_map(fn ($val) => SortSetOption::tryFrom($val), $strOptions);
-        return array_filter($options);
+        return SortSetOperation::fromSequence($this->sequence);
     }
 
     /**
-     * @param SortSetOption[] $options
+     * @param SortSetOperation[] $options
      */
-    public function setOptions(array $options): void
+    public function setOperations(array $options): void
     {
-        $values = array_map(fn (SortSetOption $opt) => $opt->value, $options);
+        $values = array_map(fn (SortSetOperation $opt) => $opt->value, $options);
         $this->sequence = implode(',', $values);
     }
+
+    public function logDescriptor(): string
+    {
+        return "({$this->id}) {$this->name}";
+    }
+
+    public function getUrl(): string
+    {
+        return url("/settings/sorting/sets/{$this->id}");
+    }
 }