diff --git a/composer.lock b/composer.lock index ca56ae56..d7059da2 100644 --- a/composer.lock +++ b/composer.lock @@ -1338,12 +1338,12 @@ "source": { "type": "git", "url": "https://github.com/elifesciences/patterns-php.git", - "reference": "44124efe244fc65e5054f870fb2fd5fe8ceee24c" + "reference": "9aae188e29567ef9db04ccb106e7b4e62112eb0c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/elifesciences/patterns-php/zipball/44124efe244fc65e5054f870fb2fd5fe8ceee24c", - "reference": "44124efe244fc65e5054f870fb2fd5fe8ceee24c", + "url": "https://api.github.com/repos/elifesciences/patterns-php/zipball/9aae188e29567ef9db04ccb106e7b4e62112eb0c", + "reference": "9aae188e29567ef9db04ccb106e7b4e62112eb0c", "shasum": "" }, "require": { @@ -1366,6 +1366,7 @@ "suggest": { "twig/twig": "^2.0, to use PatternExtension" }, + "default-branch": true, "type": "library", "autoload": { "files": [ @@ -1380,7 +1381,10 @@ "MIT" ], "description": "eLife patterns", - "time": "2024-09-03T09:17:41+00:00" + "support": { + "source": "https://github.com/elifesciences/patterns-php/tree/master" + }, + "time": "2024-10-08T11:36:14+00:00" }, { "name": "fabpot/goutte", diff --git a/src/Controller/ArticlesController.php b/src/Controller/ArticlesController.php index a0ebb429..34650272 100644 --- a/src/Controller/ArticlesController.php +++ b/src/Controller/ArticlesController.php @@ -32,6 +32,7 @@ use eLife\Journal\Helper\HasPages; use eLife\Journal\Helper\Humanizer; use eLife\Patterns\ViewModel; +use eLife\Patterns\ViewModel\Assessment; use eLife\Patterns\ViewModel\ArticleSection; use eLife\Patterns\ViewModel\ContentAside; use eLife\Patterns\ViewModel\ContentHeaderNew; @@ -46,6 +47,7 @@ use eLife\Patterns\ViewModel\ReadMoreItem; use eLife\Patterns\ViewModel\SpeechBubble; use eLife\Patterns\ViewModel\TabbedNavigation; +use eLife\Patterns\ViewModel\Term; use eLife\Patterns\ViewModel\ViewSelector; use GuzzleHttp\Promise\PromiseInterface; use Symfony\Component\HttpFoundation\RedirectResponse; @@ -309,22 +311,33 @@ private function createFirstPage(Request $request, string $id, array $arguments) if ($item instanceof ArticleVoR && $item->getElifeAssessment()) { $first = true; - $relatedLinks = []; - - $relatedLinks[] = new Link('Read the peer reviews', $this->generatePath($history, $item->getVersion(), 'peer-reviews', 'content')); - $relatedLinks[] = new Link('About eLife assessments', $this->get('router')->generate('inside-elife-article', ['id'=> 'db24dd46'])); + $summary = 'During the peer-review process the editor and reviewers write an eLife Assessment that summarises the significance of the findings reported in the article (on a scale ranging from landmark to useful) and the strength of the evidence (on a scale ranging from exceptional to inadequate). Learn more about eLife Assessments'; + $significanceTerms = [['term' => 'Landmark'], ['term' => 'Fundamental'], ['term' => 'Important'], ['term' => 'Valuable'], ['term' => 'Useful']]; + $strengthTerms = [['term' => 'Exceptional'], ['term' => 'Compelling'], ['term' => 'Convincing'], ['term' => 'Solid'], ['term' => 'Incomplete'], ['term' => 'Inadequate']]; + $content = $item->getElifeAssessment()->getContent(); + $resultSignificance = $this->highlightAndFormatTerms($content, $significanceTerms); + $resultStrength = $this->highlightAndFormatTerms($content, $strengthTerms); + $significanceAriaLable = 'eLife assessments use a common vocabulary to describe significance. The term chosen for this paper is:'; + $strengthAriaLable = 'eLife assessments use a common vocabulary to describe strength of evidence. The term or terms chosen for this paper is:'; + $significance = !empty($resultSignificance['formattedDescription']) ? new Term('Significance of the findings:', implode("\n", $resultSignificance['formattedDescription']), $resultSignificance['highlightedTerm'], $significanceAriaLable) : null; + $strength = !empty($resultStrength['formattedDescription']) ? new Term('Strength of evidence:', implode("\n", $resultStrength['formattedDescription']), $resultStrength['highlightedTerm'], $strengthAriaLable) : null; $parts[] = ArticleSection::collapsible( 'elife-assessment', $item->getElifeAssessmentTitle(), 2, $this->render(...$this->convertContent($item->getElifeAssessment(), 2, $context)), - $relatedLinks, + null, ArticleSection::STYLE_HIGHLIGHTED, false, $first, $item->getElifeAssessment()->getDoi() ? new Doi($item->getElifeAssessment()->getDoi()) : null, - ArticleSection::RELATED_LINKS_SEPARATOR_CIRCLE + null, + new Assessment( + $significance, + $strength, + $summary + ) ); $first = false; @@ -1970,4 +1983,54 @@ private function generatePublicationHistoryForNewVor($history) { return $publicationHistory; } + + private function highlightAndFormatTerms($content, array $terms): array { + $formattedDescription = []; + $highlightedWords = []; + + foreach ($content as $contentItem) { + if (method_exists($contentItem, 'getText')) { + $text = $contentItem->getText(); + + preg_match_all('/(.*?)<\/b>/', $text, $matches); + + if (!empty($matches[1])) { + $highlightedWords = array_merge($highlightedWords, $matches[1]); + } + } + } + + $highlightedTerm = array_map(function ($term) use ($highlightedWords, &$formattedDescription) { + $termDescriptions = [ + 'landmark' => 'Findings with profound implications that are expected to have widespread influence', + 'fundamental' => 'Findings that substantially advance our understanding of major research questions', + 'important' => 'Findings that have theoretical or practical implications beyond a single subfield', + 'valuable' => 'Findings that have theoretical or practical implications for a subfield', + 'useful' => 'Findings that have focused importance and scope', + 'exceptional' => 'Exemplary use of existing approaches that establish new standards for a field', + 'compelling' => 'Evidence that features methods, data and analyses more rigorous than the current state-of-the-art', + 'convincing' => 'Appropriate and validated methodology in line with current state-of-the-art', + 'solid' => 'Methods, data and analyses broadly support the claims with only minor weaknesses', + 'incomplete' => 'Main claims are only partially supported', + 'inadequate' => 'Methods, data and analyses do not support the primary claims', + ]; + + $termWord = strtolower($term['term']); + + if (in_array($termWord, $highlightedWords)) { + $term['isHighlighted'] = true; + + if (isset($termDescriptions[$termWord])) { + $formattedDescription[$termWord] = sprintf("

%s: %s

", ucfirst($termWord), $termDescriptions[$termWord]); + } + } + + return $term; + }, $terms); + + return [ + 'highlightedTerm' => $highlightedTerm, + 'formattedDescription' => $formattedDescription + ]; + } }