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
120 changes: 120 additions & 0 deletions app/GraphQL/Queries/SongLyricsPaginated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
<?php

namespace App\GraphQL\Queries;

use App\Services\LilypondClientService;
use App\Services\SongLyricBibleReferenceService;
use App\SongLyric;
use Illuminate\Http\Request;
use Illuminate\Pagination\Paginator;
use Log;

class SongLyricsPaginated
{
protected SongLyricBibleReferenceService $sl_ref_service;

public function __construct()
{
$this->sl_ref_service = app(SongLyricBibleReferenceService::class);
}

public function __invoke($root, array $args)
{
$query = SongLyric::query();

if (isset($args['search_string'])) {
return SongLyric::search($args['search_string'])->get();
}

if (isset($args['has_lyrics']) && $args['has_lyrics'] === true) {
$query = $query->whereHas('lyrics');
}
if (isset($args['has_lyrics']) && $args['has_lyrics'] === false) {
$query = $query->whereDoesntHave('lyrics');
}

if (isset($args['has_license']) && $args['has_license'] === true) {
$query = $query->where('licence_type_cc', '!=', 0);
};
if (isset($args['has_license']) && $args['has_license'] === false) {
$query = $query->where('licence_type_cc', '=', 0);
}

if (isset($args['has_scores']) && $args['has_scores'] === false) {
$query = $query->whereDoesntHave('externals', function ($q) { # Song has score in external
# External must be score
$q->where('content_type', '2');
})
->whereDoesntHave('lilypond_src')->whereDoesntHave('lilypond_parts_sheet_music', function ($q_lp) {
return $q_lp->renderable();
});
}


if (isset($args['needs_lilypond']) && $args['needs_lilypond'] === true) {
$query = $query->whereDoesntHave('lilypond_src')
->where('licence_type_cc', '!=', 0);
}

if (isset($args['has_lilypond']) && $args['has_lilypond'] === true) {
$query = $query->where(function ($q) {
return $q->whereHas('lilypond_src')->orWhereHas('lilypond_parts_sheet_music', function ($q_lp) {
return $q_lp->renderable();
});
});
}

if (isset($args['needs_lilypond_update']) && $args['needs_lilypond_update'] === true) {
$query = $query->whereHas('lilypond_src')->whereDoesntHave('lilypond_parts_sheet_music', function ($q_lp) {
return $q_lp->renderable();
});
}

if (isset($args['has_authors']) && $args['has_authors'] === true) {
$query = $query->whereHas('authors');
}
if (isset($args['has_authors']) && $args['has_authors'] === false) {
$query = $query->whereDoesntHave('authors')->where('has_anonymous_author', 0);
}

if (isset($args['has_tags']) && $args['has_tags'] === true) {
$query = $query->whereHas('tags');
}
if (isset($args['has_tags']) && $args['has_tags'] === false) {
$query = $query->whereDoesntHave('tags');
}

if (isset($args['has_chords'])) {
$query = $query->where('has_chords', $args['has_chords']);
}

if (isset($args['order_abc'])) {
$query = $query->orderBy('name', 'asc');
}

if (isset($args['updated_after'])) {
$query = $query->where('updated_at', '>', $args['updated_after']);
}

if (isset($args['liturgical_day_identificator'])) {
$query = $query->whereHas('tags', function ($q) use ($args) {
$q->where('lit_day_identificator', $args['liturgical_day_identificator']);
});
}

if (isset($args['songbook_id'])) {
$query = $query->whereHas('songbook_records', function ($q) use ($args) {
$q->where('songbook_id', $args['songbook_id']);
});
}

if (isset($args['bible_reference_osis'])) {
$sl_ids = $this->sl_ref_service->findMatchingSongLyricIds($args['bible_reference_osis']);
$query = $query->whereIn('id', $sl_ids);
}

$res = $query->paginate(perPage: $args['per_page'], page: $args['page']);

return $res;
}
}
22 changes: 22 additions & 0 deletions graphql/song_lyric.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,28 @@ extend type Query {
updated_after: DateTime
songbook_id: ID
): [SongLyric!]! # see App/GraphQL/Queries/SongLyrics.php

song_lyrics_paginated(
page: Int
per_page: Int
search_string: String
bible_reference_osis: String
liturgical_day_identificator: String
has_lyrics: Boolean
has_authors: Boolean
has_tags: Boolean
has_chords: Boolean
has_scores: Boolean
has_license: Boolean
needs_lilypond: Boolean
needs_lilypond_update: Boolean
has_lilypond: Boolean
order_abc: Boolean
updated_after: DateTime
songbook_id: ID
): SongLyricPaginator # see App/GraphQL/Queries/SongLyricsPaginated.php


search_song_lyrics(
search_params: String
page: Int
Expand Down