Skip to content

Commit ae2bce4

Browse files
Merge pull request #48 from lepidus/main
fix/use chapter pages field for page interval instead page count (OMP 3.4.0)
2 parents cae06ad + 9212af1 commit ae2bce4

3 files changed

Lines changed: 33 additions & 5 deletions

File tree

classes/factories/ThothChapterFactory.inc.php

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public function createFromChapter($chapter)
2929
$submission = Repo::submission()->get($publication->getData('submissionId'));
3030
$context = Application::getContextDAO()->getById($submission->getData('contextId'));
3131

32+
$pages = $this->extractPages($chapter);
33+
3234
return new ThothWork([
3335
'workType' => ThothWork::WORK_TYPE_BOOK_CHAPTER,
3436
'workStatus' => $this->getWorkStatusByDatePublished($chapter, $publication),
@@ -37,7 +39,9 @@ public function createFromChapter($chapter)
3739
'subtitle' => $chapter->getLocalizedData('subtitle'),
3840
'longAbstract' => HtmlStripper::stripTags($chapter->getLocalizedData('abstract')),
3941
'doi' => $chapter->getData('doiObject')?->getResolvingUrl(),
40-
'pageCount' => !empty($chapter->getPages()) ? (int) $chapter->getPages() : null,
42+
'pageInterval' => $pages['pageInterval'] ?? null,
43+
'firstPage' => $pages['firstPage'] ?? null,
44+
'lastPage' => $pages['lastPage'] ?? null,
4145
'publicationDate' => $chapter->getDatePublished() ?? $publication->getData('datePublished'),
4246
'landingPage' => $request->getDispatcher()->url(
4347
$request,
@@ -60,4 +64,26 @@ public function getWorkStatusByDatePublished($chapter, $publication)
6064

6165
return ThothWork::WORK_STATUS_FORTHCOMING;
6266
}
67+
68+
private function extractPages($chapter): array
69+
{
70+
$pages = $chapter->getPages();
71+
72+
if (empty($pages)) {
73+
return [];
74+
}
75+
76+
if (strpos($pages, '-') === false) {
77+
return [
78+
'firstPage' => trim($pages),
79+
];
80+
}
81+
82+
list($firstPage, $lastPage) = explode('-', $pages);
83+
return [
84+
'pageInterval' => trim($pages),
85+
'firstPage' => trim($firstPage),
86+
'lastPage' => trim($lastPage)
87+
];
88+
}
6389
}

tests/classes/factories/ThothChapterFactoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private function setUpMockEnvironment()
137137
)
138138
->shouldReceive('getPages')
139139
->withAnyArgs()
140-
->andReturn('31')
140+
->andReturn('31 - 50')
141141
->getMock();
142142

143143
$this->mocks = [];
@@ -161,7 +161,9 @@ public function testCreateThothChapterFromChapter()
161161
'longAbstract' => 'This is my chapter abstract',
162162
'publicationDate' => '2024-01-01',
163163
'doi' => 'https://doi.org/10.12345/11112222',
164-
'pageCount' => 31,
164+
'firstPage' => '31',
165+
'lastPage' => '50',
166+
'pageInterval' => '31 - 50',
165167
'landingPage' => 'https://omp.publicknowledgeproject.org/index.php/press/catalog/book/17'
166168
]), $thothChapter);
167169
}

version.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<version>
44
<application>thoth</application>
55
<type>plugins.generic</type>
6-
<release>0.2.8.4</release>
7-
<date>2025-08-11</date>
6+
<release>0.2.8.5</release>
7+
<date>2025-08-15</date>
88
<lazy-load>1</lazy-load>
99
<class>ThothPlugin</class>
1010
</version>

0 commit comments

Comments
 (0)