Compare commits

...

10 Commits

Author SHA1 Message Date
b12d138bb8 responsive tweaks
All checks were successful
continuous-integration/drone/push Build is passing
2024-12-18 11:18:30 +01:00
47a005e094 adding formatVat and GetConseillerName functions 2024-12-18 11:16:17 +01:00
66da510aa5 styling custom columns and data export page 2024-12-18 11:15:38 +01:00
64da1c65dd handling custom columns 2024-12-18 11:15:04 +01:00
10ae3a6f99 add revisions in the supports array for post type artisans 2024-12-18 11:14:44 +01:00
08d3c0239f introducing export module 2024-12-18 11:14:19 +01:00
932287ff60 introducing export module 2024-12-18 11:14:13 +01:00
db9d6671d8 conditionnal no-found post-components if no post found 2024-12-18 11:13:46 +01:00
8dc45e970e fixing cover not showing 2024-12-18 11:12:43 +01:00
4d52a36fed fixing namespace 2024-12-17 18:33:36 +01:00
12 changed files with 450 additions and 30 deletions

View File

@ -14,3 +14,4 @@ require_once(__DIR__ . '/includes/blocks.php');
require_once(__DIR__ . '/includes/utilities.php');
require_once(__DIR__ . '/includes/acf-fields.php');
require_once(__DIR__ . '/includes/factories.php');
require_once(__DIR__ . '/includes/export-datas.php');

View File

