Skip to content

Commit

Permalink
Fixed issue with sort order
Browse files Browse the repository at this point in the history
  • Loading branch information
Lasse Lehtinen committed Oct 13, 2023
1 parent 9f05d61 commit dc63bb7
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 28 deletions.
44 changes: 23 additions & 21 deletions src/Groschen.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ public function getContributors($returnInternalResources = true)
$sortOrderPriority = $teamMember->sortOrder;
$rolePriority = $this->getRolePriority($teamMember->role->name);
$lastNamePriority = (!empty($teamMember->contact->lastName)) ? ord($teamMember->contact->lastName) : 0;
$sortOrder = $priorityLevel . '-' . $sortOrderPriority . '-' . $rolePriority . '-' . $lastNamePriority;
$sortOrder = str_pad($priorityLevel, 3, '0', STR_PAD_LEFT) . '-' . str_pad($sortOrderPriority, 3, '0', STR_PAD_LEFT) . '-' . str_pad($rolePriority, 3, '0', STR_PAD_LEFT) . '-' . str_pad($lastNamePriority, 3, '0', STR_PAD_LEFT);

return $sortOrder;
});
Expand Down Expand Up @@ -2761,26 +2761,28 @@ public function getSalesRestrictions()
public function getRolePriority($role)
{
$rolePriorities = [
'Author' => 1,
'Editor in Chief' => 2,
'Editing author' => 3,
'Index' => 4,
'Preface' => 5,
'Foreword' => 6,
'Introduction' => 7,
'Prologue' => 8,
'Afterword' => 9,
'Epilogue' => 10,
'Illustrator' => 11,
'Photographer' => 12,
'Reader' => 13,
'Translator' => 14,
'Graphic Designer' => 15,
'Cover design or artwork by' => 16,
'Composer' => 17,
'Arranged by' => 18,
'Maps' => 19,
'Assistant' => 20,
'Author WS' => 1,
'Editor WS in Chief' => 2,
'Editing WS author' => 3,
'Index WS' => 4,
'Preface WS' => 5,
'Foreword WS' => 6,
'Introduction WS' => 7,
'Prologue WS' => 8,
'Afterword WS' => 9,
'Epilogue WS' => 10,
'Illustrator WS' => 11,
'Illustrator, cover WS' => 11,
'Designer, cover WS' => 11,
'Photographer WS' => 12,
'Reader WS' => 13,
'Translator WS' => 14,
'Graphic WS Designer' => 15,
'Cover WS design or artwork by' => 16,
'Composer WS' => 17,
'Arranged WS by' => 18,
'Maps WS' => 19,
'Assistant WS' => 20,
];

if (array_key_exists($role, $rolePriorities)) {
Expand Down
35 changes: 28 additions & 7 deletions tests/GroschenIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1399,10 +1399,6 @@ public function testGettingPublishingStatus()
// Published
$this->assertSame('04', $this->groschen->getPublishingStatus());

// Development
$groschen = new Groschen('9789513196721');
$this->assertSame('02', $groschen->getPublishingStatus());

// Exclusive sales
$groschen = new Groschen('9789510491317');
$this->assertSame('04', $groschen->getPublishingStatus());
Expand Down Expand Up @@ -2740,7 +2736,7 @@ public function testGettingProductAvailability()

// Published product that has stock
$groschen = new Groschen('9789510423370');
$this->assertSame('04', $groschen->getPublishingStatus());
$this->assertSame('07', $groschen->getPublishingStatus());
$this->assertSame('21', $groschen->getProductAvailability());

// Published product with 0 stock and no planned reprint in the future
Expand Down Expand Up @@ -3038,7 +3034,7 @@ public function testGettingComments()
*/
public function testGettingSalesStatus()
{
$this->assertSame('Final sales', $this->groschen->getSalesStatus());
$this->assertSame('Donation', $this->groschen->getSalesStatus());

$groschen = new Groschen('9789510381380');
$this->assertSame('Passive', $groschen->getSalesStatus());
Expand Down Expand Up @@ -3728,7 +3724,7 @@ public function testGettingInternalTitle()
9789520447434 => 'Explorer Academy 3. Kaksoiskierre e-kirja',
9789510493151 => 'Minisijainen metsäretkellä eä-kirja',
6430060036031 => 'Sitan kalenteri 2023 kalenteri',
9789523753686 => 'Voihan nenä! pdf',
9789523753686 => 'POISTETTU MYYNNISTÄ Voihan nenä! pdf',
9789510504147 => 'Kettulan kahvila: Pelli-pupun syntymäpäiv eä-kirja',
];

Expand Down Expand Up @@ -3767,4 +3763,29 @@ public function testPocketBookPriceGroupIsFetchedCorrectly()
$groschen = new Groschen('9789510499887');
$this->assertSame('G', $groschen->getPocketBookPriceGroup());
}

/**
* Test that contributor with two digit sort order is ordered correctly
* @group contributors
* @return void
*/
public function testContributorPriorityWithTwoNumberIsSortedCorrectly()
{
$groschen = new Groschen('9789520455637');

// First author
$firstAuthor = [
'Identifier' => 64846,
'SequenceNumber' => 1,
'ContributorRole' => 'A01',
'PersonName' => 'Lotta-Sofia Saahko',
'PersonNameInverted' => 'Saahko, Lotta-Sofia',
'KeyNames' => 'Saahko',
'NamesBeforeKey' => 'Lotta-Sofia',
'BiographicalNote' => '<p><strong>Lotta-Sofia Saahko</strong> (FM) on monipuolinen taitaja, jolla on pitkä kokemus sekä musiikkiteatterilavoilta että YouTubesta, ja joka on kirjoittanut runoja pienestä pitäen. Hän on opiskellut ja työskennellyt koko elämänsä ulkomailla, ja siksi suomalaiset ja karjalaiset juurensa ovat hänelle tärkeitä. Kotimaan tukipisteenä on aina ollut Valkeakosken pappala, ja papasta ja Lotasta on tullut toimiva tiimi.</p>',
'WebSites' => [],
'ContributorDates' => [],
];
$this->assertContains($firstAuthor, $groschen->getContributors());
}
}

0 comments on commit dc63bb7

Please sign in to comment.