244 lines
5.9 KiB
PHP
244 lines
5.9 KiB
PHP
<?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 'Metiers' 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 getAllUsers()
|
|
{
|
|
$users = get_users();
|
|
return $users;
|
|
}
|
|
|
|
|
|
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';
|
|
}
|
|
};
|
|
|
|
|
|
function format_belgian_vat_number($vat_number)
|
|
{
|
|
$vat_number = strval($vat_number);
|
|
$has_letters = preg_match('/[a-zA-Z]/', $vat_number);
|
|
|
|
if ($has_letters) {
|
|
return $vat_number;
|
|
}
|
|
if (strlen($vat_number) === 9) {
|
|
return 0 . substr($vat_number, 0, 4) . '.' . substr($vat_number, 4, 3) . '.' . substr($vat_number, 7, 3);
|
|
}
|
|
if (strlen($vat_number) !== 10) {
|
|
return $vat_number;
|
|
}
|
|
return substr($vat_number, 0, 4) . '.' . substr($vat_number, 4, 3) . '.' . substr($vat_number, 7, 3);
|
|
}
|
|
|
|
|
|
function getArtisanConseillerName($postID)
|
|
{
|
|
if (!$postID) return;
|
|
$conseiller = get_field('conseiller', $postID);
|
|
if (!$conseiller) return;
|
|
$conseiller_name = $conseiller['user_firstname'] . ' ' . $conseiller['user_lastname'];
|
|
return $conseiller_name;
|
|
}
|
|
|
|
|
|
function translate_wordpress_online_statuses($post_status)
|
|
{
|
|
$status_object = get_post_status_object($post_status);
|
|
|
|
if ($post_status === 'publish') {
|
|
return 'En ligne';
|
|
}
|
|
if ($post_status === 'draft') {
|
|
return 'Brouillon';
|
|
}
|
|
if ($post_status === 'pending') {
|
|
return 'En attente';
|
|
}
|
|
if ($post_status === 'offline') {
|
|
return 'Hors ligne';
|
|
}
|
|
if ($post_status === 'trash') {
|
|
return 'Corbeille';
|
|
}
|
|
return $status_object->label;
|
|
}
|
|
|
|
|
|
function getFrenchDateFromTimestamp($timestamp)
|
|
{
|
|
$date = new DateTime($timestamp);
|
|
$formatter = new IntlDateFormatter(
|
|
'fr_FR',
|
|
IntlDateFormatter::FULL,
|
|
IntlDateFormatter::NONE,
|
|
'Europe/Paris',
|
|
IntlDateFormatter::GREGORIAN,
|
|
'd MMMM y'
|
|
);
|
|
$formatted_date = $formatter->format($date);
|
|
return $formatted_date;
|
|
}
|
|
|
|
|
|
function getRelativeTimeFromTimestamp($timestamp)
|
|
{
|
|
|
|
$date = new DateTime($timestamp);
|
|
$now = new DateTime();
|
|
$interval = $date->diff($now);
|
|
|
|
// Créer le message relatif
|
|
$relative_time = '';
|
|
if ($interval->y > 0) {
|
|
$relative_time = 'il y a ' . $interval->y . ' an' . ($interval->y > 1 ? 's' : '');
|
|
} elseif ($interval->m > 0) {
|
|
$relative_time = 'il y a ' . $interval->m . ' mois';
|
|
} else {
|
|
$relative_time = 'il y a ' . $interval->d . ' jour' . ($interval->d > 1 ? 's' : '');
|
|
}
|
|
|
|
return $relative_time;
|
|
}
|