@ -49,7 +49,7 @@ CUSTOM POST STATUS
function custom_post_status()
{
register_post_status('offline', array(
'label' => _x('offline', 'post'),
'label' => __('offline', 'metiers-patrimoine-theme'),
'public' => true,
'exclude_from_search' => false,
'show_in_admin_all_list' => true,
@ -159,8 +159,9 @@ function metiers_new_admin_menu_order($menu_order)
$new_positions = array(
'edit.php?post_type=artisans' => 3,
'edit.php?post_type=chantiers' => 4,
'edit.php?post_type=page' => 5,
'edit.php?post_type=page' => 6,
'upload.php' => 7,
'export_datas' => 8,
'theme-general-settings' => 11,
'rank-math' => 20,
);

View File

@ -30,7 +30,6 @@ function build_search_artisan_posts_cards($request)
$StringifiedTaxonomyIds = esc_html($request->get_param('taxonomy-ids')) ?? null;
do_action('wpml_switch_language', $currentLanguage);
$test = __("Aucun résultat trouvé", "metiers-patrimoine-theme");
$lang = apply_filters('wpml_current_language', null);
$taxonomyIds = explode(',', $StringifiedTaxonomyIds);
$taxonomyIds = array_map('intval', $taxonomyIds);
@ -94,15 +93,15 @@ function build_search_artisan_posts_cards($request)
$html_template = ob_get_clean();
ob_start();
get_template_part(
'template-components/artisans/artisan-search-no-results',
null,
[]
);
$html_template = ob_get_clean();
if ($newsPostsDatas->found_posts === 0) {
ob_start();
get_template_part(
'template-components/artisans/artisan-search-no-results',
null,
[]
);
$html_template = ob_get_clean();
}
$response_data = array(
'html_template' => $html_template,
@ -147,7 +146,6 @@ function debugQueryTest()
);
$html_template = ob_get_clean();
$test = __("Aucun résultat trouvé", "metiers-patrimoine-theme");
// write_log($test);
return ($html_template);
}
// debugQueryTest();

View File

@ -124,3 +124,122 @@ function render_custom_chantier_box_content($post)
echo '<a href="' . admin_url('post-new.php?post_type=chantiers') . '" class="new-chantier">Ajouter un chantier</a>';
}
}
/* ----------------------------------------------------------------------
GESTION DE LA COLONNE METIERS DANS LA LISTE DES POSTS ARTISANS
------------------------------------------------------------------------*/
// AJOUT D'UNE COLONNE CUSTOM
function metiers_patrimoine_artisans_add_acf_posts_columns($columns)
{
global $current_screen;
// SUPPRIMER LA COLONNE 'date'
if (isset($columns['date'])) {
unset($columns['date']);
}
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + array('metiers' => 'Métiers') + array_slice($columns, 2, count($columns) - 2, true);
return array_merge($new_admin_col_arrays);
}
add_filter('manage_artisans_posts_columns', 'metiers_patrimoine_artisans_add_acf_posts_columns');
/* ----------------------------------------------------------------------
GESTION DE LA VALEUR DE CHAQUE COLONNE
------------------------------------------------------------------------*/
function metiers_patrimoine_artisans_handle_posts_custom_columns($column)
{
$post_id = get_the_ID();
if ($column == 'metiers') {
$artisan = get_field('artisan', $post_id);
$terms = get_the_terms($post_id, 'metiers');
if ($terms) {
$parent_terms = array_filter($terms, function ($term) {
return $term->parent == 0;
});
// if (empty($parent_terms)) {
// echo '<p class="no-results">Aucun métier parent</p>';
// return;
// }
echo '<div class="admin-column-metiers-container">';
foreach ($terms as $term) {
// write_log($term);
echo '<a href="' . get_edit_term_link($term->term_id, 'metiers', 'artisans') . '" class="admin-column-taxonomy-term">';
echo esc_html($term->name);
echo '</a>';
}
echo '</div >';
} else {
echo '<p class="no-results"> × </p>';
}
}
}
add_action('manage_artisans_posts_custom_column', 'metiers_patrimoine_artisans_handle_posts_custom_columns', 10, 2);
/* -------------------------------------------
CREATION DU DROPDOWN SELECT AVEC LES OPTIONS
---------------------------------------------*/
function metiers_patrimoine_filter_posts_per_metiers_declare_dropdown()
{
global $pagenow;
$post_type = (isset($_GET['post_type'])) ? $_GET['post_type'] : 'post';
//only add filter to post type you want
if ($post_type == 'artisans') {
$metiers_by_parent = getAllMetiersTermsByParents();
?>
<select name="metiers">
<option value=""><?php _e('Filtrer par Métier', 'metiers-patrimoine-theme'); ?></option>
<?php
$current_v = isset($_GET['metiers']) ? $_GET['metiers'] : '';
foreach ($metiers_by_parent as $index => $parent_term_data) {
$parent_term = $parent_term_data['term'];
printf(
'<option value="%s"%s>%s</option>',
$parent_term->slug,
$parent_term->slug == $current_v ? ' selected="selected"' : '',
$parent_term->name
);
}
?>
</select>
<?php
}
}
add_action('restrict_manage_posts', 'metiers_patrimoine_filter_posts_per_metiers_declare_dropdown');
/* ------------------------------------------------------
FILTRAGE DES POSTS QUAND LA QUERY DE FILTER EST ENVOYEE
--------------------------------------------------------*/
function metiers_patrimoine_filter_post_by_metiers_query($query)
{
global $pagenow;
$type = 'artisans'; // change to custom post name.
if (isset($_GET['post_type'])) {
$type = $_GET['post_type'];
}
if (($type === 'artisans') && is_admin() && $pagenow == 'edit.php' && isset($_GET['metiers']) && $_GET['metiers'] != '') {
$query->query_vars['tax_query'] = array(
array(
'taxonomy' => 'metiers',
'field' => 'slug',
'terms' => $_GET['metiers'],
'include_children' => true,
),
);
}
}
add_filter('parse_query', 'metiers_patrimoine_filter_post_by_metiers_query');

View File

@ -1,8 +1,8 @@
<?php
/* ---------------------------
EDIT ARTISAN LINK
---------------------------*/
/* -----------------------------------------
EDIT ARTISAN LINK ON CHANTIER EDIT PAGE
-----------------------------------------*/
add_action('acf/render_field', function ($field) {
// Vérifiez si le champ est celui que vous voulez personnaliser
@ -20,3 +20,74 @@ add_action('acf/render_field', function ($field) {
}
}
}, 10, 1);
/* ----------------------------------------------------------------------
GESTION DE LA COLONNE ARTISAN DANS LA LISTE DES POSTS CHANTIERS
------------------------------------------------------------------------*/
// AJOUT D'UNE COLONNE CUSTOM
function metiers_patrimoine_add_acf_posts_columns($columns)
{
global $current_screen;
// SUPPRIMER LA COLONNE 'date'
if (isset($columns['date'])) {
unset($columns['date']);
}
$new_admin_col_arrays = array_slice($columns, 0, 2, true) + array('artisan' => 'Artisan') + array('date_chantier' => 'Date chantier') + array_slice($columns, 2, count($columns) - 2, true);
return array_merge($new_admin_col_arrays);
}
add_filter('manage_chantiers_posts_columns', 'metiers_patrimoine_add_acf_posts_columns');
/* ----------------------------------------------------------------------
GESTION DE LA VALEUR DE CHAQUE COLONNE
------------------------------------------------------------------------*/
function metiers_patrimoine_handle_posts_custom_columns($column)
{
$post_id = get_the_ID();
if ($column == 'artisan') {
$artisan = get_field('artisan', $post_id);
if ($artisan) {
$edit_link = esc_url(get_edit_post_link($artisan->ID));
echo '<a href="' . $edit_link . '">';
echo esc_html($artisan->post_title);
echo '</a>';
}
}
if ($column == 'date_chantier') {
$date_chantier = get_field('date', $post_id);
echo '<p>' . $date_chantier . '</p>';
}
}
add_action('manage_chantiers_posts_custom_column', 'metiers_patrimoine_handle_posts_custom_columns', 10, 2);
function metiers_patrimoine_sortable_columns($columns)
{
$columns['date_chantier'] = 'date_chantier';
return $columns;
}
add_filter('manage_edit-chantiers_sortable_columns', 'metiers_patrimoine_sortable_columns');
function metiers_patrimoine_orderby($query)
{
if (!is_admin()) {
return;
}
$orderby = $query->get('orderby');
if ('date_chantier' == $orderby) {
$query->set('meta_key', 'date');
$query->set('orderby', 'meta_value');
}
}
add_action('pre_get_posts', 'metiers_patrimoine_orderby');

