192 lines
8.1 KiB
PHP
192 lines
8.1 KiB
PHP
<?php
|
||
/**
|
||
* Template pour la page admin des capacités de traduction
|
||
* Vue moderne avec structure Parent → Enfant
|
||
*/
|
||
|
||
// Sécurité : vérifier que le fichier est bien appelé depuis WordPress
|
||
if (!defined('ABSPATH')) {
|
||
exit;
|
||
}
|
||
|
||
// Helper pour récupérer le(s) nom(s) de langue(s) - gère les langues multiples
|
||
function get_langue_name($post_id) {
|
||
$langue_ids = get_field('langue', $post_id);
|
||
|
||
if (empty($langue_ids)) {
|
||
return '<span class="na">Non définie</span>';
|
||
}
|
||
|
||
// S'assurer que c'est un tableau
|
||
if (!is_array($langue_ids)) {
|
||
$langue_ids = [$langue_ids];
|
||
}
|
||
|
||
$langue_names = [];
|
||
foreach ($langue_ids as $langue_id) {
|
||
$term = get_term($langue_id, 'langue');
|
||
if ($term && !is_wp_error($term)) {
|
||
$langue_names[] = esc_html($term->name);
|
||
}
|
||
}
|
||
|
||
if (empty($langue_names)) {
|
||
return '<span class="na">Non définie</span>';
|
||
}
|
||
|
||
// Si plusieurs langues, les afficher avec des badges
|
||
if (count($langue_names) > 1) {
|
||
$output = '<div class="langue-badges">';
|
||
foreach ($langue_names as $name) {
|
||
$output .= '<span class="langue-badge">' . $name . '</span>';
|
||
}
|
||
$output .= '</div>';
|
||
return $output;
|
||
}
|
||
|
||
return $langue_names[0];
|
||
}
|
||
|
||
// Helper pour récupérer les exceptions d'une capacité
|
||
function get_exceptions_info($post_id) {
|
||
$ajouter_exception = get_field('ajouter_exception', $post_id);
|
||
if (!$ajouter_exception) {
|
||
return null;
|
||
}
|
||
|
||
$exceptions = get_field('exceptions_disponibilites', $post_id);
|
||
if (empty($exceptions)) {
|
||
return null;
|
||
}
|
||
|
||
return $exceptions;
|
||
}
|
||
|
||
// Helper pour formater l'affichage de l'exception
|
||
function format_exception_display($exceptions) {
|
||
if (empty($exceptions)) {
|
||
return '';
|
||
}
|
||
|
||
$frequence = isset($exceptions['frequence']) ? $exceptions['frequence'] : '';
|
||
$frequence_periode = isset($exceptions['frequence_periode']) ? $exceptions['frequence_periode'] : '';
|
||
$periode = isset($exceptions['periode']) ? $exceptions['periode'] : '';
|
||
|
||
if (empty($frequence) || empty($frequence_periode) || empty($periode)) {
|
||
return '';
|
||
}
|
||
|
||
$periode_label = $periode === 'matin' ? 'Matin' : ($periode === 'apres_midi' ? 'Après-midi' : 'Journée');
|
||
$frequence_periode_label = $frequence_periode === 'semaine' ? 'semaine' : 'mois';
|
||
|
||
return sprintf('%d × %s / %s', $frequence, $periode_label, $frequence_periode_label);
|
||
}
|
||
|
||
// Helper pour vérifier si la capacité a des événements
|
||
function has_events_badge($post_id) {
|
||
$has_events = ESI_CRVI_AGENDA\controllers\CRVI_TraductionLangue_Controller::check_events_for_capacite($post_id);
|
||
if ($has_events) {
|
||
return '<span class="badge badge-warning" title="Cette capacité a des événements associés">🔒 Événements</span>';
|
||
}
|
||
return '';
|
||
}
|
||
?>
|
||
|
||
<div class="wrap traduction-langue-list-wrap">
|
||
<h1 class="wp-heading-inline">
|
||
<span class="dashicons dashicons-translation"></span>
|
||
Capacités de traduction
|
||
</h1>
|
||
|
||
<a href="<?php echo admin_url('post-new.php?post_type=traduction_langue'); ?>" class="page-title-action">
|
||
Ajouter une capacité
|
||
</a>
|
||
|
||
<hr class="wp-header-end">
|
||
|
||
<?php if (empty($parent_capacites)) : ?>
|
||
<div class="notice notice-info">
|
||
<p>Aucune capacité de traduction trouvée. <a href="<?php echo admin_url('post-new.php?post_type=traduction_langue'); ?>">Créer la première capacité</a></p>
|
||
</div>
|
||
<?php else : ?>
|
||
<div class="traduction-langue-grid">
|
||
<?php foreach ($parent_capacites as $parent) :
|
||
$langue_name = get_langue_name($parent->ID);
|
||
$jour = get_field('jour', $parent->ID);
|
||
$periode = get_field('periode', $parent->ID);
|
||
$limite = get_field('limite', $parent->ID);
|
||
$limite_par = get_field('limite_par', $parent->ID);
|
||
$actif = get_field('actif', $parent->ID);
|
||
$has_events = has_events_badge($parent->ID);
|
||
|
||
// Récupérer les exceptions
|
||
$exceptions = get_exceptions_info($parent->ID);
|
||
$exception_display = format_exception_display($exceptions);
|
||
|
||
// Calculer le nombre de créneaux utilisés
|
||
$model = ESI_CRVI_AGENDA\models\CRVI_TraductionLangue_Model::load($parent->ID);
|
||
$used = $model ? ESI_CRVI_AGENDA\models\CRVI_TraductionLangue_Model::countUsed($parent->ID, null, $model) : 0;
|
||
$percentage = $limite > 0 ? round(($used / $limite) * 100) : 0;
|
||
$is_full = $percentage >= 100;
|
||
?>
|
||
<div class="capacite-card <?php echo !$actif ? 'inactive' : ''; ?> <?php echo $is_full ? 'full' : ''; ?>">
|
||
<div class="card-header">
|
||
<div class="card-title">
|
||
<h2><?php echo esc_html($parent->post_title); ?></h2>
|
||
<div class="card-badges">
|
||
<?php if (!$actif) : ?>
|
||
<span class="badge badge-inactive">Inactif</span>
|
||
<?php endif; ?>
|
||
<?php echo $has_events; ?>
|
||
</div>
|
||
</div>
|
||
<div class="card-actions">
|
||
<a href="<?php echo get_edit_post_link($parent->ID); ?>" class="button button-primary">
|
||
<span class="dashicons dashicons-edit"></span> Modifier
|
||
</a>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="card-body">
|
||
<div class="info-grid">
|
||
<div class="info-item">
|
||
<span class="info-label">Langue</span>
|
||
<span class="info-value"><?php echo $langue_name; ?></span>
|
||
</div>
|
||
<div class="info-item">
|
||
<span class="info-label">Jour</span>
|
||
<span class="info-value"><?php echo esc_html(ucfirst($jour ?: 'N/A')); ?></span>
|
||
</div>
|
||
<div class="info-item">
|
||
<span class="info-label">Période</span>
|
||
<span class="info-value"><?php echo esc_html(ucfirst($periode ?: 'N/A')); ?></span>
|
||
</div>
|
||
<div class="info-item">
|
||
<span class="info-label">Limite</span>
|
||
<span class="info-value"><?php echo esc_html($limite); ?> / <?php echo esc_html($limite_par); ?></span>
|
||
</div>
|
||
<?php if (!empty($exception_display)) : ?>
|
||
<div class="info-item info-item-full">
|
||
<span class="info-label">Exception</span>
|
||
<span class="info-value exception-badge"><?php echo esc_html($exception_display); ?></span>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div class="usage-bar">
|
||
<div class="usage-label">
|
||
<span>Utilisation</span>
|
||
<span class="usage-stats"><?php echo $used; ?> / <?php echo $limite; ?> (<?php echo $percentage; ?>%)</span>
|
||
</div>
|
||
<div class="usage-progress">
|
||
<div class="usage-progress-bar <?php echo $percentage >= 100 ? 'full' : ($percentage >= 80 ? 'warning' : ''); ?>"
|
||
style="width: <?php echo min($percentage, 100); ?>%"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<?php endforeach; ?>
|
||
</div>
|
||
<?php endif; ?>
|
||
</div>
|