116 lines
3.5 KiB
PHP
116 lines
3.5 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Template part pour afficher une section d'artisans
|
|
*
|
|
* @param string $status - Le statut des artisans à afficher
|
|
* @param string $title - Le titre de la section
|
|
* @param int $current_user_id - L'ID de l'utilisateur courant
|
|
* @param array $additional_query - Paramètres de requête supplémentaires (optionnel)
|
|
*/
|
|
|
|
|
|
|
|
$status_class = $args['status_class'] ?? "";
|
|
$status = $args['status'] ?? null;
|
|
$title = $args['title'] ?? "";
|
|
$use_current_user = $args['use_current_user'] ?? false;
|
|
$current_user_id = $args['current_user_id'] ?? null;
|
|
$not_found_message = $args['not_found_message'] ?? "";
|
|
|
|
|
|
$queryAllUnaffectedArtisansByStatus = array(
|
|
'post_type' => 'artisans',
|
|
'posts_per_page' => -1,
|
|
'post_status' => array('publish', 'offline'),
|
|
'meta_query' => array(
|
|
'relation' => 'AND',
|
|
array(
|
|
'key' => 'mdp_status',
|
|
'value' => $status,
|
|
'compare' => '='
|
|
),
|
|
array(
|
|
'relation' => 'OR',
|
|
array(
|
|
'key' => 'conseiller',
|
|
'compare' => 'NOT EXISTS'
|
|
),
|
|
array(
|
|
'key' => 'conseiller',
|
|
'value' => '',
|
|
'compare' => '='
|
|
)
|
|
)
|
|
),
|
|
'orderby' => 'title',
|
|
'order' => 'ASC'
|
|
);
|
|
|
|
$queryConseillerRelatedArtisansByStatus = array(
|
|
'post_type' => 'artisans',
|
|
'posts_per_page' => -1,
|
|
'post_status' => array('publish', 'offline'),
|
|
'meta_key' => 'conseiller',
|
|
'meta_value' => $current_user_id,
|
|
'meta_query' => array(
|
|
array(
|
|
'key' => 'mdp_status',
|
|
'value' => $status,
|
|
'compare' => '='
|
|
),
|
|
),
|
|
'orderby' => 'title',
|
|
'order' => 'ASC'
|
|
);
|
|
|
|
|
|
|
|
$currentQueryArgs = ($use_current_user && $current_user_id) ? $queryConseillerRelatedArtisansByStatus : $queryAllUnaffectedArtisansByStatus;
|
|
|
|
$artisans = new WP_Query($currentQueryArgs);
|
|
|
|
?>
|
|
|
|
<div class="group-artisans group-artisans--<?php echo $status_class ?>">
|
|
<h3 class="group-artisans__title"><?php echo $title ?> <span class="group-artisans__post-count">(<?php echo $artisans->found_posts ?>)</span></h3>
|
|
<ul class="group-artisans__list">
|
|
<?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 de travail</p>
|
|
</li>
|
|
<?php foreach ($artisans->posts as $artisan) : ?>
|
|
<?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 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; ?>
|
|
</ul>
|
|
</div>
|