145
includes/export-datas.php Normal file
View File

@ -0,0 +1,145 @@
<?php
add_action('admin_menu', 'export_datas_page_in_menu');
function export_datas_page_in_menu()
{
add_menu_page(
'Export de données', // page <title>Title</title>
'Export', // link text
'manage_options', // user capabilities
'export_datas', // page slug
'export_datas_page_callback', // this function prints the page content
'dashicons-external', // icon (from Dashicons for example)
12 // menu position
);
}
function export_datas_page_callback()
{
?>
<div class="wrap ">
<h1>Exports de données</h1>
<div class="metiers-patrimoine-data-exports-page">
<div class="card export-card">
<h2>Export des artisans</h2>
<img class="export-card__illustration" src="<?php echo get_template_directory_uri() . '/resources/img/illustrations/homegrade_formations-peb.svg' ?>" alt="">
<p> Exporter les données des artisans au format CSV. </p>
<form method="post" action="<?php echo admin_url('admin-post.php'); ?>">
<input type="hidden" name="action" value="export_artisans_datas">
<?php wp_nonce_field('export_artisans_datas_nonce', 'export_artisans_datas_nonce'); ?>
<button type="submit" name="custom_action_button" class="button cta--primary">
<?php echo __("Exporter les artisans", "metiers-patrimoine-theme"); ?>
</button>
</form>
</div>
</div>
</div>
<?php
}
add_action('admin_post_export_artisans_datas', 'metiers_handle_download_artisans_request');
function metiers_handle_download_artisans_request()
{
// Vérifier la nonce pour des raisons de sécurité
if (!isset($_POST['export_artisans_datas_nonce']) || !wp_verify_nonce($_POST['export_artisans_datas_nonce'], 'export_artisans_datas_nonce')) {
wp_die('Vérification de sécurité échouée.');
}
// Vérifier les capacités de l'utilisateur
if (!current_user_can('read')) {
wp_die('Permissions insuffisantes.');
}
generate_artisans_datas_to_csv();
exit;
}
function generate_artisans_datas_to_csv()
{
do_action('wpml_switch_language', 'fr');
// Récupérer tous les posts du type "artisans"
$args = array(
'post_type' => 'artisans',
'posts_per_page' => -1, // Récupérer tous les posts
'post_status' => 'publish',
);
$artisans = new WP_Query($args);
// Vérifier si des posts ont été trouvés
if (empty($artisans)) {
wp_die('Aucun post trouvé pour le type "artisans".');
}
// Définir le nom du fichier CSV
$filename = 'artisans_data_' . date('Ymd_His') . '.csv';
// Ouvrir un fichier CSV en mode écriture
$file = fopen($filename, 'w');
if ($file === false) {
wp_die('Erreur lors de la création du fichier CSV.');
}
// Ajouter les en-têtes du CSV
fputcsv($file, ['Artisan', 'N° Téléphone', 'Mail', 'Adresse', 'Site web', 'TVA', 'Conseiller', 'Action requise', 'Précision pour contact', 'ID de l\'artisan', 'Date de création',]);
// Boucler sur chaque post et écrire les données dans le CSV
foreach ($artisans->posts as $artisan) {
$postID = $artisan->ID;
$phoneNumber = get_field('phone_number', $postID);
$formattedPhoneNumber = preg_replace('/^(\+\d{2})(\d{3})(\d{2})(\d{2})(\d{2})$/', '$1 $2 $3 $4 $5', $phoneNumber);
$email = get_field('email', $postID);
$website = get_field('website', $postID);
$vat_number = get_field('vat_number', $postID);
$tva = $vat_number ? format_belgian_vat_number($vat_number) : '';
$adresseDatas = get_field('adresse', $postID);
$street_number = isset($adresseDatas['street_number']) ? $adresseDatas['street_number'] . ' ' : '';
$street_name = isset($adresseDatas['street_name']) ? $adresseDatas['street_name'] . ', ' : '';
$post_code = isset($adresseDatas['post_code']) ? $adresseDatas['post_code'] . ' ' : '';
$city = isset($adresseDatas['city']) ? $adresseDatas['city'] : '';
$adresse = $street_number . $street_name . $post_code . ' ' . $city;
$conseiller = getArtisanConseillerName($postID) ?? '';
$requiredAction = get_field('required_action', $postID);
$requiredAction = $requiredAction ? 'Oui' : '';
$contactComments = get_field('contact_comments', $postID);
fputcsv($file, [
$artisan->post_title,
$formattedPhoneNumber,
$email,
$adresse,
$website,
$tva,
$conseiller,
$requiredAction,
$contactComments,
$artisan->ID,
$artisan->post_date,
]);
}
// Fermer le fichier
fclose($file);
// Télécharger le fichier CSV
header('Content-Type: text/csv');
header('Content-Disposition: attachment;filename="' . $filename . '"');
readfile($filename);
// Supprimer le fichier après téléchargement
unlink($filename);
exit();
}

