97 lines
4.1 KiB
PHP
97 lines
4.1 KiB
PHP
<?php
|
|
|
|
namespace ESI_CRVI_AGENDA\views;
|
|
|
|
use ESI_CRVI_AGENDA\models\CRVI_Local_Model;
|
|
use ESI_CRVI_AGENDA\models\CRVI_Intervenant_Model;
|
|
use ESI_CRVI_AGENDA\models\CRVI_Departement_Model;
|
|
use ESI_CRVI_AGENDA\models\CRVI_Traducteur_Model;
|
|
use ESI_CRVI_AGENDA\helpers\Api_Helper;
|
|
use ESI_CRVI_AGENDA\models\CRVI_Type_Intervention_Model;
|
|
|
|
class CRVI_Agenda_View {
|
|
public static function render_agenda_page() {
|
|
|
|
$locals = CRVI_Local_Model::get_locals([],true);
|
|
$intervenants = CRVI_Intervenant_Model::get_intervenants([],true);
|
|
$departements = CRVI_Departement_Model::all(true);
|
|
|
|
// Récupérer les types d'intervention groupés par département
|
|
$types_intervention_groupes = self::get_types_intervention_by_departement();
|
|
|
|
$traducteurs = CRVI_Traducteur_Model::get_traducteurs([],true);
|
|
$langues_beneficiaire = Api_Helper::get_languages(true);
|
|
$genres = Api_Helper::get_acf_field_options('field_685e466352755');
|
|
$genres = $genres['options'] ?? [];
|
|
|
|
$types_locaux = Api_Helper::get_acf_field_options('field_685bc6db12678');
|
|
$types_locaux = $types_locaux['options'] ?? [];
|
|
|
|
$jours_disponibles = Api_Helper::get_acf_field_options('field_685bdf6d66ef9');
|
|
$jours_disponibles = $jours_disponibles['options'] ?? [];
|
|
|
|
// Récupérer tous les bénéficiaires
|
|
$beneficiaire_model = new \ESI_CRVI_AGENDA\models\CRVI_Beneficiaire_Model();
|
|
$beneficiaires_objects = $beneficiaire_model->get_all_beneficiaires();
|
|
$beneficiaires = [];
|
|
foreach ($beneficiaires_objects as $beneficiaire) {
|
|
$beneficiaires[] = [
|
|
'id' => $beneficiaire->id,
|
|
'nom' => $beneficiaire->nom . ' ' . $beneficiaire->prenom,
|
|
];
|
|
}
|
|
|
|
$template = plugin_dir_path(__FILE__) . '../../templates/admin/agenda-page.php';
|
|
if (file_exists($template)) {
|
|
include $template;
|
|
} else {
|
|
echo '<p style="color:red">Template agenda-page.php introuvable.</p>';
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Récupère les types d'intervention groupés par département
|
|
* @return array Structure: [departement_id => ['nom' => string, 'types' => [['id' => int, 'nom' => string]]]]
|
|
*/
|
|
private static function get_types_intervention_by_departement() {
|
|
$departements = CRVI_Departement_Model::all(true);
|
|
$result = [];
|
|
|
|
foreach ($departements as $departement) {
|
|
$departement_id = $departement['id'];
|
|
$departement_nom = $departement['nom'];
|
|
|
|
// Récupérer le repeater type_dinterventions
|
|
if (function_exists('get_field')) {
|
|
$type_dinterventions = get_field('type_dinterventions', $departement_id);
|
|
|
|
if (is_array($type_dinterventions) && !empty($type_dinterventions)) {
|
|
$types = [];
|
|
foreach ($type_dinterventions as $item) {
|
|
// Le repeater contient 'type' (texte) et 'article_intervention' (ID du CPT)
|
|
$article_intervention_id = $item['article_intervention'] ?? null;
|
|
|
|
if ($article_intervention_id) {
|
|
$type_intervention_post = get_post($article_intervention_id);
|
|
if ($type_intervention_post && $type_intervention_post->post_type === 'type_intervention') {
|
|
$types[] = [
|
|
'id' => $type_intervention_post->ID,
|
|
'nom' => $type_intervention_post->post_title,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!empty($types)) {
|
|
$result[$departement_id] = [
|
|
'nom' => $departement_nom,
|
|
'types' => $types,
|
|
];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
} |