correctifs presences
This commit is contained in:
parent
7c426d892d
commit
75bff25eb0
@ -79,6 +79,15 @@ class CRVI_Beneficiaire_Controller {
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// Endpoint pour rechercher des bénéficiaires par nom/prénom
|
||||||
|
register_rest_route('crvi/v1', '/beneficiaires/search', [
|
||||||
|
[
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => [self::class, 'search_beneficiaires'],
|
||||||
|
'permission_callback' => '__return_true',
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
register_rest_route('crvi/v1', '/beneficiaires/(?P<id>\\d+)', [
|
register_rest_route('crvi/v1', '/beneficiaires/(?P<id>\\d+)', [
|
||||||
[
|
[
|
||||||
'methods' => 'GET',
|
'methods' => 'GET',
|
||||||
@ -122,6 +131,61 @@ class CRVI_Beneficiaire_Controller {
|
|||||||
return Api_Helper::json_success($items);
|
return Api_Helper::json_success($items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Recherche de bénéficiaires par nom ou prénom
|
||||||
|
* GET /wp-json/crvi/v1/beneficiaires/search?search=durand
|
||||||
|
*/
|
||||||
|
public static function search_beneficiaires($request) {
|
||||||
|
$search = $request->get_param('search');
|
||||||
|
|
||||||
|
if (empty($search) || strlen($search) < 3) {
|
||||||
|
return Api_Helper::json_success([]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Rechercher les bénéficiaires par nom ou prénom
|
||||||
|
$args = [
|
||||||
|
'post_type' => 'beneficiaire',
|
||||||
|
'posts_per_page' => 20,
|
||||||
|
'post_status' => 'publish',
|
||||||
|
'meta_query' => [
|
||||||
|
'relation' => 'OR',
|
||||||
|
[
|
||||||
|
'key' => 'nom',
|
||||||
|
'value' => $search,
|
||||||
|
'compare' => 'LIKE'
|
||||||
|
],
|
||||||
|
[
|
||||||
|
'key' => 'prenom',
|
||||||
|
'value' => $search,
|
||||||
|
'compare' => 'LIKE'
|
||||||
|
]
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
$query = new \WP_Query($args);
|
||||||
|
$results = [];
|
||||||
|
|
||||||
|
if ($query->have_posts()) {
|
||||||
|
while ($query->have_posts()) {
|
||||||
|
$query->the_post();
|
||||||
|
$post_id = get_the_ID();
|
||||||
|
|
||||||
|
$nom = get_post_meta($post_id, 'nom', true);
|
||||||
|
$prenom = get_post_meta($post_id, 'prenom', true);
|
||||||
|
|
||||||
|
$results[] = [
|
||||||
|
'id' => $post_id,
|
||||||
|
'nom' => $nom,
|
||||||
|
'prenom' => $prenom,
|
||||||
|
'nom_complet' => trim($prenom . ' ' . $nom)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
wp_reset_postdata();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Api_Helper::json_success($results);
|
||||||
|
}
|
||||||
|
|
||||||
public static function get_item($request) {
|
public static function get_item($request) {
|
||||||
$id = (int) $request['id'];
|
$id = (int) $request['id'];
|
||||||
$item = CRVI_Beneficiaire_Model::load($id);
|
$item = CRVI_Beneficiaire_Model::load($id);
|
||||||
|
|||||||
@ -558,7 +558,7 @@ export function openCheckPresenceModal(eventData) {
|
|||||||
const row = document.createElement('tr');
|
const row = document.createElement('tr');
|
||||||
row.innerHTML = `
|
row.innerHTML = `
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" class="form-check-input" id="presence_${i}" name="presences[${i}][is_present]" checked>
|
<input type="checkbox" class="form-check-input" id="presence_${i}" name="presences[${i}][is_present]">
|
||||||
</td>
|
</td>
|
||||||
<td style="position: relative;">
|
<td style="position: relative;">
|
||||||
<input type="text" class="form-control presence-nom-input" id="presence_nom_${i}" name="presences[${i}][nom]"
|
<input type="text" class="form-control presence-nom-input" id="presence_nom_${i}" name="presences[${i}][nom]"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user