View File

@ -19,7 +19,7 @@ function metiers_patrimoine_create_posttype()
'menu_icon' => 'data:image/svg+xml;base64,' . base64_encode('<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512" fill="currentColor"><!--!Font Awesome Free 6.5.2 by @fontawesome - https://fontawesome.com License - https://fontawesome.com/license/free Copyright 2024 Fonticons, Inc.--><path d="M72 88a56 56 0 1 1 112 0A56 56 0 1 1 72 88zM64 245.7C54 256.9 48 271.8 48 288s6 31.1 16 42.3V245.7zm144.4-49.3C178.7 222.7 160 261.2 160 304c0 34.3 12 65.8 32 90.5V416c0 17.7-14.3 32-32 32H96c-17.7 0-32-14.3-32-32V389.2C26.2 371.2 0 332.7 0 288c0-61.9 50.1-112 112-112h32c24 0 46.2 7.5 64.4 20.3zM448 416V394.5c20-24.7 32-56.2 32-90.5c0-42.8-18.7-81.3-48.4-107.7C449.8 183.5 472 176 496 176h32c61.9 0 112 50.1 112 112c0 44.7-26.2 83.2-64 101.2V416c0 17.7-14.3 32-32 32H480c-17.7 0-32-14.3-32-32zm8-328a56 56 0 1 1 112 0A56 56 0 1 1 456 88zM576 245.7v84.7c10-11.3 16-26.1 16-42.3s-6-31.1-16-42.3zM320 32a64 64 0 1 1 0 128 64 64 0 1 1 0-128zM240 304c0 16.2 6 31 16 42.3V261.7c-10 11.3-16 26.1-16 42.3zm144-42.3v84.7c10-11.3 16-26.1 16-42.3s-6-31.1-16-42.3zM448 304c0 44.7-26.2 83.2-64 101.2V448c0 17.7-14.3 32-32 32H288c-17.7 0-32-14.3-32-32V405.2c-37.8-18-64-56.5-64-101.2c0-61.9 50.1-112 112-112h32c61.9 0 112 50.1 112 112z"/></svg>'),
// 'menu_icon' => 'dashicons-hammer',
'menu_position' => 5.1,
'supports' => array('title', 'custom-fields', 'thumbnail'),
'supports' => array('title', 'custom-fields', 'thumbnail', 'revisions'),
)
);
// **** CHANTIERS

View File

@ -148,3 +148,31 @@ function getGenericStateNameFromAcfStateName($state)
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;
}

View File

