From 6a9f3e5cecca94b4e2b53a0236685e9ea6523cbe Mon Sep 17 00:00:00 2001 From: philipp lang Date: Thu, 23 Mar 2023 00:00:41 +0100 Subject: [PATCH] Fix filter --- app/Http/Views/ActivityFilterScope.php | 2 +- app/Http/Views/Filter.php | 72 -------------------------- 2 files changed, 1 insertion(+), 73 deletions(-) delete mode 100644 app/Http/Views/Filter.php diff --git a/app/Http/Views/ActivityFilterScope.php b/app/Http/Views/ActivityFilterScope.php index 474f4e12..e3b412e1 100644 --- a/app/Http/Views/ActivityFilterScope.php +++ b/app/Http/Views/ActivityFilterScope.php @@ -3,6 +3,7 @@ namespace App\Http\Views; use App\Activity; +use App\Lib\Filter; use Illuminate\Database\Eloquent\Builder; use Spatie\LaravelData\Attributes\MapInputName; use Spatie\LaravelData\Attributes\MapOutputName; @@ -42,4 +43,3 @@ class ActivityFilterScope extends Filter return $query; } } - diff --git a/app/Http/Views/Filter.php b/app/Http/Views/Filter.php deleted file mode 100644 index e713d0ef..00000000 --- a/app/Http/Views/Filter.php +++ /dev/null @@ -1,72 +0,0 @@ - - */ - abstract protected function locks(): array; - - public static function fromRequest(?string $request = null): static - { - $parameters = json_decode(base64_decode($request), true); - - return static::from($parameters ?: [])->parseLocks(); - } - - public function parseLocks(): static - { - foreach ($this->locks() as $key => $value) { - if ($value === $this->unsetReplacer) { - continue; - } - - $this->{$key} = $value; - } - - return $this; - } - - /** - * @param mixed $value - * - * @return mixed - */ - public function when(bool $when, $value) - { - return $when ? $value : $this->unsetReplacer; - } - - /** - * @param Builder $query - * - * @return Builder - */ - protected function applyOwnOthers(Builder $query, bool $own, bool $others): Builder - { - if ($own && !$others) { - $query->where('user_id', auth()->id()); - } - - if (!$own && $others) { - $query->where('user_id', '!=', auth()->id()); - } - - if (!$own && !$others) { - $query->where('id', -1); - } - - return $query; - } -}