From c6a1e3826320dfd9b87e2243c2916701ffff892e Mon Sep 17 00:00:00 2001 From: LinaKind Date: Fri, 6 Dec 2024 13:45:53 +0000 Subject: [PATCH] Introduce an unused function to build terms in reviewed preprint teasers https://github.com/elifesciences/issues/issues/9034 --- .../ReviewedPreprintTeaserConverter.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/ViewModel/Converter/ReviewedPreprintTeaserConverter.php b/src/ViewModel/Converter/ReviewedPreprintTeaserConverter.php index 494f812f..2c7829d2 100644 --- a/src/ViewModel/Converter/ReviewedPreprintTeaserConverter.php +++ b/src/ViewModel/Converter/ReviewedPreprintTeaserConverter.php @@ -2,9 +2,11 @@ namespace eLife\Journal\ViewModel\Converter; +use eLife\ApiSdk\Model\ElifeAssessment; use eLife\ApiSdk\Model\ReviewedPreprint; use eLife\Journal\Helper\ModelName; use eLife\Patterns\ViewModel; +use eLife\Patterns\ViewModel\TeaserTerms; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; final class ReviewedPreprintTeaserConverter implements ViewModelConverter @@ -50,6 +52,7 @@ public function convert($object, string $viewModel = null, array $context = []) $object->getThumbnail() ? $this->smallTeaserImage($object) : null, ViewModel\TeaserFooter::forArticle( $meta + // $object->getElifeAssessment() ? $this->buildTeaserTerms($object->getElifeAssessment()) : null ) ); } @@ -63,4 +66,22 @@ protected function getViewModelConverter() : ViewModelConverter { return $this->viewModelConverter; } + + private function buildTeaserTerms(ElifeAssessment $elifeAssessment) + { + $significance = array_map( + function ($significanceValue) { + return new ViewModel\Term($significanceValue); + }, + $elifeAssessment->getSignificance() ?? [] + ); + + $strength = array_map( + function ($strengthValue) { + return new ViewModel\Term($strengthValue); + }, + $elifeAssessment->getStrength() ?? [] + ); + return new TeaserTerms(array_merge($significance, $strength)); + } }