{# Document Management Macros Reusable components for document listing and management Usage: {% import 'admin/companies/documents/_macros.html.twig' as docs %} {{ docs.expiration_badge(media) }} #} {# Expiration Badge Displays expiration status with color coding and remaining days @param media Media entity with expiresAt property @return string Badge HTML #} {% macro expiration_badge(media) %} {% if media.expiresAt %} {% set now = 'now'|date('U') %} {% set expirationDate = media.expiresAt|date('U') %} {% set daysLeft = ((expirationDate - now) / 86400)|round(0, 'floor') %} {% if daysLeft < 0 %} {# Expired #} Expiré {% elseif daysLeft <= 7 %} {# Expiring soon (7 days or less) #} {{ daysLeft }}j restant{{ daysLeft > 1 ? 's' : '' }} {% elseif daysLeft <= 30 %} {# Expiring within a month #} {{ daysLeft }}j restants {% else %} {# OK - more than 30 days #} {{ media.expiresAt|date('d/m/Y') }} {% endif %} {% else %} Aucune {% endif %} {% endmacro %} {# File Icon Displays appropriate icon based on MIME type @param media Media entity @param size string Icon size (text-xl, text-2xl, text-4xl, text-6xl) @param show_label boolean Show file type label below icon @return string Icon HTML #} {% macro file_icon(media, size = 'text-2xl', show_label = false) %}
{% if media.category == 'image' or media.mimeType starts with 'image/' %} {% if show_label %}

Image

{% endif %} {% elseif media.mimeType starts with 'video/' %} {% if show_label %}

Vidéo

{% endif %} {% elseif media.mimeType == 'application/pdf' %} {% if show_label %}

PDF

{% endif %} {% elseif 'word' in media.mimeType or (media.originalFileName|split('.')|last|lower) in ['doc', 'docx'] %} {% if show_label %}

Word

{% endif %} {% elseif 'excel' in media.mimeType or 'spreadsheet' in media.mimeType or (media.originalFileName|split('.')|last|lower) in ['xls', 'xlsx'] %} {% if show_label %}

Excel

{% endif %} {% elseif 'powerpoint' in media.mimeType or 'presentation' in media.mimeType or (media.originalFileName|split('.')|last|lower) in ['ppt', 'pptx'] %} {% if show_label %}

PowerPoint

{% endif %} {% elseif 'zip' in media.mimeType or 'rar' in media.mimeType or 'archive' in media.mimeType %} {% if show_label %}

Archive

{% endif %} {% else %} {% if show_label %}

Fichier

{% endif %} {% endif %}
{% endmacro %} {# Document Actions Action buttons for edit/download/view/delete @param media Media entity @param company Company entity @param layout string Layout mode: 'inline' (default), 'stacked', 'compact' @return string Actions HTML #} {% macro document_actions(media, company, layout = 'inline') %} {% set button_class = layout == 'compact' ? 'px-2 py-1 text-xs' : 'px-3 py-1.5 text-sm' %} {% set gap_class = layout == 'stacked' ? 'flex-col gap-2' : 'flex-row gap-1' %}
{# Edit Button (Admin/Manager only) #} {% if not company.deletedAt and (is_granted('ROLE_ADMIN') or is_granted('ROLE_MANAGER')) %} {% endif %} {# Download Button #} Télécharger {# View Button #} Voir {# Delete Button (Admin only) #} {% if is_granted('ROLE_ADMIN') and not company.deletedAt %}
{% endif %}
{% endmacro %} {# Empty State Display when no documents are available @param icon string Font Awesome icon class @param title string Main message @param message string Descriptive text @param show_upload boolean Show upload button @param company Company entity (required if show_upload is true) @return string Empty state HTML #} {% macro empty_state(icon = 'fa-file-alt', title = 'Aucun document disponible', message = '', show_upload = true, company = null) %}

{{ title }}

{% if message %}

{{ message }}

{% endif %} {% if show_upload and company and not company.deletedAt and (is_granted('ROLE_ADMIN') or is_granted('ROLE_MANAGER')) %}
{% endif %}
{% endmacro %} {# Modal Base Base modal structure for consistency @param id string Modal HTML ID @param title string Modal title @param icon string Font Awesome icon for header @param body string Modal body content @param footer string Modal footer content @return string Modal HTML #} {% macro modal_base(id, title, icon, body, footer = '') %} {% endmacro %}