templates/default/annonces.html.twig line 1

Open in your IDE?
  1. {% extends 'base2.html.twig' %}
  2. {% block title %}Hello DefaultController!{% endblock %}
  3. {% block body %}
  4. <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>
  5. <link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet" />
  6. <script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.8/js/select2.min.js" defer></script>
  7. <!-- browse product -->
  8. <style>
  9.     .fav-message {
  10.         color: #fff; /* Blanc */
  11.         background-color: #F6249D; /* Rose */
  12.         font-size: 12px;
  13.         padding: 5px 10px;
  14.         border-radius: 5px;
  15.         position: absolute;
  16.         z-index: 1000;
  17.         display: none;
  18.         white-space: nowrap;
  19.     }
  20. .rating span {
  21.     font-size: 2em;
  22.     cursor: pointer;
  23.     transition: color 0.3s ease;
  24. }
  25. .rating .selected,
  26. .rating span:hover,
  27. .rating span:hover ~ span {
  28.     color: #D82E9F;
  29. }
  30. .btnMod {
  31.     background-color: #adb9ca;
  32.     color: white;
  33.     padding: 10px 20px;
  34.     text-decoration: none;
  35.     border-radius: 5px;
  36.     transition: background-color 0.3s ease;
  37. }
  38. .btnMod:hover {
  39.     background-color: #0073CD;
  40.     color: white;
  41. }
  42. </style>
  43. <section class="browse-product-area page-paddings" style="padding-top: 70px; background-color: white" id="annonces{{ app.session.get('type') }}">
  44.    {% if app.session.get('type') == 'pro' and not app.user %}
  45.       <div class="container-fluid" style="margin-top : -50px">
  46.          <div class="row" style="background: #D82E9F; text-align: right; color: white; height: 70px">
  47.             <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>
  48.          </div>
  49.       </div>
  50.    {% endif %}
  51.    <div class="container">
  52.         <div class="row">
  53.             <div class="browse-vote-btn">
  54.                 <a href="{{path('app_default')}}" class="theme-btn particulier" style="margin-top: 20px; width: 250px"><i class="fas fa-arrow-left"></i>Accueil</a>
  55.             </div><br><br>
  56.         </div>
  57.       <div class="row">
  58.          <div class="col-xl-3 col-lg-4 col-md-4 col-sm-12 col-12">
  59.             <div class="browse-product-filter">
  60.                <div class="filter-box">
  61.                   <h3 class="theme-title blue">Recherche</h3>
  62. <form action="{{path('annonces')}}" name="searchForm" id="searchForm" method="get">
  63.                   <div class="filter-menu" style="display: flex; justify-content: center">
  64.                      <input class="form-control" type="text" placeholder="Rechercher" aria-label="rechercher" style="margin-right:10px;" name="motscles" value="{{motscles}}">
  65.                      <button class="theme-btn-pro" onclick="submitForm()"><i class="fas fa-search"></i></button>
  66.                   </div>
  67.                </div>
  68.                 
  69.                <div class="filter-box">
  70.     <h3 class="theme-title blue">Trier par</h3>
  71.     <div class="filter-menu">
  72.         <ul>
  73.             <li>
  74.                 <input class="styled-checkbox-pro" name="tri" id="styled-checkbox-1" type="checkbox" value="asc" {% if triSearch == 'asc' %}checked{% endif %}>
  75.                 <label for="styled-checkbox-1"><span>Prix Croissant</span></label>
  76.             </li>
  77.             <li>
  78.                 <input class="styled-checkbox-pro" name="tri" id="styled-checkbox-2" type="checkbox" value="desc" {% if triSearch == 'desc' %}checked{% endif %}>
  79.                 <label for="styled-checkbox-2"><span>Prix Décroissant</span></label>
  80.             </li>
  81.         </ul>
  82.     </div>
  83. </div>
  84.                 
  85.                <div class="filter-box">
  86.                   <h3 class="theme-title blue">Périmètre</h3>
  87.                   <div class="filter-menu">
  88.                 
  89.                      <ul>
  90.                         <li>
  91.                         <input type="hidden" id="villeSelect" value="{{ville}}">
  92.                            <select class="js-data-example-ajax" name="ville" style="width:100%" >                                        
  93.                         </select>
  94.                
  95.                            
  96.                         </li>
  97.                         <li>
  98.                            <label class="d-flex" for="styled-checkbox-4">
  99.                               <p>Rayon de</p> <input class="form-control" style="width: 50px; height:30px; margin: 0 1em ;" type="text" name="rayon" id="km" value="{{distance}}">
  100.                               <p>Km</p>
  101.                            </label>
  102.                         </li>
  103.                      </ul>
  104.                      <br>
  105.                   <div align="center" class="text-center">
  106.                   <button type="submit" class="btn btn-primary w-100" style="background-color : #ADB9CA">Appliquer</button>
  107.                   
  108.                   </div>
  109.                   </div>
  110.                </div>
  111.                <div class="filter-box">
  112.                   <h3 class="theme-title blue">Rechercher par catégories</h3>
  113.                   <div class="filter-menu">
  114.                      <ul>
  115.                            {% for res in categories %}
  116.                               <li>
  117.                                  <input class="styled-checkbox-pro" name="categories[]" id="styled-checkbox-cat-{{ res.id }}" type="checkbox" value="{{ res.id }}"
  118.                                        {% if res.id in categoriesSearch %}checked{% endif %}>
  119.                                  <label for="styled-checkbox-cat-{{ res.id }}"><span>{{ res.libelle }}</span></label>
  120.                               </li>
  121.                            {% endfor %}
  122.                      </ul>
  123.                   </div>
  124.                </div>
  125.                
  126.             </div>
  127.          </div>
  128.          <div class="col-xl-9 col-lg-8 col-md-8 col-sm-12 col-12">
  129.             <div class="browse-product-top">
  130.                <div class="row">
  131.                   <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
  132.                      <div class="browse-product-left d-flex align-items-center">
  133.     <p>Afficher</p>
  134.     <select class="form-select select-btn" name="nbParPage" aria-label="5" onchange="this.form.submit()">
  135.         <option value="5" {% if nbParPage == 5 %}selected{% endif %}>5</option>
  136.         <option value="10" {% if nbParPage == 10 %}selected{% endif %}>10</option>
  137.         <option value="20" {% if nbParPage == 20 %}selected{% endif %}>20</option>
  138.         <option value="30" {% if nbParPage == 30 %}selected{% endif %}>30</option>
  139.         <option value="25" {% if nbParPage == 25 %}selected{% endif %}>25</option>
  140.         <option value="50" {% if nbParPage == 50 %}selected{% endif %}>50</option>
  141.         <option value="75" {% if nbParPage == 75 %}selected{% endif %}>75</option>
  142.         <option value="100" {% if nbParPage == 100 %}selected{% endif %}>100</option>
  143.     </select>
  144.     <p>articles</p>
  145. </div>
  146.                      {% if  app.session.get('type') == 'pro' %}
  147.                      <input class="styled-checkbox-pro" id="styled-checkbox-filtre" type="checkbox" name="pro" onchange="submitForm()" {% if pro == 'on' %}checked{% endif %}>
  148.                      <label for="styled-checkbox-filtre" ><span>Annonces reservées uniquement aux profesionnels</span></label>
  149.                      {% endif %}
  150.                   </div>
  151.                   <div class="col-xl-6 col-lg-6 col-md-6 col-sm-12 col-12">
  152.                      <div class="browse-product-right clearfix">
  153.                        
  154.                      </div>
  155.                    
  156.                   </div>
  157.                </div>
  158.             </div>
  159.             </form>
  160.             <div class="browse-product-box">
  161.                <div class="tab-content">
  162.                   <div class="tab-pane active" id="view-store-grid" role="tabpanel">
  163.                      <div class="row">
  164.                      {% for res in annonces %}
  165.                      
  166.                      <div class="col-xl-4 col-lg-6 col-md-6 col-sm-6 col-12">
  167.                         <div class="item-group">
  168.                            {% if res.booste == 1 %}<span class="store-label">Boosté </span>{% endif %}
  169.                            <div class="item-group-content">
  170.                                  <div class="items-like">
  171.                                     {% if app.user %}
  172.                                     <button class="btn-fav {% if res.id in favorisUser %}btn-fav-active{% endif %}" id="btnfav{{res.id}}" onclick="addFavoris({{res.id}})">
  173.                                        <i class="far fa-heart"></i>
  174.                                     </button>
  175.                                     <div id="fav-message-{{res.id}}" class="fav-message"></div>
  176.                                     {% else %}
  177.                                     <button class="btn-fav active" data-bs-toggle="modal" data-bs-target="#connexion-modal"><i class="far fa-heart"></i></button>
  178.                                     {% endif %}
  179.                                  </div>
  180.                                  <a href="{{path('detailAnonnce',{'id':res.id})}}">
  181.                                     <div class="item-group-avtar">
  182.                                        {% if res.images %}
  183.                                        <img src="{{asset('uploads/annonces/'~res.images)}}" alt="">
  184.                                        {% endif %}
  185.                                     </div>
  186.                                     <h3 class="theme-title">{{res.titre}}</h3>
  187.                                     <p class="theme-description">{{res.enseigne}} <span>-{{res.pourcentRemise }}%</span></p>
  188.                                     <div class="row price">
  189.                                        <div class="col-6">
  190.                                              <h2 class="item-price" style="text-decoration: line-through;">{{res.prix}}€</h2>
  191.                                        </div>
  192.                                        <div class="col-6">
  193.                                              <h2 class="item-price pink">{{res.newprix }}€</h2>
  194.                                        </div>
  195.                                     </div>
  196.                                     <div class="item-group-timer">
  197.                                        <ul class="clearfix">
  198.                                              <li><span>{{res.heures}}</span> Heure</li>
  199.                                              <li><span>{{res.minutes}}</span> Min</li>
  200.                                              <li><span>{{res.secondes}}</span> Sec</li>
  201.                                        </ul>
  202.                                     </div>
  203.                                  </a>
  204.                                  <div class="row mb-3 review">
  205.                                     <div class="col-12">
  206.                                        <p class="theme-description">Noter l'annonce</p>
  207.                                        <div class="store-ratting2">
  208.                                              {% if app.user %}
  209.                                              <a data-bs-toggle="modal" data-bs-target="#notez-{{ res.id }}" style="color: #D82E9F">
  210.                                                 {% else %}
  211.                                                 <a data-bs-toggle="modal" data-bs-target="#connexion-modal" style="color: #D82E9F">
  212.                                                    {% endif %}
  213.                                                    {% if res.moyAnnonce == 0 %}
  214.                                                    <i class="far fa-star"></i>
  215.                                                    <i class="far fa-star"></i>
  216.                                                    <i class="far fa-star"></i>
  217.                                                    <i class="far fa-star"></i>
  218.                                                    <i class="far fa-star"></i>
  219.                                                    {% endif %}
  220.                                                    {% if res.moyAnnonce == 0.5 %}
  221.                                                    <i class="fas fa-star-half-alt"></i>
  222.                                                    <i class="far fa-star"></i>
  223.                                                    <i class="far fa-star"></i>
  224.                                                    <i class="far fa-star"></i>
  225.                                                    <i class="far fa-star"></i>
  226.                                                    {% endif %}
  227.                                                    {% if res.moyAnnonce == 1 %}
  228.                                                    <i class="fas fa-star"></i>
  229.                                                    <i class="far fa-star"></i>
  230.                                                    <i class="far fa-star"></i>
  231.                                                    <i class="far fa-star"></i>
  232.                                                    <i class="far fa-star"></i>
  233.                                                    {% endif %}
  234.                                                    {% if res.moyAnnonce == 1.5 %}
  235.                                                    <i class="fas fa-star"></i>
  236.                                                    <i class="fas fa-star-half-alt"></i>
  237.                                                    <i class="far fa-star"></i>
  238.                                                    <i class="far fa-star"></i>
  239.                                                    <i class="far fa-star"></i>
  240.                                                    {% endif %}
  241.                                                    {% if res.moyAnnonce == 2 %}
  242.                                                    <i class="fas fa-star"></i>
  243.                                                    <i class="fas fa-star"></i>
  244.                                                    <i class="far fa-star"></i>
  245.                                                    <i class="far fa-star"></i>
  246.                                                    <i class="far fa-star"></i>
  247.                                                    {% endif %}
  248.                                                    {% if res.moyAnnonce == 2.5 %}
  249.                                                    <i class="fas fa-star"></i>
  250.                                                    <i class="fas fa-star"></i>
  251.                                                    <i class="fas fa-star-half-alt"></i>
  252.                                                    <i class="far fa-star"></i>
  253.                                                    <i class="far fa-star"></i>
  254.                                                    {% endif %}
  255.                                                    {% if res.moyAnnonce == 3 %}
  256.                                                    <i class="fas fa-star"></i>
  257.                                                    <i class="fas fa-star"></i>
  258.                                                    <i class="fas fa-star"></i>
  259.                                                    <i class="far fa-star"></i>
  260.                                                    <i class="far fa-star"></i>
  261.                                                    {% endif %}
  262.                                                    {% if res.moyAnnonce == 3.5 %}
  263.                                                    <i class="fas fa-star"></i>
  264.                                                    <i class="fas fa-star"></i>
  265.                                                    <i class="fas fa-star"></i>
  266.                                                    <i class="fas fa-star-half-alt"></i>
  267.                                                    <i class="far fa-star"></i>
  268.                                                    {% endif %}
  269.                                                    {% if res.moyAnnonce == 4 %}
  270.                                                    <i class="fas fa-star"></i>
  271.                                                    <i class="fas fa-star"></i>
  272.                                                    <i class="fas fa-star"></i>
  273.                                                    <i class="fas fa-star"></i>
  274.                                                    <i class="far fa-star"></i>
  275.                                                    {% endif %}
  276.                                                    {% if res.moyAnnonce == 4.5 %}
  277.                                                    <i class="fas fa-star"></i>
  278.                                                    <i class="fas fa-star"></i>
  279.                                                    <i class="fas fa-star"></i>
  280.                                                    <i class="fas fa-star"></i>
  281.                                                    <i class="fas fa-star-half-alt"></i>
  282.                                                    {% endif %}
  283.                                                    {% if res.moyAnnonce >= 5 %}
  284.                                                    <i class="fas fa-star"></i>
  285.                                                    <i class="fas fa-star"></i>
  286.                                                    <i class="fas fa-star"></i>
  287.                                                    <i class="fas fa-star"></i>
  288.                                                    <i class="fas fa-star"></i>
  289.                                                    {% endif %}
  290.                                                    ({{ res.moyAnnonce }})
  291.                                                 </a>
  292.                                        </div>
  293.                                     </div>
  294.                                  </div>
  295.                            </div>
  296.                         </div>
  297.                      <!-- Modal -->
  298.                      <div class="modal fade" id="notez-{{ res.id }}" tabindex="-1" aria-labelledby="notezLabel" aria-hidden="true">
  299.                         <div class="modal-dialog">
  300.                            <div class="modal-content">
  301.                               <div class="modal-header">
  302.                                  <h5 class="modal-title" id="notezLabel">Evaluer</h5>
  303.                                  <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
  304.                               </div>
  305.                               <div class="modal-body">
  306.                                  <h2>Evaluez l'annonce : </h2><br>
  307.                                  <div class="rating store-ratting2">
  308.                                     <span data-value="5" title="Evaluer 5 Étoiles">★</span>
  309.                                     <span data-value="4" title="Evaluer 4 Étoiles">★</span>
  310.                                     <span data-value="3" title="Evaluer 3 Étoiles">★</span>
  311.                                     <span data-value="2" title="Evaluer 2 Étoiles">★</span>
  312.                                     <span data-value="1" title="Evaluer 1 Étoile">★</span>
  313.                                  </div>
  314.                               </div>
  315.                               <div class="modal-footer">
  316.                                  <a class="btnMod" data-bs-dismiss="modal" style="background-color: #D82E9F">Fermer</a>
  317.                                  <a class="btnMod submitRating" data-annonce-id="{{ res.id }}" style="display: none;">Valider</a>
  318.                               </div>
  319.                            </div>
  320.                         </div>
  321.                      </div>
  322.                      <!-- end modal -->
  323.                      </div>
  324.                      {% endfor %}
  325.                        
  326.                      </div>
  327.                   </div>
  328.                </div>
  329.                <div class="row">
  330.                   <div class="col-xl-12 col-lg-12 col-md-12 col-sm-12 col-12">
  331.                      <div class="pagination-box text-center">
  332.                         {{ knp_pagination_render(annonces) }}
  333.                      </div>
  334.                   </div>
  335.                </div>
  336.             </div>
  337.            
  338.          </div>
  339.       </div>
  340.    </div>
  341. </section>
  342. <!-- Modal -->
  343. <!-- end modal -->
  344. <!-- browse product -->
  345. <script>
  346.     document.addEventListener('DOMContentLoaded', (event) => {
  347.         const searchInput = document.querySelector('input[name="motscles"]');
  348.         const searchForm = document.getElementById('searchForm');
  349.         searchInput.addEventListener('keydown', function(e) {
  350.             if (e.key === 'Enter') {
  351.                 e.preventDefault();
  352.             }
  353.         });
  354.         searchForm.addEventListener('submit', function(e) {
  355.             e.preventDefault();
  356.             submitForm();
  357.         });
  358.         function submitForm() {
  359.             searchForm.submit();
  360.         }
  361.         // Fonction pour soumettre le formulaire ou retirer le tri
  362.         function handleTriChange(event) {
  363.             const isChecked = event.target.checked;
  364.             const triInputs = document.querySelectorAll('input[name="tri"]');
  365.             if (!isChecked) {
  366.                 triInputs.forEach(input => {
  367.                     input.checked = false;
  368.                 });
  369.                 // Supprimer le paramètre 'tri' du formulaire
  370.                 const triField = document.querySelector('input[name="tri"]');
  371.                 if (triField) {
  372.                     triField.value = '';
  373.                 }
  374.                 // Soumettre le formulaire sans le paramètre 'tri'
  375.                 searchForm.submit();
  376.             } else {
  377.                 submitForm();
  378.             }
  379.         }
  380.         // Ajouter un écouteur d'événements aux boutons radio de tri
  381.         const triInputs = document.querySelectorAll('input[name="tri"]');
  382.         triInputs.forEach(input => {
  383.             input.addEventListener('change', handleTriChange);
  384.         });
  385.         // Ajouter un écouteur d'événements aux checkboxes de catégories
  386.         const categoryCheckboxes = document.querySelectorAll('input[name="categories[]"]');
  387.         categoryCheckboxes.forEach(checkbox => {
  388.             checkbox.addEventListener('change', submitForm);
  389.         });
  390.     });
  391.  function addFavoris(id) {
  392.         let elm = document.getElementById("btnfav" + id);
  393.         let messageElm = document.createElement('div');
  394.         messageElm.classList.add('fav-message');
  395.         let etat = elm.classList.contains('btn-fav-active') ? 'active' : 'non active';
  396.         let messageText = etat === 'non active' ? "Article ajouté aux favoris :)" : "Article retiré des favoris :(";
  397.         messageElm.textContent = messageText;
  398.         document.body.appendChild(messageElm);
  399.         let rect = elm.getBoundingClientRect();
  400.         messageElm.style.top = (rect.top - messageElm.offsetHeight - 5) + 'px';
  401.         messageElm.style.left = (rect.left + (elm.offsetWidth / 2) - (messageElm.offsetWidth / 2)) + 'px';
  402.         messageElm.style.display = 'block';
  403.         setTimeout(function() {
  404.             messageElm.style.display = 'none';
  405.             document.body.removeChild(messageElm);
  406.         }, 3000); // Message disparaît après 3 secondes
  407.         $.ajax({
  408.             type: "POST",
  409.             url: "{{ path('addFavoris') }}",
  410.             data: { id: id, etat: etat },
  411.             success: function(output) {
  412.                 elm.classList.toggle("btn-fav-active");
  413.             }
  414.         });
  415.     }
  416. </script>
  417. <script>
  418. $(document).ready(function() {
  419.     var selectedRating = 0;
  420.     function updateStarDisplay(rating) {
  421.         $('.rating span').each(function() {
  422.             var value = $(this).data('value');
  423.             $(this).toggleClass('selected', value <= rating);
  424.         });
  425.     }
  426.     $('.rating span').on('mouseenter', function() {
  427.         var index = $(this).data('value');
  428.         updateStarDisplay(index);
  429.     });
  430.     $('.rating span').on('mouseleave', function() {
  431.         updateStarDisplay(selectedRating);
  432.     });
  433.     $('.rating span').on('click', function() {
  434.         selectedRating = $(this).data('value');
  435.         updateStarDisplay(selectedRating);
  436.         $(this).closest('.modal-content').find('.submitRating').fadeIn('slow');
  437.     });
  438.     $('.submitRating').on('click', function() {
  439.         if (selectedRating > 0) {
  440.             var annonceId = $(this).data('annonce-id');
  441.             updateRating(selectedRating, annonceId);
  442.         } else {
  443.             alert('Veuillez sélectionner une note.');
  444.         }
  445.     });
  446.     function updateRating(note, annonceId) {
  447.         $.ajax({
  448.             type: "POST",
  449.             url: "/update-rating",
  450.             data: { note: note, annonceId: annonceId },
  451.             success: function(response) {
  452.                 alert('Merci pour votre évaluation de ' + note + ' étoiles!');
  453.                 $('#notez-' + annonceId).modal('hide');
  454.             },
  455.             error: function(xhr, status, error) {
  456.                 console.error(error);
  457.             }
  458.         });
  459.     }
  460. });
  461. </script>
  462. {% endblock %}