{% extends 'base2.html.twig' %}
{% block title %}Hello DefaultController!{% endblock %}
{% block body %}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.0/jquery.min.js" integrity="sha512-3gJwYpMe3QewGELv8k/BX9vcqhryRdzRMxVfq6ngyWXwo03GFEzjsUm8Q7RZcHPHksttq7/GFoxjCVUjkjvPdw==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js" defer></script>
<!-- browse product -->
<style>
.fav-message {
color: #fff; /* Blanc */
background-color: #F6249D; /* Rose */
font-size: 12px;
padding: 5px 10px;
border-radius: 5px;
position: absolute;
z-index: 1000;
display: none;
white-space: nowrap;
}
.rating span {
font-size: 2em;
cursor: pointer;
transition: color 0.3s ease;
}
.rating .selected,
.rating span:hover,
.rating span:hover ~ span {
color: #D82E9F;
}
.btnMod {
background-color: #adb9ca;
color: white;
padding: 10px 20px;
text-decoration: none;
border-radius: 5px;
transition: background-color 0.3s ease;
}
.btnMod:hover {
background-color: #0073CD;
color: white;
}
</style>
<section class="browse-product-area page-paddings" style="padding-top: 70px; background-color: white" id="annonces{{ app.session.get('type') }}">
{% if app.session.get('type') == 'pro' and not app.user %}
<div class="container-fluid" style="margin-top : -50px">
<div class="row" style="background: #D82E9F; text-align: right; color: white; height: 70px">
<h2 class="souts-title-particulier" style="padding-right: 8% !important; margin-top: 15px"><i><strong>100 Crédits offerts</strong> dès votre <a href="{{path('inscription',{'type':'pro'})}}" style="color:#fff;font-weight:800;text-decoration:underline!important;">création de compte</a> à utiliser sous <strong>100 jours !</strong> </i></h2>
</div>
</div>
{% endif %}
<div class="container">
<div class="row">
<div class="browse-vote-btn">
<a href="{{path('app_default')}}" class="theme-btn particulier" style="margin-top: 20px; width: 250px"><i class="fas fa-arrow-left"></i>Accueil</a>
</div><br><br>
</div>
<div class="row">
<div class="col-xl-3 col-lg-4 col-md-4 col-sm-12 col-12">
<div class="browse-product-filter">
<div class="filter-box">
<h3 class="theme-title blue">Recherche</h3>
<form action="{{path('annonces')}}" name="searchForm" id="searchForm" method="get">
<div class="filter-menu" style="display: flex; justify-content: center">
<input class="form-control" type="text" placeholder="Rechercher" aria-label="rechercher" style="margin-right:10px;" name="motscles" value="{{motscles}}">
<button class="theme-btn-pro" onclick="submitForm()"><i class="fas fa-search"></i></button>
</div>
</div>
<div class="filter-box">
<h3 class="theme-title blue">Trier par</h3>
<div class="filter-menu">
<ul>
<li>
<input class="styled-checkbox-pro" name="tri" id="styled-checkbox-1" type="checkbox" value="asc" {% if triSearch == 'asc' %}checked{% endif %}>
<label for="styled-checkbox-1"><span>Prix Croissant</span></label>
</li>
<li>
<input class="styled-checkbox-pro" name="tri" id="styled-checkbox-2" type="checkbox" value="desc" {% if triSearch == 'desc' %}checked{% endif %}>
<label for="styled-checkbox-2"><span>Prix Décroissant</span></label>
</li>
</ul>
</div>
</div>
<div class="filter-box">
<h3 class="theme-title blue">Périmètre</h3>
<div class="filter-menu">
<ul>
<li>
<input type="hidden" id="villeSelect" value="{{ville}}">
<select class="js-data-example-ajax" name="ville" style="width:100%" >
</select>
</li>
<li>
<label class="d-flex" for="styled-checkbox-4">
<p>Rayon de</p> <input class="form-control" style="width: 50px; height:30px; margin: 0 1em ;" type="text" name="rayon" id="km" value="{{distance}}">
<p>Km</p>
</label>
</li>
</ul>
<br>
<div align="center" class="text-center">
<button type="submit" class="btn btn-primary w-100" style="background-color : #ADB9CA">Appliquer</button>
</div>
</div>
</div>
<div class="filter-box">
<h3 class="theme-title blue">Rechercher par catégories</h3>
<div class="filter-menu">
<ul>
{% for res in categories %}
<li>
<input class="styled-checkbox-pro" name="categories[]" id="styled-checkbox-cat-{{ res.id }}" type="checkbox" value="{{ res.id }}"
{% if res.id in categoriesSearch %}checked{% endif %}>
<label for="styled-checkbox-cat-{{ res.id }}"><span>{{ res.libelle }}</span></label>
</li>
{% endfor %}
</ul>
</div>
</div>
</div>
</div>
<div class="col-xl-9 col-lg-8 col-md-8 col-sm-12 col-12">
<div class="browse-product-top">
<div class="row">
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
<div class="browse-product-left d-flex align-items-center">
<p>Afficher</p>
<select class="form-select select-btn" name="nbParPage" aria-label="5" onchange="this.form.submit()">
<option value="5" {% if nbParPage == 5 %}selected{% endif %}>5</option>
<option value="10" {% if nbParPage == 10 %}selected{% endif %}>10</option>
<option value="20" {% if nbParPage == 20 %}selected{% endif %}>20</option>
<option value="30" {% if nbParPage == 30 %}selected{% endif %}>30</option>
<option value="25" {% if nbParPage == 25 %}selected{% endif %}>25</option>
<option value="50" {% if nbParPage == 50 %}selected{% endif %}>50</option>
<option value="75" {% if nbParPage == 75 %}selected{% endif %}>75</option>
<option value="100" {% if nbParPage == 100 %}selected{% endif %}>100</option>
</select>
<p>articles</p>
</div>
{% if app.session.get('type') == 'pro' %}
<input class="styled-checkbox-pro" id="styled-checkbox-filtre" type="checkbox" name="pro" onchange="submitForm()" {% if pro == 'on' %}checked{% endif %}>
<label for="styled-checkbox-filtre" ><span>Annonces reservées uniquement aux profesionnels</span></label>
{% endif %}
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
<div class="browse-product-right clearfix">
</div>
</div>
</div>
</div>
</form>
<div class="browse-product-box">
<div class="tab-content">
<div class="tab-pane active" id="view-store-grid" role="tabpanel">
<div class="row">
{% for res in annonces %}
<div class="col-xl-4 col-lg-6 col-md-6 col-sm-6 col-12">
<div class="item-group">
{% if res.booste == 1 %}<span class="store-label">Boosté </span>{% endif %}
<div class="item-group-content">
<div class="items-like">
{% if app.user %}
<button class="btn-fav {% if res.id in favorisUser %}btn-fav-active{% endif %}" id="btnfav{{res.id}}" onclick="addFavoris({{res.id}})">
<i class="far fa-heart"></i>
</button>
<div id="fav-message-{{res.id}}" class="fav-message"></div>
{% else %}
<button class="btn-fav active" data-bs-toggle="modal" data-bs-target="#connexion-modal"><i class="far fa-heart"></i></button>
{% endif %}
</div>
<a href="{{path('detailAnonnce',{'id':res.id})}}">
<div class="item-group-avtar">
{% if res.images %}
<img src="{{asset('uploads/annonces/'~res.images)}}" alt="">
{% endif %}
</div>
<h3 class="theme-title">{{res.titre}}</h3>
<p class="theme-description">{{res.enseigne}} <span>-{{res.pourcentRemise }}%</span></p>
<div class="row price">
<div class="col-6">
<h2 class="item-price" style="text-decoration: line-through;">{{res.prix}}€</h2>
</div>
<div class="col-6">
<h2 class="item-price pink">{{res.newprix }}€</h2>
</div>
</div>
<div class="item-group-timer">
<ul class="clearfix">
<li><span>{{res.heures}}</span> Heure</li>
<li><span>{{res.minutes}}</span> Min</li>
<li><span>{{res.secondes}}</span> Sec</li>
</ul>
</div>
</a>
<div class="row mb-3 review">
<div class="col-12">
<p class="theme-description">Noter l'annonce</p>
<div class="store-ratting2">
{% if app.user %}
<a data-bs-toggle="modal" data-bs-target="#notez-{{ res.id }}" style="color: #D82E9F">
{% else %}
<a data-bs-toggle="modal" data-bs-target="#connexion-modal" style="color: #D82E9F">
{% endif %}
{% if res.moyAnnonce == 0 %}
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 0.5 %}
<i class="fas fa-star-half-alt"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 1 %}
<i class="fas fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 1.5 %}
<i class="fas fa-star"></i>
<i class="fas fa-star-half-alt"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 2 %}
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 2.5 %}
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star-half-alt"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 3 %}
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="far fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 3.5 %}
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star-half-alt"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 4 %}
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="far fa-star"></i>
{% endif %}
{% if res.moyAnnonce == 4.5 %}
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star-half-alt"></i>
{% endif %}
{% if res.moyAnnonce >= 5 %}
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
<i class="fas fa-star"></i>
{% endif %}
({{ res.moyAnnonce }})
</a>
</div>
</div>
</div>
</div>
</div>
<!-- Modal -->
<div class="modal fade" id="notez-{{ res.id }}" tabindex="-1" aria-labelledby="notezLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="notezLabel">Evaluer</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<h2>Evaluez l'annonce : </h2><br>
<div class="rating store-ratting2">
<span data-value="5" title="Evaluer 5 Étoiles">★</span>
<span data-value="4" title="Evaluer 4 Étoiles">★</span>
<span data-value="3" title="Evaluer 3 Étoiles">★</span>
<span data-value="2" title="Evaluer 2 Étoiles">★</span>
<span data-value="1" title="Evaluer 1 Étoile">★</span>
</div>
</div>
<div class="modal-footer">
<a class="btnMod" data-bs-dismiss="modal" style="background-color: #D82E9F">Fermer</a>
<a class="btnMod submitRating" data-annonce-id="{{ res.id }}" style="display: none;">Valider</a>
</div>
</div>
</div>
</div>
<!-- end modal -->
</div>
{% endfor %}
</div>
</div>
</div>
<div class="row">
<div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
<div class="pagination-box text-center">
{{ knp_pagination_render(annonces) }}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</section>
<!-- Modal -->
<!-- end modal -->
<!-- browse product -->
<script>
document.addEventListener('DOMContentLoaded', (event) => {
const searchInput = document.querySelector('input[name="motscles"]');
const searchForm = document.getElementById('searchForm');
searchInput.addEventListener('keydown', function(e) {
if (e.key === 'Enter') {
e.preventDefault();
}
});
searchForm.addEventListener('submit', function(e) {
e.preventDefault();
submitForm();
});
function submitForm() {
searchForm.submit();
}
// Fonction pour soumettre le formulaire ou retirer le tri
function handleTriChange(event) {
const isChecked = event.target.checked;
const triInputs = document.querySelectorAll('input[name="tri"]');
if (!isChecked) {
triInputs.forEach(input => {
input.checked = false;
});
// Supprimer le paramètre 'tri' du formulaire
const triField = document.querySelector('input[name="tri"]');
if (triField) {
triField.value = '';
}
// Soumettre le formulaire sans le paramètre 'tri'
searchForm.submit();
} else {
submitForm();
}
}
// Ajouter un écouteur d'événements aux boutons radio de tri
const triInputs = document.querySelectorAll('input[name="tri"]');
triInputs.forEach(input => {
input.addEventListener('change', handleTriChange);
});
// Ajouter un écouteur d'événements aux checkboxes de catégories
const categoryCheckboxes = document.querySelectorAll('input[name="categories[]"]');
categoryCheckboxes.forEach(checkbox => {
checkbox.addEventListener('change', submitForm);
});
});
function addFavoris(id) {
let elm = document.getElementById("btnfav" + id);
let messageElm = document.createElement('div');
messageElm.classList.add('fav-message');
let etat = elm.classList.contains('btn-fav-active') ? 'active' : 'non active';
let messageText = etat === 'non active' ? "Article ajouté aux favoris :)" : "Article retiré des favoris :(";
messageElm.textContent = messageText;
document.body.appendChild(messageElm);
let rect = elm.getBoundingClientRect();
messageElm.style.top = (rect.top - messageElm.offsetHeight - 5) + 'px';
messageElm.style.left = (rect.left + (elm.offsetWidth / 2) - (messageElm.offsetWidth / 2)) + 'px';
messageElm.style.display = 'block';
setTimeout(function() {
messageElm.style.display = 'none';
document.body.removeChild(messageElm);
}, 3000); // Message disparaît après 3 secondes
$.ajax({
type: "POST",
url: "{{ path('addFavoris') }}",
data: { id: id, etat: etat },
success: function(output) {
elm.classList.toggle("btn-fav-active");
}
});
}
</script>
<script>
$(document).ready(function() {
var selectedRating = 0;
function updateStarDisplay(rating) {
$('.rating span').each(function() {
var value = $(this).data('value');
$(this).toggleClass('selected', value <= rating);
});
}
$('.rating span').on('mouseenter', function() {
var index = $(this).data('value');
updateStarDisplay(index);
});
$('.rating span').on('mouseleave', function() {
updateStarDisplay(selectedRating);
});
$('.rating span').on('click', function() {
selectedRating = $(this).data('value');
updateStarDisplay(selectedRating);
$(this).closest('.modal-content').find('.submitRating').fadeIn('slow');
});
$('.submitRating').on('click', function() {
if (selectedRating > 0) {
var annonceId = $(this).data('annonce-id');
updateRating(selectedRating, annonceId);
} else {
alert('Veuillez sélectionner une note.');
}
});
function updateRating(note, annonceId) {
$.ajax({
type: "POST",
url: "/update-rating",
data: { note: note, annonceId: annonceId },
success: function(response) {
alert('Merci pour votre évaluation de ' + note + ' étoiles!');
$('#notez-' + annonceId).modal('hide');
},
error: function(xhr, status, error) {
console.error(error);
}
});
}
});
</script>
{% endblock %}