Skip to content

Commit

Permalink
Merge pull request #1745 from kaitlinnewson/10526-3_4_0
Browse files Browse the repository at this point in the history
pkp/pkp-lib#10526 chapter authors are not returned in the correct sequence
  • Loading branch information
bozana authored Nov 1, 2024
2 parents c1ab59e + 4c90b36 commit 53bb3d3
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 16 deletions.
22 changes: 12 additions & 10 deletions classes/author/Collector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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;
}

Expand All @@ -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;
}
}
2 changes: 1 addition & 1 deletion classes/monograph/Chapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion classes/publication/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion classes/publication/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion controllers/grid/users/chapter/ChapterGridHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion controllers/grid/users/chapter/form/ChapterForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 53bb3d3

Please sign in to comment.