changements departements
This commit is contained in:
parent
fa36f16291
commit
3c8254cb86
@ -460,20 +460,8 @@ class CRVI_Event_Controller {
|
||||
}
|
||||
}
|
||||
|
||||
// Récupérer tous les départements disponibles depuis les CPT
|
||||
$departements_posts = get_posts([
|
||||
'post_type' => 'departement',
|
||||
'numberposts' => -1,
|
||||
'post_status' => 'publish',
|
||||
]);
|
||||
|
||||
$departements = [];
|
||||
foreach ($departements_posts as $post) {
|
||||
$departements[] = [
|
||||
'id' => $post->ID,
|
||||
'nom' => $post->post_title,
|
||||
];
|
||||
}
|
||||
// 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([
|
||||
|
||||
@ -14,6 +14,7 @@ class CRVI_Departement_Model extends Main_Model
|
||||
public static $acf_schema = [
|
||||
'nom' => 'text',
|
||||
'type_dinterventions' => 'repeater',
|
||||
'actif' => 'true_false',
|
||||
];
|
||||
|
||||
/**
|
||||
@ -37,8 +38,11 @@ class CRVI_Departement_Model extends Main_Model
|
||||
$data['id'] = $post->ID;
|
||||
} elseif ($field === 'nom') {
|
||||
$data['nom'] = $post->post_title;
|
||||
} elseif (property_exists(self::class, $field)) {
|
||||
$data[$field] = get_field($field, $post->ID);
|
||||
} elseif ($field === 'actif') {
|
||||
// Charger le champ ACF 'actif'
|
||||
$data['actif'] = function_exists('get_field') ? get_field('actif', $post->ID) : true;
|
||||
} elseif (isset(self::$acf_schema[$field])) {
|
||||
$data[$field] = function_exists('get_field') ? get_field($field, $post->ID) : null;
|
||||
}
|
||||
}
|
||||
return new self($data);
|
||||
@ -50,8 +54,10 @@ class CRVI_Departement_Model extends Main_Model
|
||||
|
||||
/**
|
||||
* Retourne la liste de tous les départements (CPT)
|
||||
* @param bool $simple_list Si true, retourne uniquement id et nom
|
||||
* @param bool $only_active Si true (défaut), ne retourne que les départements actifs
|
||||
*/
|
||||
public static function all($simple_list = false)
|
||||
public static function all($simple_list = false, $only_active = true)
|
||||
{
|
||||
$posts = get_posts([
|
||||
'post_type' => 'departement',
|
||||
@ -59,6 +65,15 @@ class CRVI_Departement_Model extends Main_Model
|
||||
'post_status' => 'publish',
|
||||
]);
|
||||
|
||||
// Filtrer par statut actif si demandé
|
||||
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');
|
||||
});
|
||||
}
|
||||
|
||||
if ($simple_list) {
|
||||
$posts = array_map(function($post) {
|
||||
return [
|
||||
|
||||
@ -149,10 +149,16 @@ function collectFilters() {
|
||||
filters.intervenant = personne;
|
||||
}
|
||||
|
||||
// Département
|
||||
const departement = document.getElementById('departement');
|
||||
if (departement && departement.value && departement.value.trim() !== '') {
|
||||
filters.departement = departement.value;
|
||||
}
|
||||
|
||||
// Type d'intervention
|
||||
const typeIntervention = document.getElementById('type_intervention').value;
|
||||
if (typeIntervention && typeIntervention.trim() !== '') {
|
||||
filters.type_intervention = typeIntervention;
|
||||
const typeIntervention = document.getElementById('type_intervention');
|
||||
if (typeIntervention && typeIntervention.value && typeIntervention.value.trim() !== '') {
|
||||
filters.type_intervention = typeIntervention.value;
|
||||
}
|
||||
|
||||
// Bénéficiaire
|
||||
|
||||
@ -590,6 +590,9 @@ function collectIntervenantFilters() {
|
||||
const typeRdv = document.getElementById('type_rdv')?.value;
|
||||
if (typeRdv) filters.type_rdv = typeRdv;
|
||||
|
||||
const departement = document.getElementById('departement')?.value;
|
||||
if (departement) filters.departement = parseInt(departement);
|
||||
|
||||
const typeIntervention = document.getElementById('type_intervention')?.value;
|
||||
if (typeIntervention) filters.type_intervention = parseInt(typeIntervention);
|
||||
|
||||
@ -617,6 +620,9 @@ function collectColleaguesFilters() {
|
||||
const typeRdv = document.getElementById('type_rdv-colleagues')?.value;
|
||||
if (typeRdv) filters.type_rdv = typeRdv;
|
||||
|
||||
const departement = document.getElementById('departement-colleagues')?.value;
|
||||
if (departement) filters.departement = parseInt(departement);
|
||||
|
||||
const typeIntervention = document.getElementById('type_intervention-colleagues')?.value;
|
||||
if (typeIntervention) filters.type_intervention = parseInt(typeIntervention);
|
||||
|
||||
@ -758,6 +764,17 @@ async function loadFilterOptions(mode = 'intervenant') {
|
||||
});
|
||||
}
|
||||
|
||||
// Départements
|
||||
const departementSelect = document.getElementById(`departement${prefix}`);
|
||||
if (departementSelect && disponibilites.departements) {
|
||||
disponibilites.departements.forEach(dept => {
|
||||
const option = document.createElement('option');
|
||||
option.value = dept.id;
|
||||
option.textContent = dept.nom;
|
||||
departementSelect.appendChild(option);
|
||||
});
|
||||
}
|
||||
|
||||
// Types d'intervention
|
||||
const typeInterventionSelect = document.getElementById(`type_intervention${prefix}`);
|
||||
if (typeInterventionSelect && disponibilites.types_intervention) {
|
||||
|
||||
@ -39,6 +39,18 @@
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter">
|
||||
<label for="departement">Département</label>
|
||||
<select id="departement" name="departement" class="select2">
|
||||
<option value="">Tous</option>
|
||||
<!-- Options dynamiques -->
|
||||
<?php
|
||||
foreach ($departements as $departement) {
|
||||
echo '<option value="' . $departement['id'] . '">' . $departement['nom'] . '</option>';
|
||||
}
|
||||
?>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter" style="display: none;">
|
||||
<label for="type_intervention">Type d'intervention</label>
|
||||
<select id="type_intervention" name="type_intervention" class="select2">
|
||||
<option value="">Tous</option>
|
||||
|
||||
@ -96,6 +96,12 @@ $user = wp_get_current_user();
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter">
|
||||
<label for="departement">Département</label>
|
||||
<select id="departement" name="departement" class="select2">
|
||||
<option value="">Tous</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter" style="display: none;">
|
||||
<label for="type_intervention">Type d'intervention</label>
|
||||
<select id="type_intervention" name="type_intervention" class="select2">
|
||||
<option value="">Tous</option>
|
||||
@ -167,6 +173,12 @@ $user = wp_get_current_user();
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter">
|
||||
<label for="departement-colleagues">Département</label>
|
||||
<select id="departement-colleagues" name="departement" class="select2">
|
||||
<option value="">Tous</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter" style="display: none;">
|
||||
<label for="type_intervention-colleagues">Type d'intervention</label>
|
||||
<select id="type_intervention-colleagues" name="type_intervention" class="select2">
|
||||
<option value="">Tous</option>
|
||||
|
||||
@ -96,6 +96,12 @@ $user = wp_get_current_user();
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter">
|
||||
<label for="departement">Département</label>
|
||||
<select id="departement" name="departement" class="select2">
|
||||
<option value="">Tous</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter" style="display: none;">
|
||||
<label for="type_intervention">Type d'intervention</label>
|
||||
<select id="type_intervention" name="type_intervention" class="select2">
|
||||
<option value="">Tous</option>
|
||||
@ -167,6 +173,12 @@ $user = wp_get_current_user();
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter">
|
||||
<label for="departement-colleagues">Département</label>
|
||||
<select id="departement-colleagues" name="departement" class="select2">
|
||||
<option value="">Tous</option>
|
||||
</select>
|
||||
</div>
|
||||
<div class="filter" style="display: none;">
|
||||
<label for="type_intervention-colleagues">Type d'intervention</label>
|
||||
<select id="type_intervention-colleagues" name="type_intervention" class="select2">
|
||||
<option value="">Tous</option>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user