introducing some utilities functions
This commit is contained in:
parent
b77e053b79
commit
fb729e9bc1
150
includes/utilities.php
Normal file
150
includes/utilities.php
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
<?php
|
||||
|
||||
function getAllBatimentsTermsByParents()
|
||||
{
|
||||
// Récupérer tous les termes de la taxonomie 'elementsbatiments' avec une hiérarchie
|
||||
$ElementBatimentsTerms = get_terms([
|
||||
'taxonomy' => 'elementsbatiments',
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
|
||||
$terms_by_parent = [];
|
||||
$child_terms = [];
|
||||
|
||||
if ($ElementBatimentsTerms) {
|
||||
|
||||
// Boucle pour organiser les termes en fonction de leurs parents
|
||||
foreach ($ElementBatimentsTerms as $term) {
|
||||
if ($term->parent == 0) {
|
||||
// Si c'est un parent, on le place dans le tableau des parents
|
||||
$terms_by_parent[$term->term_id] = ['term' => $term, 'children' => []];
|
||||
} else {
|
||||
$child_terms[$term->parent][] = $term;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Réunir les termes parents et leurs enfants
|
||||
foreach ($terms_by_parent as $parent_id => &$parent_data) {
|
||||
// Ajouter les enfants au parent
|
||||
if (isset($child_terms[$parent_id])) {
|
||||
$parent_data['children'] = $child_terms[$parent_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $terms_by_parent;
|
||||
}
|
||||
|
||||
function getAllMetiersTermsByParents()
|
||||
{
|
||||
// Récupérer tous les termes de la taxonomie 'elementsbatiments' avec une hiérarchie
|
||||
$MetiersTerms = get_terms([
|
||||
'taxonomy' => 'metiers',
|
||||
'orderby' => 'name',
|
||||
'order' => 'ASC',
|
||||
'hide_empty' => false,
|
||||
]);
|
||||
$terms_by_parent = [];
|
||||
$child_terms = [];
|
||||
|
||||
if ($MetiersTerms) {
|
||||
|
||||
// Boucle pour organiser les termes en fonction de leurs parents
|
||||
foreach ($MetiersTerms as $term) {
|
||||
if ($term->parent == 0) {
|
||||
// Si c'est un parent, on le place dans le tableau des parents
|
||||
$terms_by_parent[$term->term_id] = ['term' => $term, 'children' => []];
|
||||
} else {
|
||||
$child_terms[$term->parent][] = $term;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Réunir les termes parents et leurs enfants
|
||||
foreach ($terms_by_parent as $parent_id => &$parent_data) {
|
||||
// Ajouter les enfants au parent
|
||||
if (isset($child_terms[$parent_id])) {
|
||||
$parent_data['children'] = $child_terms[$parent_id];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $terms_by_parent;
|
||||
}
|
||||
|
||||
|
||||
function get_region_by_postcode($postcode)
|
||||
{
|
||||
// Conversion du code postal en entier pour faciliter les comparaisons
|
||||
$postcode = (int) $postcode;
|
||||
|
||||
// Bruxelles (1000 - 1200)
|
||||
if ($postcode >= 1000 && $postcode <= 1200) {
|
||||
return 'Bruxelles';
|
||||
}
|
||||
|
||||
// Flandre (8000 - 8999 : Flandre occidentale, 9000 - 9999 : Flandre orientale, 2000 - 2999 : Anvers, etc.)
|
||||
if (($postcode >= 8000 && $postcode <= 8999) ||
|
||||
($postcode >= 9000 && $postcode <= 9999) ||
|
||||
($postcode >= 2000 && $postcode <= 2999) ||
|
||||
($postcode >= 1500 && $postcode <= 1999) ||
|
||||
($postcode >= 3500 && $postcode <= 3999)
|
||||
) {
|
||||
return 'Flandre';
|
||||
}
|
||||
|
||||
// Wallonie (4000 - 4999 : Liège, 6000 - 6999 : Hainaut, 6600 - 6999 : Luxembourg, 5000 - 5999 : Namur, etc.)
|
||||
if (($postcode >= 4000 && $postcode <= 4999) ||
|
||||
($postcode >= 6000 && $postcode <= 6999) ||
|
||||
($postcode >= 6600 && $postcode <= 6999) ||
|
||||
($postcode >= 5000 && $postcode <= 5999) ||
|
||||
($postcode >= 1300 && $postcode <= 1499)
|
||||
) {
|
||||
return 'Wallonie';
|
||||
}
|
||||
|
||||
// Retourne une valeur par défaut si le code postal ne correspond à aucune région
|
||||
return 'Inconnu';
|
||||
}
|
||||
|
||||
|
||||
function getAcfStateNameFromEnglish($localisation)
|
||||
{
|
||||
|
||||
if ($localisation === 'brussels') {
|
||||
return 'Bruxelles';
|
||||
}
|
||||
|
||||
if ($localisation === 'flanders') {
|
||||
return 'Vlaams Gewest';
|
||||
}
|
||||
|
||||
if ($localisation === 'wallonia') {
|
||||
return 'Région Wallonne';
|
||||
}
|
||||
if ($localisation === 'all') {
|
||||
return 'all';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function getGenericStateNameFromAcfStateName($state)
|
||||
{
|
||||
if ($state === 'Bruxelles') {
|
||||
return 'brussels';
|
||||
}
|
||||
|
||||
if ($state === 'Vlaams Gewest') {
|
||||
return 'flanders';
|
||||
}
|
||||
|
||||
if ($state === 'Région Wallonne') {
|
||||
return 'wallonia';
|
||||
}
|
||||
if ($state === 'all') {
|
||||
return 'all';
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user