@ -1,4 +1,5 @@
@import './base/filters.css';
@import './base/shadows.css';
body.post-type-chantiers,
body.post-type-artisans {
@ -316,3 +317,64 @@ ul.striped > :nth-child(odd) {
@apply !text-neutral-500;
}
}
/* #icl_translations,
.column-icl_translations {
width: 60px;
} */
.admin-column-metiers-container {
@apply flex flex-wrap;
}
.admin-column-taxonomy-term {
@apply bg-patrimoine-sante-securite-light text-patrimoine-sante-securite
!font-normal !text-xs rounded-md block w-fit !px-2 !py-1;
&:hover {
@apply text-purple-900;
}
}
.admin-column-metiers-container {
@apply flex flex-wrap gap-2;
}
.column-metiers .no-results {
@apply text-neutral-400;
}
#rank-math-seo-filter {
@apply hidden;
}
/* .tablenav select[name='metiers'] {
@apply text-patrimoine-sante-securite bg-patrimoine-sante-securite-light;
} */
.button-primary {
@apply bg-patrimoine-sante-securite text-white;
}
.metiers-patrimoine-data-exports-page {
@apply grid sm:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4;
.export-card {
@apply !rounded-lg border-none
flex flex-col items-center justify-center !p-8
gap-8 text-center col-span-2 shadowed;
max-width: unset;
h2 {
@apply !m-0 text-patrimoine-sante-securite max-w-md leading-5 pb-2;
}
&__illustration {
max-width: 200px;
filter: hue-rotate(-100deg);
}
}
.cta--primary {
@apply bg-patrimoine-sante-securite text-white border-purple-800 rounded-full;
&:hover {
@apply bg-purple-900 text-white;
}
}
}

View File

@ -30,7 +30,7 @@
@apply pb-12;
} */
.metier-patrimoine-searchbar {
@apply w-80 lg:w-80 shrink-0 h-fit sticky top-0;
@apply md:w-80 shrink-0 h-fit md:sticky top-0;
.posts-results-count {
@apply shrink-0;
}
@ -179,10 +179,7 @@
&__geographic-filters {
@apply hidden;
}
&:has(
#elements_batiments_checkbox:checked,
#metiers_checkbox:checked
) {
&:has(#elements_batiments_checkbox:checked, #metiers_checkbox:checked) {
.metier-patrimoine-searchbar__geographic-filters {
@apply block;
}
@ -193,10 +190,7 @@
@apply hidden;
}
/* HIDE METIERS FILTERS WHEN SEARCH IS ON ELEMENTS BATIMENTS */
&:has(
.metier-patrimoine-searchbar__search-by
#elements_batiments_checkbox:checked
) {
&:has(.metier-patrimoine-searchbar__search-by #elements_batiments_checkbox:checked) {
.metier-patrimoine-searchbar__elements-batiments-filters {
@apply block;
/* @apply opacity-40; */
@ -209,10 +203,7 @@
/* HIDE ELEMENTS BATIMENTS FILTERS WHEN SEARCH IS ON METIERS */
&:has(
.metier-patrimoine-searchbar__search-by
#metiers_checkbox:checked
) {
&:has(.metier-patrimoine-searchbar__search-by #metiers_checkbox:checked) {
.metier-patrimoine-searchbar__metiers-filters {
@apply block;
/* @apply opacity-40; */

View File

@ -1,7 +1,8 @@
<?php
?>
<div class='no-results'><img class='no-results__cover' src=" <?php get_stylesheet_directory_uri() . "/resources/img/illustrations/Homegrade_resultats-filtres-cactus.svg" ?>" alt='' />
<div class='no-results'>
<img class='no-results__cover' src="<?php echo get_stylesheet_directory_uri() . "/resources/img/illustrations/Homegrade_resultats-filtres-cactus.svg" ?>" alt='' />
<h3><?php echo __("Aucun résultat trouvé", "metiers-patrimoine-theme") ?> </h3>
<p> <?php echo __("Essayez d'ajouter un <span class='highlighted-purple'>filtre supplémentaire</span> pour trouver plus de résultats", "metiers-patrimoine-theme") ?></p>
</div>

View File

@ -53,12 +53,15 @@
}
&__website {
@apply text-primary underline font-semibold underline-offset-4 inline-flex w-full;
@apply text-primary underline font-semibold underline-offset-4 !flex w-full;
&:before {
@apply inline-flex mr-3 h-6 w-6 bg-center bg-contain bg-no-repeat;
content: '';
background-image: url('../resources/img/pictogrammes/Homegrade_repertoire-site.svg');
}
&:after {
@apply !transform-none;
}
}
.cta--read-more {