Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/Elastic/SongLyricSearchableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Database\Eloquent\Builder;
use App\Scopes\EvangelicalSongsScope;
use App\Scopes\EKSongsScope;
use App\Scopes\ExcludeEvangelicalOnlySongsScope;


Expand Down Expand Up @@ -271,7 +272,9 @@ function ($q) {
},
]);

$q = $q->withoutGlobalScope(ExcludeEvangelicalOnlySongsScope::class)->withoutGlobalScope(EvangelicalSongsScope::class);
$q = $q->withoutGlobalScope(ExcludeEvangelicalOnlySongsScope::class)
->withoutGlobalScope(EvangelicalSongsScope::class)
->withoutGlobalScope(EKSongsScope::class);

return $q;
}
Expand Down
8 changes: 4 additions & 4 deletions app/GraphQL/Queries/SearchSongLyrics.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ public function __invoke($rootValue, array $args, GraphQLContext $context, Resol
// We need to manually apply the same filter that is implied by the song lyric (global) scope,
// (see ExcludeEvangelicalOnlySongsScope and EvangelicalSongsScope)
// because they work only for Eloquent, not Elasticsearch, which confuses Scout.
$filter_ez = Request::header('Filter-Content') == 'ez';
if ($filter_ez) {
$ez_songbook_id = Songbook::where('shortcut', 'ez')->first()->id;
$filter_shortcut = Request::header('Filter-Content');
if ($filter_shotcut == 'ez' || $filter_shortcut == 'ek') {
$songbook_id = Songbook::where('shortcut', $filter_shortcut)->first()->id;
$searchParams['query']['bool']['filter'][] = [
'terms' => ['songbook_records.songbook_id' => [$ez_songbook_id]]
'terms' => ['songbook_records.songbook_id' => [$songbook_id]]
];
} else {
$searchParams['query']['bool']['must_not'] = [
Expand Down
24 changes: 24 additions & 0 deletions app/Scopes/EKSongsScope.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Scopes;

use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class EKSongsScope implements Scope
{
/**
* Apply the scope to a given Eloquent query builder.
*
* @param \Illuminate\Database\Eloquent\Builder $builder
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function apply(Builder $builder, Model $model)
{
$builder->whereHas('songbook_records', function ($q) {
$q->where('shortcut', "EK");
});
}
}
3 changes: 3 additions & 0 deletions app/SongLyric.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use App\Elastic\SongLyricSearchableTrait;
use App\Scopes\EvangelicalSongsScope;
use App\Scopes\EKSongsScope;
use Illuminate\Support\Facades\Request;

/**
Expand Down Expand Up @@ -188,6 +189,8 @@ protected static function booted()
if (Request::header('Filter-Content') == 'ez') {
// limit the songs to only those that are in the Evangelical songbook
static::addGlobalScope(new EvangelicalSongsScope);
} else if (Request::header('Filter-Content') == 'ek') {
static::addGlobalScope(new EKSongsScope);
} else {
static::addGlobalScope(new ExcludeEvangelicalOnlySongsScope);
}
Expand Down