{% extends "website/base.html.twig" %}
{% block title %}Ateliers{% endblock %}
{% block body %}
<div class="container workregister">
<div class="row">
<div class="col">
<div class="workregister__inner">
<h2>Comment m'inscrire ?</h2>
<p>Si vous souhaitez vous inscrire à l’un de nos ateliers, vous pouvez nous contacter par :</p>
<ul>
<li><img src="website/Assets/dot-li.svg" alt="Point de liste"><a href="{{ path('contact')}}">Via notre formulaire de contact</a></li>
<li><img src="website/Assets/dot-li.svg" alt="Point de liste">Mail : contact@lamargueriteasso.fr</li>
<li><img src="website/Assets/dot-li.svg" alt="Point de liste">Tel : 05 55 01 35 94</li>
</ul>
<p>Vous pouvez également <a href="/contact">demander un entretien individuel santé.</a></p>
</div>
</div>
</div>
</div>
<div class="container searchwork">
<div class="row">
<div class="col">
<div class="searchwork__inner">
<select name="category" id="searchwork_cat">
<option value="" disabled selected hidden>Choisir une catégorie</option>
{% for cat in workshopCat %}
<option value="{{cat.id}}">{{cat.name}}</option>
{% endfor %}
</select>
<section>
<input type="text" id="searchwork_bar" placeholder="Rechercher un atelier">
<button><img src="website/Assets/loupe.svg" alt="icone de loupe"></button>
</section>
<button><a {{latestFilename}}>Télécharger le calendrier</a></button>
{# TODO problème, c'est pas bon car l'heure actuelle n'égale pas l'heure du dernier fichier #}
</div>
</div>
</div>
</div>
<div class="container workcontainer">
<div class="row">
{% for work in workshop %}
<div class="col-12 col-lg-12 col-xl-4">
<div data-w-color="{{work.workshopCategory.color}}" class="workcard">
<section class="workcard__header">
{# Affichage de l'image de l'atelier s'il y en a une, sinon affichage de la photo de profil du premier animateur #}
{% if work.image is not empty %}
<img class="BORDER_color_change" src="/assets/images/{{work.image.id}}.{{work.image.extension}}" alt="Photo de profil">
{% else %}
{% if work.contributors is not empty %}
{% set firstContributor = work.contributors|first %}
{% if firstContributor.profilePic is null %}
<div class="BG_color_change BORDER_color_change"></div>
{% else %}
<img class="BORDER_color_change" src="/assets/images/{{firstContributor.profilePic.id}}.{{firstContributor.profilePic.extension}}" alt="Photo de profil">
{% endif %}
{% endif %}
{% endif %}
<ul>
<li><h2 class="TEXT_color_change">{{work.name}}</h2></li>
{% if work.contributors is not empty %}
{# Pour chaque animateur de l'événement :
- S'il ne possède pas de structure, on affiche son nom
- S'il possède une structure :
- Si l'animateur est en showOrganisation, on affiche la structure
- Sinon, on affiche la structure et le nom de l'animateur
#}
{% for cont in work.contributors %}
{% if cont.organisation is null %}
<li><h2>{{ cont.firstname }} {{ cont.lastname }}</h2></li>
{% else %}
{% if cont.showOrganisation == true %}
<li><h2>{{ cont.organisation }}</h2></li>
{% else %}
<li>
<h2>{{ cont.organisation }}</h2>
<h3 class="workcard__header__names">{{ cont.firstname }} {{ cont.lastname }}</h3>
</li>
{% endif %}
{% endif %}
{% endfor %}
{% endif %}
</ul>
<h3 class="BG_color_change workcard__header__tag">{{work.workshopCategory.name}}</h3>
</section>
<section class="workcard__activity BORDER_color_change">
<h3 class="TEXT_color_change">{{work.name}} ?</h3>
<p>{{work.infoWorkshop}}</p>
</section>
<section class="workcard__content">
<h3 class="TEXT_color_change">Activités des scéances :</h3>
<p>{{work.activityWorkshop}}</p>
</section>
<section class="workcard__info BG_color_change">
<h3>Lieux, Jours & Heures</h3>
<p>{{work.place}} <br> {{work.day}} <br> {{work.hours}} </p>
</section>
</div>
</div>
{% endfor %}
</div>
</div>
{{ include("website/workshop/workshop_card_template.html.twig") }}
{% endblock %}
{% block javascripts %}
<script>
$(document).ready(function() {
// Change the color of the workshop card depending on the category
function colorWorkshopCard() {
$('.workcard').each(function() {
// Get the color
var color = $(this).data('w-color');
// For each element in the card, change the color
$(this).find('.BG_color_change').css('background-color', color);
$(this).find('.TEXT_color_change').css('color', color);
$(this).find('.BORDER_color_change').css('border-color', color);
});
}
colorWorkshopCard();
$('#searchwork_cat').change(function() {
// Get the id of the category
var category = $(this).val();
$.ajax({
url: '/api/search/workshop/category?id=' + category,
method: 'GET',
success: function(data) {
// Replace the cards and color them
replaceWorkshopCards(data);
colorWorkshopCard();
}
});
});
$('#searchwork_bar').next('button').click(function(e) {
e.preventDefault();
// Get the value of the searchbar
var searchTerm = $('#searchwork_bar').val();
$.ajax({
url: '/api/search/workshop/content?value=' + searchTerm,
method: 'GET',
success: function(data) {
// Replace the cards and color them
replaceWorkshopCards(data);
colorWorkshopCard();
}
});
});
$('#searchwork_bar').keypress(function(e) {
if(e.which == 13) {
// If enter key is pressed
e.preventDefault();
// Get the value of the searchbar
var searchTerm = $('#searchwork_bar').val();
$.ajax({
url: '/search/workshop/content?value=' + searchTerm,
method: 'GET',
success: function(data) {
// Replace the cards and color them
replaceWorkshopCards(data);
colorWorkshopCard();
}
});
}
});
});
// Create a list of all the Workshop cards
function replaceWorkshopCards(workshops) {
let listHTML = "";
// For each table of data, create a card and add it to the list
workshops.forEach(workshop => {
listHTML +=createWorkshopCard(workshop);
});
// Replace the container content with all the cards created
$('.workcontainer .row').html(listHTML);
}
// Create a card using the workshop data
function createWorkshopCard(workshop) {
// Get the template
var template_workshop_card = $('#workshop_card_template').html();
// Get the first contributor's image
var firstContributorImage = workshop.contributors.length > 0 ? workshop.contributors[0].image : null;
// Build the list of contributors
var contributorsList = workshop.contributors.map(contributor => {
if (contributor.organisation == null) {
return `<h2>${contributor.firstname} ${contributor.lastname}</h2>`;
} else {
if (contributor.showOrganisation) {
console.log(1);
return `<h2>${contributor.organisation}</h2>`;
}
else {
console.log(2);
return `<h2>${contributor.organisation}</h2> <h3 class="workcard__header__names">${contributor.firstname} ${contributor.lastname}</h3>`;
}
return null;
}
}).filter(contributor => contributor !== null).join(', ');
// Replace the placeholders with the data
var listHTML = template_workshop_card
.replace(/%name%/g, workshop.name)
.replace(/%contributors%/g, contributorsList)
.replace(/%cont_image%/g, firstContributorImage ? `${firstContributorImage}` : 'default-image-path.jpg')
.replace(/%cat_name%/g, workshop.cat_name)
.replace(/%cat_color%/g, workshop.cat_color)
.replace(/%info%/g, workshop.info)
.replace(/%activity%/g, workshop.activity)
.replace(/%place%/g, workshop.place)
.replace(/%day%/g, workshop.day)
.replace(/%hours%/g, workshop.hours);
return listHTML;
}
</script>
{% endblock %}