diff --git a/classes/author/Collector.php b/classes/author/Collector.php index b9baae3fdae..3c544c77d68 100644 --- a/classes/author/Collector.php +++ b/classes/author/Collector.php @@ -14,11 +14,11 @@ namespace APP\author; use Illuminate\Database\Query\Builder; +use Illuminate\Database\Query\JoinClause; class Collector extends \PKP\author\Collector { - /** @var array|null */ - public $chapterIds = null; + public ?int $chapterId = null; public function __construct(DAO $dao) { @@ -28,9 +28,9 @@ public function __construct(DAO $dao) /** * Limit results to authors assigned to this chapter by chapterId */ - public function filterByChapterIds(?array $chapterIds): self + public function filterByChapterId(?int $chapterId): self { - $this->chapterIds = $chapterIds; + $this->chapterId = $chapterId; return $this; } @@ -41,14 +41,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->chapterId !== null, function (Builder $query) { + $query->join('submission_chapter_authors as sca', function (JoinClause $join) { + $join->on('a.author_id', '=', 'sca.author_id') + ->where('sca.chapter_id', '=', $this->chapterId); }); + // 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; } } diff --git a/classes/monograph/Chapter.php b/classes/monograph/Chapter.php index 94b572718a4..76047fcc21d 100644 --- a/classes/monograph/Chapter.php +++ b/classes/monograph/Chapter.php @@ -155,7 +155,7 @@ public function setSequence($sequence) public function getAuthors() { return Repo::author()->getCollector() - ->filterByChapterIds([$this->getId()]) + ->filterByChapterId($this->getId()) ->filterByPublicationIds([$this->getData('publicationId')]) ->getMany(); } diff --git a/classes/publication/Repository.php b/classes/publication/Repository.php index 6c5ef04cace..44689e6e26b 100644 --- a/classes/publication/Repository.php +++ b/classes/publication/Repository.php @@ -218,7 +218,7 @@ public function version(Publication $publication): int // old one. We then map the old chapter author associations to the new // authors. $oldChapterAuthors = Repo::author()->getCollector() - ->filterByChapterIds([$oldChapter->getId()]) + ->filterByChapterId($oldChapter->getId()) ->filterByPublicationIds([$oldPublicationId]) ->getMany(); diff --git a/classes/publication/maps/Schema.php b/classes/publication/maps/Schema.php index b46a130af66..f21d4050bd0 100644 --- a/classes/publication/maps/Schema.php +++ b/classes/publication/maps/Schema.php @@ -36,7 +36,7 @@ protected function mapByProperties(array $props, Publication $publication, bool } else { $data['authors'] = Repo::author() ->getCollector() - ->filterByChapterIds([$chapter->getId()]) + ->filterByChapterId($chapter->getId()) ->filterByPublicationIds([$publication->getId()]) ->getMany() ->map(function ($chapterAuthor) { diff --git a/controllers/grid/users/chapter/ChapterGridHandler.php b/controllers/grid/users/chapter/ChapterGridHandler.php index ad306baab61..98ccaa2d61d 100644 --- a/controllers/grid/users/chapter/ChapterGridHandler.php +++ b/controllers/grid/users/chapter/ChapterGridHandler.php @@ -589,7 +589,7 @@ public function getChapterData(Chapter $chapter, Publication $publication): arra 'title' => $chapter->getLocalizedFullTitle(), 'authors' => Repo::author() ->getCollector() - ->filterByChapterIds([$chapter->getId()]) + ->filterByChapterId($chapter->getId()) ->filterByPublicationIds([$publication->getId()]) ->getMany() ->map(fn (Author $author) => $author->getFullName()) diff --git a/controllers/grid/users/chapter/form/ChapterForm.php b/controllers/grid/users/chapter/form/ChapterForm.php index 2e523cb2442..eea75f7b27d 100644 --- a/controllers/grid/users/chapter/form/ChapterForm.php +++ b/controllers/grid/users/chapter/form/ChapterForm.php @@ -224,7 +224,7 @@ public function fetch($request, $template = null, $display = false) $selectedChapterAuthorsArray = []; if ($this->getChapter()) { $selectedChapterAuthors = Repo::author()->getCollector() - ->filterByChapterIds([$this->getChapter()->getId()]) + ->filterByChapterId($this->getChapter()->getId()) ->filterByPublicationIds([$this->getPublication()->getId()]) ->getMany(); diff --git a/plugins/importexport/native/filter/ChapterNativeXmlFilter.php b/plugins/importexport/native/filter/ChapterNativeXmlFilter.php index f1dfd203130..39a9b6fea52 100644 --- a/plugins/importexport/native/filter/ChapterNativeXmlFilter.php +++ b/plugins/importexport/native/filter/ChapterNativeXmlFilter.php @@ -97,7 +97,7 @@ public function createChapterNode($doc, $chapter) // Add authors $chapterAuthors = Repo::author()->getCollector() - ->filterByChapterIds([$chapter->getId()]) + ->filterByChapterId($chapter->getId()) ->filterByPublicationIds([$chapter->getData('publicationId')]) ->getMany();