Update Submissions and add fields
This commit is contained in:
@@ -3,13 +3,16 @@
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Models\Author;
|
||||
use App\Models\Category;
|
||||
use App\Models\Entry;
|
||||
use App\Models\Game;
|
||||
use App\Models\Genre;
|
||||
use App\Models\Language;
|
||||
use App\Models\Level;
|
||||
use App\Models\Modification;
|
||||
use App\Models\Platform;
|
||||
use App\Models\Status;
|
||||
use App\Models\System;
|
||||
use Livewire\Attributes\Url;
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
@@ -114,6 +117,41 @@ class Database extends Component
|
||||
#[Url(except:'or')]
|
||||
public string $modificationsMode = 'or';
|
||||
|
||||
/**
|
||||
* Categories IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $categories = [];
|
||||
|
||||
/**
|
||||
* Categories mode and/or
|
||||
* @var string
|
||||
*/
|
||||
#[Url(except:['or'])]
|
||||
public string $categoriesMode = 'or';
|
||||
|
||||
/**
|
||||
* Systems IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $systems = [];
|
||||
|
||||
/**
|
||||
* Systems mode and/or
|
||||
* @var string
|
||||
*/
|
||||
#[Url(except:['or'])]
|
||||
public string $systemsMode = 'or';
|
||||
|
||||
/**
|
||||
* Levels IDs filter.
|
||||
* @var array
|
||||
*/
|
||||
#[Url(except:[])]
|
||||
public array $levels = [];
|
||||
|
||||
/**
|
||||
* Sort by field.
|
||||
* @var string
|
||||
@@ -164,11 +202,16 @@ class Database extends Component
|
||||
public function updatedLanguagesMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedModifications(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedModificationsMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedCategories(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedCategoriesMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedSystems(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedSystemsMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
public function updatedLevels(): void { $this->resetPage(); $this->dispatch('filters-updated'); }
|
||||
|
||||
public function clearFilters(): void
|
||||
{
|
||||
$this->reset([
|
||||
'search', 'types', 'platforms', 'genres', 'statuses', 'authors', 'authorsMode', 'languages', 'languagesMode', 'modifications', 'modificationsMode'
|
||||
'search', 'types', 'platforms', 'genres', 'statuses', 'authors', 'authorsMode', 'languages', 'languagesMode', 'modifications', 'modificationsMode', 'categories', 'categoriesMode', 'systems', 'systemsMode', 'levels'
|
||||
]);
|
||||
$this->resetPage();
|
||||
}
|
||||
@@ -188,7 +231,7 @@ class Database extends Component
|
||||
private function buildQuery()
|
||||
{
|
||||
$query = Entry::query()->published()->with([
|
||||
'game.platform', 'game.genre', 'status', 'authors', 'languages'
|
||||
'game.platform', 'game.genre', 'status', 'authors', 'languages', 'level', 'systems', 'categories', 'modifications'
|
||||
]);
|
||||
|
||||
if( $this->search ) {
|
||||
@@ -253,6 +296,30 @@ class Database extends Component
|
||||
}
|
||||
}
|
||||
|
||||
if( $this->levels ) {
|
||||
$query->whereIn('level_id', $this->levels);
|
||||
}
|
||||
|
||||
if( $this->categories ) {
|
||||
if( $this->categoriesMode === 'and' ) {
|
||||
foreach ( $this->categories as $categoryId ) {
|
||||
$query->whereHas('categories', fn($q) => $q->where('categories.id', $categoryId));
|
||||
}
|
||||
} else {
|
||||
$query->whereHas('categories', fn($q) => $q->whereIn('categories.id', $this->categories));
|
||||
}
|
||||
}
|
||||
|
||||
if( $this->systems ) {
|
||||
if( $this->systemsMode === 'and' ) {
|
||||
foreach ( $this->systems as $systemId ) {
|
||||
$query->whereHas('systems', fn($q) => $q->where('systems.id', $systemId));
|
||||
}
|
||||
} else {
|
||||
$query->whereHas('systems', fn($q) => $q->whereIn('systems.id', $this->systems));
|
||||
}
|
||||
}
|
||||
|
||||
return $query->orderBy($this->sortBy, $this->sortDir);
|
||||
}
|
||||
|
||||
@@ -267,6 +334,9 @@ class Database extends Component
|
||||
'allAuthors' => Author::orderBy('name')->get(),
|
||||
'allLanguages' => Language::orderBy('name')->get(),
|
||||
'allModifications' => Modification::orderBy('name')->get(),
|
||||
'allCategories' => Category::orderBy('name')->get(),
|
||||
'allLevels' => Level::orderBy('name')->get(),
|
||||
'allSystems' => System::orderBy('name')->get(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user