WebOrbiton
v1.0.0.1

StocketBase

95 lines · 3.6 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)) {
  11. echo '<p>You don\'t have access to reviews.</p>';
  12. return;
  13. }
  14. ​
  15. $usersDb = Database::users();
  16. $db = Database::site();
  17. ​
  18. $statusFilter = in_array($_GET['status'] ?? '', ['visible', 'hidden', 'flagged'], true) ? $_GET['status'] : 'flagged';
  19. ​
  20. $statement = $usersDb->prepare(
  21. 'SELECT r.*, u.display_name, u.email FROM product_reviews r LEFT JOIN user_accounts u ON u.id = r.user_account_id
  22. WHERE r.status = :status ORDER BY r.created_at DESC LIMIT 200'
  23. );
  24. $statement->execute(['status' => $statusFilter]);
  25. $reviews = $statement->fetchAll();
  26. ​
  27. $productIds = array_values(array_unique(array_map(static fn(array $review) => (int) $review['product_id'], $reviews)));
  28. $productTitles = [];
  29. if (!empty($productIds)) {
  30. $placeholders = implode(',', array_fill(0, count($productIds), '?'));
  31. $productStatement = $db->prepare("SELECT id, title FROM products WHERE id IN ($placeholders)");
  32. $productStatement->execute($productIds);
  33. foreach ($productStatement->fetchAll() as $row) {
  34. $productTitles[(int) $row['id']] = $row['title'];
  35. }
  36. }
  37. ​
  38. ?>
  39. <div class="dash-header-row">
  40. <h1 class="dash-title"><?= Icons::icon("star", "icon icon-lg") ?>Reviews</h1>
  41. </div>
  42. ​
  43. <div class="settings-tabs">
  44. <a href="dashboard.php?view=reviews&status=flagged" class="<?= $statusFilter === 'flagged' ? 'active' : '' ?>">Reported</a>
  45. <a href="dashboard.php?view=reviews&status=visible" class="<?= $statusFilter === 'visible' ? 'active' : '' ?>">Visible</a>
  46. <a href="dashboard.php?view=reviews&status=hidden" class="<?= $statusFilter === 'hidden' ? 'active' : '' ?>">Hidden</a>
  47. </div>
  48. ​
  49. <table class="dash-table">
  50. <thead>
  51. <tr>
  52. <th><?= Icons::icon('grid', 'icon icon-sm') ?>Product</th>
  53. <th><?= Icons::icon('user', 'icon icon-sm') ?>Customer</th>
  54. <th><?= Icons::icon('star', 'icon icon-sm') ?>Rating</th>
  55. <th><?= Icons::icon('message', 'icon icon-sm') ?>Review</th>
  56. <th><?= Icons::icon('clock', 'icon icon-sm') ?>Posted</th>
  57. <th></th>
  58. </tr>
  59. </thead>
  60. <tbody>
  61. <?php foreach ($reviews as $review): ?>
  62. <tr>
  63. <td><?= htmlspecialchars($productTitles[(int) $review['product_id']] ?? ('#' . (int) $review['product_id'])) ?></td>
  64. <td><?= htmlspecialchars((string) ($review['display_name'] ?? $review['email'] ?? 'Anonymous')) ?></td>
  65. <td><?= $review['rating'] ? str_repeat('★', (int) $review['rating']) . str_repeat('☆', 5 - (int) $review['rating']) : 'No rating' ?></td>
  66. <td><?= htmlspecialchars(mb_strimwidth((string) $review['body'], 0, 140, '…')) ?></td>
  67. <td><?= htmlspecialchars($review['created_at']) ?></td>
  68. <td class="dash-table-actions">
  69. <?php if ($statusFilter !== 'visible'): ?>
  70. <form method="post" style="display:inline;">
  71. <?= Csrf::field() ?>
  72. <input type="hidden" name="action" value="moderate_review">
  73. <input type="hidden" name="review_id" value="<?= (int) $review['id'] ?>">
  74. <input type="hidden" name="decision" value="show">
  75. <button type="submit" class="dash-btn-small dash-btn-success"><?= Icons::icon('check', 'icon icon-sm') ?>Approve</button>
  76. </form>
  77. <?php endif; ?>
  78. <?php if ($statusFilter !== 'hidden'): ?>
  79. <form method="post" style="display:inline;">
  80. <?= Csrf::field() ?>
  81. <input type="hidden" name="action" value="moderate_review">
  82. <input type="hidden" name="review_id" value="<?= (int) $review['id'] ?>">
  83. <input type="hidden" name="decision" value="hide">
  84. <button type="submit" class="dash-btn-small dash-btn-danger"><?= Icons::icon('x', 'icon icon-sm') ?>Hide</button>
  85. </form>
  86. <?php endif; ?>
  87. </td>
  88. </tr>
  89. <?php endforeach; ?>
  90. <?php if (empty($reviews)): ?>
  91. <tr><td colspan="6">Nothing here right now.</td></tr>
  92. <?php endif; ?>
  93. </tbody>
  94. </table>
  95. ​