v2.0.0.1
Publisium
- <?php
-
- declare(strict_types=1);
-
- $db = Database::site();
- $isAdmin = Auth::isAdministrative();
-
- if ($isAdmin) {
- $topArticles = $db->query(
- 'SELECT title, views_count, status FROM articles WHERE deleted_at IS NULL ORDER BY views_count DESC LIMIT 10'
- )->fetchAll();
- $totalViews = (int) $db->query('SELECT COALESCE(SUM(views_count), 0) AS total FROM articles WHERE deleted_at IS NULL')->fetch()['total'];
- } else {
- $statement = $db->prepare(
- 'SELECT title, views_count, status FROM articles WHERE author_id = :id AND deleted_at IS NULL ORDER BY views_count DESC LIMIT 10'
- );
- $statement->execute(['id' => $currentUser['id']]);
- $topArticles = $statement->fetchAll();
-
- $totalStatement = $db->prepare('SELECT COALESCE(SUM(views_count), 0) AS total FROM articles WHERE author_id = :id AND deleted_at IS NULL');
- $totalStatement->execute(['id' => $currentUser['id']]);
- $totalViews = (int) $totalStatement->fetch()['total'];
- }
-
- ?>
- <h1 class="dash-title"><?= Icons::icon("stats", "icon icon-lg") ?>Statistics</h1>
-
- <div class="dash-cards">
- <div class="dash-card"><?= Icons::icon('eye', 'icon icon-lg') ?><div class="dash-card-value"><?= number_format($totalViews) ?></div><div class="dash-card-label">Total views</div></div>
- </div>
-
- <h2 class="dash-subtitle"><?= Icons::icon('star', 'icon icon-sm') ?>Most read</h2>
- <table class="dash-table">
- <thead><tr><th><?= Icons::icon('heading', 'icon icon-sm') ?>Title</th><th><?= Icons::icon('eye', 'icon icon-sm') ?>Views</th><th><?= Icons::icon('flag', 'icon icon-sm') ?>Status</th></tr></thead>
- <tbody>
- <?php foreach ($topArticles as $article): ?>
- <tr>
- <td><?= htmlspecialchars($article['title']) ?></td>
- <td><?= number_format((int) $article['views_count']) ?></td>
- <td><span class="status-pill status-<?= htmlspecialchars($article['status']) ?>"><?= htmlspecialchars(dashStatusLabel((string) $article['status'])) ?></span></td>
- </tr>
- <?php endforeach; ?>
- <?php if (empty($topArticles)): ?>
- <tr><td colspan="3">No views yet. Check back once your articles are live.</td></tr>
- <?php endif; ?>
- </tbody>
- </table>
-