mirror of
https://github.com/wallabag/wallabag.git
synced 2025-10-05 19:31:02 +00:00
Extract user reading time logic in a single place
Extract user reading time computation in a single place under Entry to avoid duplication. This will also fix reading time computation for short entries. RuleTagger logic is slightly changed as we will round when filtering, which will be consistent with frontend display.
This commit is contained in:
parent
1eca3cf327
commit
d24b703315
4 changed files with 13 additions and 5 deletions
|
@ -658,6 +658,14 @@ class Entry
|
|||
$this->readingTime = $readingTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getUserReadingTime()
|
||||
{
|
||||
return round($this->readingTime / $this->getUser()->getConfig()->getReadingSpeed() * 200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -210,7 +210,7 @@ class EntriesExport
|
|||
$publishedDate = $entry->getPublishedAt()->format('Y-m-d');
|
||||
}
|
||||
|
||||
$readingTime = round($entry->getReadingTime() / $user->getConfig()->getReadingSpeed() * 200);
|
||||
$readingTime = $entry->getUserReadingTime();
|
||||
|
||||
$titlepage = $content_start .
|
||||
'<h1>' . $entry->getTitle() . '</h1>' .
|
||||
|
@ -331,7 +331,7 @@ class EntriesExport
|
|||
$authors = implode(',', $publishedBy);
|
||||
}
|
||||
|
||||
$readingTime = $entry->getReadingTime() / $user->getConfig()->getReadingSpeed() * 200;
|
||||
$readingTime = $entry->getUserReadingTime();
|
||||
|
||||
$pdf->addPage();
|
||||
$html = '<h1>' . $entry->getTitle() . '</h1>' .
|
||||
|
|
|
@ -133,7 +133,7 @@ class RuleBasedTagger
|
|||
private function fixEntry(Entry $entry)
|
||||
{
|
||||
$clonedEntry = clone $entry;
|
||||
$clonedEntry->setReadingTime($entry->getReadingTime() / $entry->getUser()->getConfig()->getReadingSpeed() * 200);
|
||||
$clonedEntry->setReadingTime($entry->getUserReadingTime());
|
||||
|
||||
return $clonedEntry;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
{% set reading_time = entry.readingTime / app.user.config.readingSpeed * 200 %}
|
||||
{% set reading_time = entry.userReadingTime %}
|
||||
<i class="material-icons grey-text">timer</i>
|
||||
{% if reading_time > 0 %}
|
||||
<span>{{ 'entry.list.reading_time_minutes_short'|trans({'%readingTime%': reading_time|round}) }}</span>
|
||||
<span>{{ 'entry.list.reading_time_minutes_short'|trans({'%readingTime%': reading_time}) }}</span>
|
||||
{% else %}
|
||||
<span>{{ 'entry.list.reading_time_less_one_minute_short'|trans|raw }}</span>
|
||||
{% endif %}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue