From 92bf36160b4483f6d327450fdd0c388ec7603a4d Mon Sep 17 00:00:00 2001 From: Nils Stefan Weiher Date: Tue, 29 Oct 2024 16:30:33 +0100 Subject: [PATCH 1/2] 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; } } From 965dba6450151858a1dafb39f22ddba8bc8f70d2 Mon Sep 17 00:00:00 2001 From: Kaitlin Newson Date: Thu, 31 Oct 2024 14:46:04 -0300 Subject: [PATCH 2/2] pkp/pkp-lib#10526 change filterByChapterId for chapter author ordering --- classes/author/Collector.php | 13 ++++++------- classes/monograph/Chapter.php | 2 +- classes/publication/Repository.php | 2 +- classes/publication/maps/Schema.php | 2 +- .../grid/users/chapter/ChapterGridHandler.php | 2 +- controllers/grid/users/chapter/form/ChapterForm.php | 2 +- .../native/filter/ChapterNativeXmlFilter.php | 2 +- 7 files changed, 12 insertions(+), 13 deletions(-) diff --git a/classes/author/Collector.php b/classes/author/Collector.php index 12e29d85002..3c544c77d68 100644 --- a/classes/author/Collector.php +++ b/classes/author/Collector.php @@ -18,8 +18,7 @@ class Collector extends \PKP\author\Collector { - /** @var array|null */ - public $chapterIds = null; + public ?int $chapterId = null; public function __construct(DAO $dao) { @@ -29,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; } @@ -42,10 +41,10 @@ public function getQueryBuilder(): Builder { $q = parent::getQueryBuilder(); - $q->when($this->chapterIds !== null, function (Builder $query) { + $q->when($this->chapterId !== 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'); + $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 diff --git a/classes/monograph/Chapter.php b/classes/monograph/Chapter.php index fa8113fbe52..19b902b4e58 100644 --- a/classes/monograph/Chapter.php +++ b/classes/monograph/Chapter.php @@ -128,7 +128,7 @@ public function setSequence(float $sequence): void public function getAuthors(): LazyCollection { 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 92306ed8e41..4a608424f80 100644 --- a/classes/publication/Repository.php +++ b/classes/publication/Repository.php @@ -217,7 +217,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 f7a27bbf63e..5d747d08c5a 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 3ba15bd80dc..4982cb1476c 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();