{% extends 'base_home.html.twig' %}
{% block title %}Avis - {{ shop.name }} | MaketOu{% endblock %}
{% block stylesheets %}
{{ parent() }}
<style>
/* Styles spécifiques aux reviews - tous scoped pour éviter les conflits avec le template de base */
.shop-reviews-page .review-card {
border: 1px solid #e0e0e0;
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
background: white;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.shop-reviews-page .review-header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 15px;
}
.shop-reviews-page .review-user {
display: flex;
align-items: center;
}
.shop-reviews-page .review-user-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
background: linear-gradient(45deg, #667eea, #764ba2);
display: flex;
align-items: center;
justify-content: center;
color: white;
font-weight: bold;
margin-right: 12px;
}
.shop-reviews-page .review-user-info h6 {
margin: 0;
font-weight: 600;
color: #333;
}
.shop-reviews-page .review-user-info small {
color: #666;
}
.shop-reviews-page .review-rating {
display: flex;
align-items: center;
gap: 5px;
}
.shop-reviews-page .stars {
color: #ffc107;
font-size: 18px;
}
.shop-reviews-page .review-date {
color: #666;
font-size: 14px;
}
.shop-reviews-page .review-content {
margin-bottom: 15px;
line-height: 1.6;
color: #333;
}
.shop-reviews-page .review-type {
display: inline-block;
background: #f8f9fa;
color: #495057;
padding: 4px 8px;
border-radius: 4px;
font-size: 12px;
margin-bottom: 10px;
}
.shop-reviews-page .review-actions {
display: flex;
gap: 10px;
align-items: center;
}
.shop-reviews-page .helpful-btn {
background: none;
border: 1px solid #dee2e6;
padding: 5px 10px;
border-radius: 4px;
font-size: 12px;
color: #6c757d;
cursor: pointer;
transition: all 0.3s ease;
}
.shop-reviews-page .helpful-btn:hover {
background: #f8f9fa;
border-color: #adb5bd;
}
.shop-reviews-page .helpful-btn.active {
background: #28a745;
color: white;
border-color: #28a745;
}
.shop-reviews-page .stats-card {
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.shop-reviews-page .stats-header {
display: flex;
align-items: center;
margin-bottom: 20px;
}
.shop-reviews-page .overall-rating {
font-size: 48px;
font-weight: bold;
color: #333;
margin-right: 20px;
}
.shop-reviews-page .rating-breakdown {
flex: 1;
}
.shop-reviews-page .rating-bar {
display: flex;
align-items: center;
margin-bottom: 8px;
}
.shop-reviews-page .rating-label {
width: 60px;
font-size: 14px;
color: #666;
}
.shop-reviews-page .rating-progress {
flex: 1;
height: 8px;
background: #e9ecef;
border-radius: 4px;
margin: 0 10px;
overflow: hidden;
}
.shop-reviews-page .rating-fill {
height: 100%;
background: linear-gradient(45deg, #ffc107, #ff8c00);
transition: width 0.3s ease;
}
.shop-reviews-page .rating-count {
width: 40px;
text-align: right;
font-size: 14px;
color: #666;
}
.shop-reviews-page .filters-card {
background: white;
border-radius: 10px;
padding: 20px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
.shop-reviews-page .filter-group {
margin-bottom: 15px;
}
.shop-reviews-page .filter-group label {
font-weight: 600;
margin-bottom: 5px;
display: block;
}
.shop-reviews-page .rating-filter {
display: flex;
gap: 10px;
flex-wrap: wrap;
}
.shop-reviews-page .rating-btn {
padding: 8px 12px;
border: 1px solid #dee2e6;
background: white;
border-radius: 4px;
cursor: pointer;
transition: all 0.3s ease;
font-size: 14px;
}
.shop-reviews-page .rating-btn:hover {
background: #f8f9fa;
}
.shop-reviews-page .rating-btn.active {
background: #007bff;
color: white;
border-color: #007bff;
}
.shop-reviews-page .verified-badge {
background: #28a745;
color: white;
padding: 2px 6px;
border-radius: 3px;
font-size: 10px;
font-weight: bold;
margin-left: 5px;
}
.shop-reviews-page .pagination-wrapper {
display: flex;
justify-content: center;
margin-top: 30px;
}
.shop-reviews-page .btn-review {
background: linear-gradient(45deg, #667eea, #764ba2);
border: none;
color: white;
padding: 12px 24px;
border-radius: 6px;
font-weight: 600;
text-decoration: none;
display: inline-block;
transition: all 0.3s ease;
}
.shop-reviews-page .btn-review:hover {
transform: translateY(-2px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
color: white;
}
.shop-reviews-page .empty-reviews {
text-align: center;
padding: 60px 20px;
color: #666;
}
.shop-reviews-page .empty-reviews i {
font-size: 64px;
color: #ddd;
margin-bottom: 20px;
}
@media (max-width: 768px) {
.shop-reviews-page .review-header {
flex-direction: column;
align-items: flex-start;
}
.shop-reviews-page .stats-header {
flex-direction: column;
text-align: center;
}
.shop-reviews-page .overall-rating {
margin-right: 0;
margin-bottom: 15px;
}
.shop-reviews-page .rating-filter {
justify-content: center;
}
}
</style>
{% endblock %}
{% block body %}
<div class="shop-reviews-page">
<!-- Breadcrumb -->
<section class="banner-area organic-breadcrumb">
<div class="container">
<div class="breadcrumb-banner d-flex flex-wrap align-items-center justify-content-end">
<div class="col-first">
<h1>Avis - {{ shop.name }}</h1>
<nav class="d-flex align-items-center">
<a href="{{ path('ui_home') }}">Accueil<span class="lnr lnr-arrow-right"></span></a>
<a href="{{ path('ui_shop_show', {'slug': shop.slug}) }}">{{ shop.name }}<span class="lnr lnr-arrow-right"></span></a>
<a href="javascript:void(0)">Avis</a>
</nav>
</div>
</div>
</div>
</section>
<section class="blog_area">
<div class="container my-5">
<div class="row">
<!-- Statistiques des avis -->
<div class="col-12">
<div class="stats-card">
<div class="stats-header">
<div class="overall-rating">
{{ stats.averageRating|number_format(1) }}
<div class="stars">{{ stats.averageRating|rating_stars }}</div>
</div>
<div class="rating-breakdown">
{% set ratingMap = {
5: 'fiveStars',
4: 'fourStars',
3: 'threeStars',
2: 'twoStars',
1: 'oneStar'
} %}
{% for rating in 5..1 %}
{% set ratingKey = ratingMap[rating] %}
{% set ratingCount = attribute(stats, ratingKey)|default(0) %}
{% set percentage = stats.totalReviews > 0 ? (ratingCount / stats.totalReviews * 100) : 0 %}
<div class="rating-bar">
<span class="rating-label">{{ rating }} étoiles</span>
<div class="rating-progress">
<div class="rating-fill" style="width: {{ percentage }}%"></div>
</div>
<span class="rating-count">{{ ratingCount }}</span>
</div>
{% endfor %}
</div>
</div>
<div class="row text-center">
<div class="col-md-3">
<h4>{{ stats.totalReviews }}</h4>
<p class="text-muted mb-0">Avis total</p>
</div>
<div class="col-md-3">
<h4>{{ stats.positivePercentage }}%</h4>
<p class="text-muted mb-0">Positifs</p>
</div>
<div class="col-md-3">
<h4>{{ stats.verifiedReviews }}</h4>
<p class="text-muted mb-0">Vérifiés</p>
</div>
<div class="col-md-3">
<h4>{{ shop.followersCount|default(0) }}</h4>
<p class="text-muted mb-0">Followers</p>
</div>
</div>
</div>
</div>
<!-- Filtres -->
<div class="col-md-3">
<div class="filters-card">
<h5 class="mb-3">Filtrer les avis</h5>
<div class="filter-group">
<label>Note</label>
<div class="rating-filter">
<button class="rating-btn {{ filters.rating == '' ? 'active' : '' }}" data-rating="">
Toutes
</button>
{% for rating in 5..1 %}
<button class="rating-btn {{ filters.rating == rating ? 'active' : '' }}" data-rating="{{ rating }}">
{{ rating }}★
</button>
{% endfor %}
</div>
</div>
<div class="filter-group">
<label>
<input type="checkbox" {{ filters.verified ? 'checked' : '' }} id="verified-filter">
Avis vérifiés uniquement
</label>
</div>
<div class="filter-group">
<label>Rechercher</label>
<input type="text" class="form-control" id="search-filter" placeholder="Rechercher dans les avis..." value="{{ filters.search }}">
</div>
<button class="btn btn-primary w-100" onclick="applyFilters()">
Appliquer les filtres
</button>
</div>
{% if canReview %}
<div class="text-center mt-3">
<a href="{{ path('shop_reviews_new', {'slug': shop.slug}) }}" class="btn-review">
<i class="lnr lnr-star"></i> Laisser un avis
</a>
</div>
{% endif %}
</div>
<!-- Liste des avis -->
<div class="col-md-9">
{% if reviews|length > 0 %}
<div id="reviews-container">
{% for review in reviews %}
<div class="review-card">
<div class="review-header">
<div class="review-user">
<div class="review-user-avatar">
{{ review.user.firstName|first|upper|default(review.user.email|first|upper) }}
</div>
<div class="review-user-info">
<h6>{{ review.user.firstName|default('Utilisateur') }}</h6>
<small>{{ review.getTimeAgo() }}</small>
</div>
</div>
<div class="review-rating">
<div class="stars">{{ review.getRatingStars() }}</div>
{% if review.isVerified %}
<span class="verified-badge">✓ Vérifié</span>
{% endif %}
</div>
</div>
{% if review.reviewType %}
<div class="review-type">{{ review.getReviewTypeLabel() }}</div>
{% endif %}
<div class="review-content">
{{ review.comment|nl2br }}
</div>
<div class="review-actions">
<button class="helpful-btn" onclick="markAsHelpful({{ review.id }})">
<i class="lnr lnr-thumbs-up"></i> Utile ({{ review.helpfulCount }})
</button>
<button class="helpful-btn" onclick="markAsNotHelpful({{ review.id }})">
<i class="lnr lnr-thumbs-down"></i> Pas utile ({{ review.notHelpfulCount }})
</button>
{% if review.user == app.user %}
<div class="ms-auto">
<a href="{{ path('shop_reviews_edit', {'slug': shop.slug, 'id': review.id}) }}" class="btn btn-sm btn-outline-primary">
<i class="lnr lnr-pencil"></i> Modifier
</a>
<form method="post" action="{{ path('shop_reviews_delete', {'slug': shop.slug, 'id': review.id}) }}" class="d-inline" onsubmit="return confirm('Supprimer cet avis ?')">
<input type="hidden" name="_token" value="{{ csrf_token('delete' ~ review.id) }}">
<button type="submit" class="btn btn-sm btn-outline-danger">
<i class="lnr lnr-trash"></i> Supprimer
</button>
</form>
</div>
{% endif %}
</div>
</div>
{% endfor %}
</div>
<!-- Pagination -->
{% if pagination.pages > 1 %}
<div class="pagination-wrapper">
<nav>
<ul class="pagination">
{% if pagination.page > 1 %}
<li class="page-item">
<a class="page-link" href="{{ path('shop_reviews_index', {'slug': shop.slug, 'page': pagination.page - 1}) }}">Précédent</a>
</li>
{% endif %}
{% for page in 1..pagination.pages %}
{% if page == pagination.page %}
<li class="page-item active">
<span class="page-link">{{ page }}</span>
</li>
{% else %}
<li class="page-item">
<a class="page-link" href="{{ path('shop_reviews_index', {'slug': shop.slug, 'page': page}) }}">{{ page }}</a>
</li>
{% endif %}
{% endfor %}
{% if pagination.page < pagination.pages %}
<li class="page-item">
<a class="page-link" href="{{ path('shop_reviews_index', {'slug': shop.slug, 'page': pagination.page + 1}) }}">Suivant</a>
</li>
{% endif %}
</ul>
</nav>
</div>
{% endif %}
{% else %}
<div class="empty-reviews">
<i class="lnr lnr-star"></i>
<h3>Aucun avis pour le moment</h3>
<p>Soyez le premier à laisser un avis sur cette boutique !</p>
{% if canReview %}
<a href="{{ path('shop_reviews_new', {'slug': shop.slug}) }}" class="btn-review">
<i class="lnr lnr-star"></i> Laisser un avis
</a>
{% endif %}
</div>
{% endif %}
</div>
</div>
</div>
</section>
</div>
{% endblock %}
{% block javascripts %}
{{ parent() }}
<script>
// Scoper toutes les fonctions dans le contexte de la page reviews pour éviter les conflits
(function() {
'use strict';
function applyFilters() {
const ratingBtn = document.querySelector('.shop-reviews-page .rating-btn.active');
if (!ratingBtn) return;
const rating = ratingBtn.dataset.rating;
const verified = document.getElementById('verified-filter')?.checked || false;
const search = document.getElementById('search-filter')?.value || '';
const params = new URLSearchParams();
if (rating) params.append('rating', rating);
if (verified) params.append('verified', '1');
if (search) params.append('search', search);
window.location.href = '{{ path("shop_reviews_index", {"slug": shop.slug}) }}?' + params.toString();
}
function markAsHelpful(reviewId) {
fetch('{{ path("shop_reviews_helpful", {"slug": shop.slug, "id": "REVIEW_ID"}) }}'.replace('REVIEW_ID', reviewId), {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert(data.message || 'Une erreur est survenue');
}
})
.catch(error => {
console.error('Erreur:', error);
alert('Une erreur est survenue lors du vote');
});
}
function markAsNotHelpful(reviewId) {
fetch('{{ path("shop_reviews_not_helpful", {"slug": shop.slug, "id": "REVIEW_ID"}) }}'.replace('REVIEW_ID', reviewId), {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
}
})
.then(response => response.json())
.then(data => {
if (data.success) {
location.reload();
} else {
alert(data.message || 'Une erreur est survenue');
}
})
.catch(error => {
console.error('Erreur:', error);
alert('Une erreur est survenue lors du vote');
});
}
// Exposer les fonctions globalement pour les boutons onclick
window.applyFilters = applyFilters;
window.markAsHelpful = markAsHelpful;
window.markAsNotHelpful = markAsNotHelpful;
// Gestion des boutons de filtre par note - scoped à la page reviews
document.addEventListener('DOMContentLoaded', function() {
const reviewPage = document.querySelector('.shop-reviews-page');
if (!reviewPage) return;
reviewPage.querySelectorAll('.rating-btn').forEach(btn => {
btn.addEventListener('click', function() {
reviewPage.querySelectorAll('.rating-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
});
});
});
})();
</script>
{% endblock %}