Ajout departements
This commit is contained in:
parent
b123b75b27
commit
24e8a54ff9
@ -469,20 +469,8 @@ class CRVI_Event_Controller {
|
||||
// Récupérer tous les départements actifs
|
||||
$departements = CRVI_Departement_Model::all(true, true);
|
||||
|
||||
// Récupérer tous les types d'intervention disponibles depuis les CPT
|
||||
$types_intervention_posts = get_posts([
|
||||
'post_type' => 'type_intervention',
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'publish',
|
||||
]);
|
||||
|
||||
$types_intervention = [];
|
||||
foreach ($types_intervention_posts as $post) {
|
||||
$types_intervention[] = [
|
||||
'id' => $post->ID,
|
||||
'nom' => $post->post_title,
|
||||
];
|
||||
}
|
||||
// Récupérer les types d'intervention groupés par département
|
||||
$types_intervention_groupes = self::get_types_intervention_by_departement();
|
||||
|
||||
$response = [
|
||||
'intervenants' => $intervenants_formatted,
|
||||
@ -490,7 +478,7 @@ class CRVI_Event_Controller {
|
||||
'beneficiaires' => $beneficiaires,
|
||||
'langues' => $langues,
|
||||
'departements' => $departements,
|
||||
'types_intervention' => $types_intervention,
|
||||
'types_intervention_groupes' => $types_intervention_groupes,
|
||||
];
|
||||
|
||||
// Inclure les traducteurs seulement si la vérification a été faite
|
||||
@ -501,6 +489,52 @@ class CRVI_Event_Controller {
|
||||
return Api_Helper::json_success($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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, 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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Endpoint pour récupérer les permissions de l'utilisateur courant.
|
||||
* @param WP_REST_Request $request
|
||||
|
||||
@ -69,8 +69,9 @@ class CRVI_Departement_Model extends Main_Model
|
||||
if ($only_active && function_exists('get_field')) {
|
||||
$posts = array_filter($posts, function($post) {
|
||||
$actif = get_field('actif', $post->ID);
|
||||
// Si le champ n'existe pas encore, considérer le département comme actif par défaut
|
||||
return ($actif === null || $actif === true || $actif === 1 || $actif === '1');
|
||||
// N'afficher que les départements où le champ 'actif' est explicitement 'oui' (true, 1, '1', ou 'oui')
|
||||
// Exclure ceux où le champ est null, false, 0, ou inexistant
|
||||
return ($actif === true || $actif === 1 || $actif === '1' || $actif === 'oui');
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -15,7 +15,10 @@ class CRVI_Agenda_View {
|
||||
$locals = CRVI_Local_Model::get_locals([],true);
|
||||
$intervenants = CRVI_Intervenant_Model::get_intervenants([],true);
|
||||
$departements = CRVI_Departement_Model::all(true);
|
||||
$types_intervention = CRVI_Type_Intervention_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');
|
||||
@ -45,4 +48,50 @@ class CRVI_Agenda_View {
|
||||
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;
|
||||
}
|
||||
}
|
||||
@ -775,14 +775,26 @@ async function loadFilterOptions(mode = 'intervenant') {
|
||||
});
|
||||
}
|
||||
|
||||
// Types d'intervention
|
||||
// Types d'intervention groupés par département
|
||||
const typeInterventionSelect = document.getElementById(`type_intervention${prefix}`);
|
||||
if (typeInterventionSelect && disponibilites.types_intervention) {
|
||||
disponibilites.types_intervention.forEach(type => {
|
||||
const option = document.createElement('option');
|
||||
option.value = type.id;
|
||||
option.textContent = type.nom;
|
||||
typeInterventionSelect.appendChild(option);
|
||||
if (typeInterventionSelect && disponibilites.types_intervention_groupes) {
|
||||
// Parcourir les départements et créer des optgroup
|
||||
Object.keys(disponibilites.types_intervention_groupes).forEach(departementId => {
|
||||
const departementData = disponibilites.types_intervention_groupes[departementId];
|
||||
const optgroup = document.createElement('optgroup');
|
||||
optgroup.label = departementData.nom;
|
||||
|
||||
// Ajouter les types d'intervention de ce département
|
||||
if (departementData.types && Array.isArray(departementData.types)) {
|
||||
departementData.types.forEach(type => {
|
||||
const option = document.createElement('option');
|
||||
option.value = type.id;
|
||||
option.textContent = type.nom;
|
||||
optgroup.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
typeInterventionSelect.appendChild(optgroup);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -55,10 +55,14 @@
|
||||
<label for="type_intervention">Type d'intervention</label>
|
||||
<select id="type_intervention" name="type_intervention" class="select2">
|
||||
<option value="">Tous</option>
|
||||
<!-- Options dynamiques -->
|
||||
<!-- Options dynamiques groupées par département -->
|
||||
<?php
|
||||
foreach ($types_intervention as $type_intervention) {
|
||||
echo '<option value="' . $type_intervention['id'] . '">' . $type_intervention['nom'] . '</option>';
|
||||
foreach ($types_intervention_groupes as $departement_id => $departement_data) {
|
||||
echo '<optgroup label="' . esc_attr($departement_data['nom']) . '">';
|
||||
foreach ($departement_data['types'] as $type_intervention) {
|
||||
echo '<option value="' . esc_attr($type_intervention['id']) . '">' . esc_html($type_intervention['nom']) . '</option>';
|
||||
}
|
||||
echo '</optgroup>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user