refactoring queries and display to handle extra informations in colulmns

This commit is contained in:
Antoine M 2025-03-04 16:18:19 +01:00
parent 58876d018c
commit 06ca902b9f

View File

@ -19,37 +19,40 @@ $current_user_id = $args['current_user_id'] ?? null;
$not_found_message = $args['not_found_message'] ?? "";
$queryArgsWithStatus = array(
$queryAllUnaffectedArtisansByStatus = array(
'post_type' => 'artisans',
'posts_per_page' => -1,
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'mdp_status',
'value' => $status,
'compare' => '='
),
array(
'key' => 'conseiller',
'compare' => 'NOT EXISTS'
)
)
);
$queryConseillerRelatedArtisansByStatus = array(
'post_type' => 'artisans',
'posts_per_page' => -1,
'meta_key' => 'conseiller',
'meta_value' => $current_user_id,
'meta_query' => array(
array(
'key' => 'mdp_status',
'value' => $status,
'compare' => '='
)
)
);
$queryArgsActionRequired = array(
'post_type' => 'artisans',
'posts_per_page' => -1,
'meta_query' => array(
array(
'key' => 'required_action',
'value' => true,
'compare' => '='
)
),
)
);
$currentQueryArgs = $status ? $queryArgsWithStatus : $queryArgsActionRequired;
if ($use_current_user && $current_user_id) {
$currentQueryArgs['meta_value'] = $current_user_id;
$currentQueryArgs['meta_key'] = 'conseiller';
}
$currentQueryArgs = ($use_current_user && $current_user_id) ? $queryConseillerRelatedArtisansByStatus : $queryAllUnaffectedArtisansByStatus;
$artisans = new WP_Query($currentQueryArgs);
@ -61,13 +64,37 @@ $artisans = new WP_Query($currentQueryArgs);
<?php if ($artisans->found_posts === 0) : ?>
<p class="group-artisans__no-results"><?php echo $not_found_message ?></p>
<?php else : ?>
<li class="list-titles">
<p>Nom</p>
<p>Dernière action</p>
<p>Commentaire</p>
<p>Statut</p>
</li>
<?php foreach ($artisans->posts as $artisan) : ?>
<?php $mdp_status = get_field('mdp_status', $artisan->ID); ?>
<?php
$mdp_status = get_field('mdp_status', $artisan->ID);
$last_contact = get_field('last_action', $artisan->ID);
$last_contact_date = isset($last_contact['last_contact_date']) ? $last_contact['last_contact_date'] : null;
$last_contact_comment = isset($last_contact['comments']) ? $last_contact['comments'] : null;
if ($last_contact_date) {
$formatted_date = getFrenchDateFromTimestamp($last_contact_date);
$relative_time = getRelativeTimeFromTimestamp($last_contact_date);
$last_contact_date = $relative_time . ' (' . $formatted_date . ')';
} else {
$last_contact_date = null;
}
?>
<li class="group-artisans__list__item">
<a href="<?php echo get_edit_post_link($artisan->ID) ?>"><?php echo $artisan->post_title ?></a>
<?php if ($mdp_status) : ?>
<span class="status-state status-state--<?php echo $mdp_status['value'] ?>"><?php echo $mdp_status['label'] ?></span>
<?php endif; ?>
<a class="post-link" href="<?php echo get_edit_post_link($artisan->ID) ?>"><?php echo $artisan->post_title ?></a>
<span class="last-contact-date"> <?php echo $last_contact_date ?></span>
<span class="last-contact-comment"><?php echo $last_contact_comment ?></span>
<span class="status-state status-state--<?php echo $mdp_status['value'] ?>"><?php echo $mdp_status['label'] ?></span>
</li>
<?php endforeach; ?>
<?php endif; ?>