File manager - Edit - /home/webapp69.cm.in.th/u69319090039/Shop39/app/Models/StoreReview.php
Back
<?php class StoreReview extends Model { protected string $table = 'store_reviews'; /** * Get all reviews for a seller with reviewer's details */ public function getReviewsBySeller(int $sellerId): array { $sql = "SELECT sr.*, u.full_name, u.avatar FROM store_reviews sr JOIN users u ON sr.user_id = u.id WHERE sr.seller_id = :seller_id ORDER BY sr.created_at DESC"; $stmt = $this->db->prepare($sql); $stmt->execute(['seller_id' => $sellerId]); return $stmt->fetchAll(); } /** * Get review summary (total reviews and average rating) for a seller */ public function getReviewSummary(int $sellerId): array { $sql = "SELECT COUNT(*) as total_reviews, COALESCE(AVG(rating), 0) as avg_rating FROM store_reviews WHERE seller_id = :seller_id"; $stmt = $this->db->prepare($sql); $stmt->execute(['seller_id' => $sellerId]); return $stmt->fetch(); } /** * Get detailed breakdown of review counts by star rating (1-5) */ public function getRatingBreakdown(int $sellerId): array { $sql = "SELECT rating, COUNT(*) as count FROM store_reviews WHERE seller_id = :seller_id GROUP BY rating"; $stmt = $this->db->prepare($sql); $stmt->execute(['seller_id' => $sellerId]); $results = $stmt->fetchAll(); $breakdown = [5 => 0, 4 => 0, 3 => 0, 2 => 0, 1 => 0]; foreach ($results as $row) { $breakdown[(int)$row['rating']] = (int)$row['count']; } return $breakdown; } /** * Check if an order has already been reviewed */ public function getReviewByOrder(int $orderId): ?array { return $this->findOneWhere(['order_id' => $orderId]); } }
| ver. 1.4 |
Github
|
.
| PHP 7.4.33 | Generation time: 0.24 |
proxy
|
phpinfo
|
Settings