'Date added', 'release_date' => 'Release date', 'title' => 'Title' ]; /** * Translation of entries key. */ public const array ENTRY_TYPES = [ 'translations' => 'Translations', 'romhacks' => 'Romhacks', 'homebrew' => 'Homebrew', 'utilities' => 'Utilities', 'documents' => 'Documents', 'lua-scripts' => 'Lua Scripts', 'tutorials' => 'Tutorials', ]; public const int PAGINATION = 30; public function updatedSearch(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedTypes(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedGames(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedPlatforms(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedGenres(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedStatuses(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedAuthors(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedAuthorsMode(): void { $this->resetPage(); $this->dispatch('filters-updated'); } public function updatedLanguages(): void { $this->resetPage(); $this->dispatch('filters-updated'); } 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', 'categories', 'categoriesMode', 'systems', 'systemsMode', 'levels' ]); $this->resetPage(); } public function setSort(string $field): void { if( $this->sortBy === $field ) { $this->sortDir = $this->sortDir === 'asc' ? 'desc' : 'asc'; } else { $this->sortBy = $field; $this->sortDir = 'asc'; } $this->resetPage(); $this->dispatch('filters-updated'); } private function buildQuery() { $query = Entry::query()->published()->with([ 'game.platform', 'game.genre', 'status', 'authors', 'languages', 'level', 'systems', 'categories', 'modifications' ]); if( $this->search ) { $query->where(function($q) { $q->where('title', 'like', '%'.$this->search.'%'); $q->orWhere('complete_title', 'like', '%'.$this->search.'%'); }); } if( $this->types ) { $query->whereIn('type', $this->types); } if( $this->platforms ) { $query->where(function($q) { $q->whereIn('platform_id', $this->platforms) ->orWhereHas('game', fn($q2) => $q2->whereIn('platform_id', $this->platforms) ); }); } if( $this->genres ) { $query->where(function($q) { $q->whereHas('game', fn($q2) => $q2->whereIn('genre_id', $this->genres) ); }); } if( $this->games ){ $query->whereIn('game_id', $this->games); } if( $this->statuses ) { $query->whereIn('status_id', $this->statuses); } if( $this->authors ) { if( $this->authorsMode === 'and' ) { foreach ( $this->authors as $authorId ) { $query->whereHas('authors', fn($q) => $q->where('authors.id', $authorId)); } } else { $query->whereHas('authors', fn($q) => $q->whereIn('authors.id', $this->authors)); } } if( $this->languages ) { if( $this->languagesMode === 'and' ) { foreach ( $this->languages as $langId ) { $query->whereHas('languages', fn($q) => $q->where('languages.id', $langId)); } } else { $query->whereHas('languages', fn($q) => $q->whereIn('languages.id', $this->languages)); } } if( $this->modifications ) { if( $this->modificationsMode === 'and' ) { foreach ( $this->modifications as $modificationId ) { $query->whereHas('modifications', fn($q) => $q->where('modifications.id', $modificationId)); } } else { $query->whereHas('modifications', fn($q) => $q->whereIn('modifications.id', $this->modifications)); } } 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); } public function render() { return view('livewire.database', [ 'entries' => $this->buildQuery()->paginate(self::PAGINATION), 'allGames' => Game::orderBy('name')->get(), 'allPlatforms' => Platform::orderBy('name')->get(), 'allGenres' => Genre::orderBy('name')->get(), 'allStatuses' => Status::orderBy('name')->get(), '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(), ]); } }