1616
1717use APP \facades \Repo ;
1818use APP \submission \Submission ;
19+ use PKP \core \Core ;
20+ use PKP \doi \Doi ;
21+ use PKP \submission \PKPSubmission ;
1922use ThothApi \GraphQL \Models \Work as ThothWork ;
2023
2124import ('plugins.generic.thoth.classes.formatters.HtmlStripper ' );
@@ -31,18 +34,26 @@ public function createFromPublication($publication)
3134
3235 return new ThothWork ([
3336 'workType ' => $ thothWorkType ?? $ this ->getWorkTypeBySubmissionWorkType ($ submission ->getData ('workType ' )),
34- 'workStatus ' => empty ($ publication ->getData ('datePublished ' ))
35- ? ThothWork::WORK_STATUS_FORTHCOMING
36- : ThothWork::WORK_STATUS_ACTIVE ,
37+ 'workStatus ' => $ this ->getWorkStatusByDatePublished ($ publication ->getData ('datePublished ' )),
3738 'fullTitle ' => $ publication ->getLocalizedFullTitle (),
3839 'title ' => $ publication ->getLocalizedTitle (),
3940 'subtitle ' => $ publication ->getLocalizedData ('subtitle ' ),
4041 'longAbstract ' => HtmlStripper::stripTags ($ publication ->getLocalizedData ('abstract ' )),
4142 'edition ' => $ publication ->getData ('version ' ),
42- 'doi ' => $ publication -> getData ( ' doiObject ' )?->getResolvingUrl( ),
43+ 'doi ' => $ this -> getDoi ( $ publication ),
4344 'publicationDate ' => $ publication ->getData ('datePublished ' ),
44- 'license ' => $ publication ->getData ('licenseUrl ' ),
45- 'copyrightHolder ' => $ publication ->getLocalizedData ('copyrightHolder ' ),
45+ 'license ' => $ publication ->getData ('licenseUrl ' )
46+ ?? $ submission ->_getContextLicenseFieldValue (
47+ null ,
48+ PKPSubmission::PERMISSIONS_FIELD_LICENSE_URL ,
49+ $ publication
50+ ),
51+ 'copyrightHolder ' => $ publication ->getLocalizedData ('copyrightHolder ' )
52+ ?? $ submission ->_getContextLicenseFieldValue (
53+ $ submission ->getData ('locale ' ),
54+ PKPSubmission::PERMISSIONS_FIELD_COPYRIGHT_HOLDER ,
55+ $ publication
56+ ),
4657 'coverUrl ' => $ publication ->getLocalizedCoverImageUrl ($ submission ->getData ('contextId ' )),
4758 'landingPage ' => $ request ->getDispatcher ()->url (
4859 $ request ,
@@ -55,7 +66,7 @@ public function createFromPublication($publication)
5566 ]);
5667 }
5768
58- private function getWorkTypeBySubmissionWorkType ($ submissionWorkType )
69+ public function getWorkTypeBySubmissionWorkType ($ submissionWorkType )
5970 {
6071 $ workTypeMapping = [
6172 Submission::WORK_TYPE_EDITED_VOLUME => ThothWork::WORK_TYPE_EDITED_BOOK ,
@@ -64,4 +75,43 @@ private function getWorkTypeBySubmissionWorkType($submissionWorkType)
6475
6576 return $ workTypeMapping [$ submissionWorkType ];
6677 }
78+
79+ public function getWorkStatusByDatePublished ($ datePublished )
80+ {
81+ if ($ datePublished && $ datePublished <= Core::getCurrentDate ()) {
82+ return ThothWork::WORK_STATUS_ACTIVE ;
83+ }
84+
85+ return ThothWork::WORK_STATUS_FORTHCOMING ;
86+ }
87+
88+ public function getDoi ($ publication )
89+ {
90+ $ doiObject = $ publication ->getData ('doiObject ' );
91+
92+ if ($ doiObject === null ) {
93+ $ publicationFormats = DAORegistry::getDAO ('PublicationFormatDAO ' )
94+ ->getByPublicationId ($ publication ->getId ());
95+ foreach ($ publicationFormats as $ publicationFormat ) {
96+ $ identificationCodes = $ publicationFormat ->getIdentificationCodes ()->toArray ();
97+ foreach ($ identificationCodes as $ identificationCode ) {
98+ if ($ identificationCode ->getCode () == '06 ' ) {
99+ $ doi = $ identificationCode ->getValue ();
100+ if (str_contains ($ doi , 'doi.org ' )) {
101+ $ doi = str_replace ('https://doi.org/ ' , '' , $ doi );
102+ }
103+ $ doiObject = new Doi ();
104+ $ doiObject ->setDoi ($ doi );
105+ break 2 ;
106+ }
107+ }
108+ }
109+ }
110+
111+ if ($ doiObject === null ) {
112+ return $ doiObject ;
113+ }
114+
115+ return $ doiObject ->getResolvingUrl ();
116+ }
67117}
0 commit comments