{# # ============================================================================ # MOLECULE: SECTION ACCORDION ITEM # ============================================================================ # # Affiche une section de formation dans un accordéon avec ses activités. # Utilisé dans les pages de détail utilisateur et de détail de formation SAM. # # ============================================================================ # PARAMÈTRES # ============================================================================ # # | Paramètre | Type | Défaut | Description | # |-----------------|--------|----------|--------------------------------------| # | section | object | (requis) | Entité section (id, name, position) | # | sectionProgress | object | (requis) | {completed, total} | # | activities | array | [] | Tableau d'actData : | # | | | | activity: entité activité | # | | | | isTrackable: bool | # | | | | completed: bool | # | | | | score: float|null | # | | | | attempts: int|null | # | | | | timeSpent: int | # | | | | timeFormatted: string | # | | | | completedAt: DateTime|null | # | controllerScope | string | 'sam--accordion' | Nom du controller Stimulus | # # ============================================================================ # EXEMPLE D'UTILISATION # ============================================================================ # # {% include '_molecules/section-accordion-item/section-accordion-item.html.twig' with { # section: sectionData.section, # sectionProgress: sectionData.progress, # activities: sectionData.activities # } only %} # # ============================================================================ #} {% set section = section %} {% set sectionProgress = sectionProgress|default({completed: 0, total: 0}) %} {% set activities = activities|default([]) %} {% set controllerScope = controllerScope|default('sam--accordion') %} {% set completedCount = sectionProgress.completed|default(0) %} {% set totalCount = sectionProgress.total|default(0) %} {% set hasTracked = completedCount > 0 %}
{# ── Section header (accordion toggle) ─────────────────────────────────── #} {# ── Activities list (collapsed by default) ────────────────────────────── #}
{% if activities|length == 0 %}
{% include '_atoms/icon/icon.html.twig' with { name: 'info', size: 'xs', color: 'gray' } only %} Aucune activité dans cette section
{% else %}
{% for actData in activities %} {% set activity = actData.activity %} {% set isTrackable = actData.isTrackable|default(false) %} {% set isCompleted = actData.completed|default(false) %}
{# Type icon — vert si validé, gris si non suivi, neutre sinon #} {% if isCompleted %} {% set iconBg = 'bg-success/15' %} {% set iconColor = 'success' %} {% elseif not isTrackable %} {% set iconBg = 'bg-gray-100' %} {% set iconColor = 'gray-300' %} {% else %} {% set iconBg = 'bg-gray-100' %} {% set iconColor = 'gray-400' %} {% endif %}
{% include 'sam/_activity_icon.html.twig' with {type: activity.type, color: iconColor} only %}
{# Name + type #}
{{ activity.name }} {{ activity.type }}
{# Right metadata & badge #}
{% if not isTrackable %} Non suivi {% else %} {# Quiz score #} {% if activity.type == 'quiz' and actData.score is defined and actData.score is not null %} {{ actData.score|number_format(0) }}% {% if actData.attempts is defined and actData.attempts %} {{ actData.attempts }}× {% endif %} {% endif %} {# Completion date #} {% if actData.completedAt is defined and actData.completedAt %} {{ actData.completedAt|date('d/m') }} {% endif %} {# Status badge #} {% if isCompleted %} Validé {% endif %} {% endif %} {% if activity.url is defined and activity.url %} {% endif %}
{% endfor %}
{% endif %}