From 1be2cfaee5fa0e7ddc5357de9304dffaac9c437a Mon Sep 17 00:00:00 2001 From: Nils Stefan Weiher Date: Tue, 29 Oct 2024 16:30:33 +0100 Subject: [PATCH] Fix chapter author ordering in Collector https://github.com/pkp/pkp-lib/issues/10526 --- classes/author/Collector.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/classes/author/Collector.php b/classes/author/Collector.php index b9baae3fdae..12e29d85002 100644 --- a/classes/author/Collector.php +++ b/classes/author/Collector.php @@ -14,6 +14,7 @@ namespace APP\author; use Illuminate\Database\Query\Builder; +use Illuminate\Database\Query\JoinClause; class Collector extends \PKP\author\Collector { @@ -41,14 +42,16 @@ public function getQueryBuilder(): Builder { $q = parent::getQueryBuilder(); - $q->when($this->chapterIds !== null, function ($query) { - $query->whereIn('author_id', function ($query) { - return $query->select('author_id') - ->from('submission_chapter_authors') - ->whereIn('chapter_id', $this->chapterIds); + $q->when($this->chapterIds !== null, function (Builder $query) { + $query->join('submission_chapter_authors as sca', function (JoinClause $join) { + $join->whereIn('sca.chapter_id', $this->chapterIds) + ->whereColumn('a.author_id', 'sca.author_id'); }); + // Use the order specified by the submission_chapter_authors table, + // to ensure that the order of authors reflects the order from the manually sorted chapters grid + $query->orders = null; + $query->orderBy('sca.seq'); }); - return $q; } }