Skip to content

Commit 6d4d8a2

Browse files
Merge pull request #47 from lepidus/stable-3_3_0
fix/use chapter pages field for page interval instead page count (OMP 3.3.0)
2 parents 7afbfbf + 2090b2c commit 6d4d8a2

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
@@ -28,6 +28,8 @@ public function createFromChapter($chapter)
2828
$submission = DAORegistry::getDAO('SubmissionDAO')->getById($publication->getData('submissionId'));
2929
$context = Application::getContextDAO()->getById($submission->getData('contextId'));
3030

31+
$pages = $this->extractPages($chapter);
32+
3133
return new ThothWork([
3234
'workType' => ThothWork::WORK_TYPE_BOOK_CHAPTER,
3335
'workStatus' => $this->getWorkStatusByDatePublished($chapter, $publication),
@@ -36,7 +38,9 @@ public function createFromChapter($chapter)
3638
'subtitle' => $chapter->getLocalizedData('subtitle'),
3739
'longAbstract' => HtmlStripper::stripTags($chapter->getLocalizedData('abstract')),
3840
'doi' => DoiFormatter::resolveUrl($chapter->getStoredPubId('doi')),
39-
'pageCount' => $chapter->getPages(),
41+
'pageInterval' => $pages['pageInterval'] ?? null,
42+
'firstPage' => $pages['firstPage'] ?? null,
43+
'lastPage' => $pages['lastPage'] ?? null,
4044
'publicationDate' => $chapter->getDatePublished() ?? $publication->getData('datePublished'),
4145
'landingPage' => $request->getDispatcher()->url(
4246
$request,
@@ -49,6 +53,28 @@ public function createFromChapter($chapter)
4953
]);
5054
}
5155

56+
private function extractPages($chapter): array
57+
{
58+
$pages = $chapter->getPages();
59+
60+
if (empty($pages)) {
61+
return [];
62+
}
63+
64+
if (strpos($pages, '-') === false) {
65+
return [
66+
'firstPage' => trim($pages),
67+
];
68+
}
69+
70+
list($firstPage, $lastPage) = explode('-', $pages);
71+
return [
72+
'pageInterval' => trim($pages),
73+
'firstPage' => trim($firstPage),
74+
'lastPage' => trim($lastPage)
75+
];
76+
}
77+
5278
public function getWorkStatusByDatePublished($chapter, $publication)
5379
{
5480
$dataPublished = $chapter->getDatePublished() ?? $publication->getData('datePublished');

tests/classes/factories/ThothChapterFactoryTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private function setUpMockEnvironment()
136136
->will($this->returnValue('10.12345/11112222'));
137137
$mockChapter->expects($this->any())
138138
->method('getPages')
139-
->will($this->returnValue('31'));
139+
->will($this->returnValue('31 - 50'));
140140
$mockChapter->expects($this->any())
141141
->method('getDatePublished')
142142
->will($this->returnValue('2024-01-01'));
@@ -162,7 +162,9 @@ public function testCreateThothChapterFromChapter()
162162
'longAbstract' => 'This is my chapter abstract',
163163
'publicationDate' => '2024-01-01',
164164
'doi' => 'https://doi.org/10.12345/11112222',
165-
'pageCount' => 31,
165+
'pageInterval' => '31 - 50',
166+
'firstPage' => '31',
167+
'lastPage' => '50',
166168
'landingPage' => 'https://omp.publicknowledgeproject.org/index.php/press/catalog/book/17'
167169
]), $thothChapter);
168170
}

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.1.10.4</release>
7-
<date>2025-08-11</date>
6+
<release>0.1.10.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)