Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elife assessment updates #1914

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
12 changes: 8 additions & 4 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 69 additions & 6 deletions src/Controller/ArticlesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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). <a href="https://elifesciences.org/about/elife-assessments">Learn more about eLife Assessments</a>';
$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;
Expand Down Expand Up @@ -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>(.*?)<\/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("<p><b>%s</b>: %s</p>", ucfirst($termWord), $termDescriptions[$termWord]);
}
}

return $term;
}, $terms);

return [
'highlightedTerm' => $highlightedTerm,
'formattedDescription' => $formattedDescription
];
}
}