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

Update author stats correctly, and show plurality #242

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions application/controllers/cron/Project_status_stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public function __construct()

public function author()
{
// Reset completion and in-progress counts for all authors
// This avoids an edge-case in the later queries: if there are no projects with the given author or status, they leave meta_complete
// and meta_in_progress untouched, resulting in 'phantom' project counts.
$this->db->query('
UPDATE authors
SET meta_complete = 0,
meta_in_progress = 0');

$sql = '
UPDATE authors
JOIN
Expand Down
6 changes: 6 additions & 0 deletions application/helpers/previewer_helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,3 +255,9 @@ function format_playtime($seconds)
$hours = ($remainder - $minutes) / 60;
return sprintf('%02d:%02d:%02d', $hours, $minutes, $seconds);
}

/** Example: translate_plural("%d book", "%d books", $n) => "1 book" or "13 books" */
function translate_plural($one, $other, $n)
{
return sprintf(ngettext($one, $other, $n), $n);
}
5 changes: 4 additions & 1 deletion application/views/catalog/item_blades/author_blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@

<div class="result-data">
<h3><?= format_author($item, FMT_AUTH_YEARS|FMT_AUTH_HTML|FMT_AUTH_LINK) ?></h3>
<p class="book-meta">Completed: <span><?= $item['meta_complete']?> books</span> | In progress: <span><?= $item['meta_in_progress']?> books</span></p>
<p class="book-meta">
Completed: <span><?= translate_plural("%d book", "%d books", $item['meta_complete']) ?></span>
| In progress: <span><?= translate_plural("%d book", "%d books", $item['meta_in_progress']) ?></span>
</p>
</div>
<a href="<?= base_url('author/'. $item['author_id']) ?>" class="more-result">more results</a>
</li>