43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
class Ramais_Ajax {
|
|
private $database;
|
|
|
|
public function __construct($database) {
|
|
$this->database = $database;
|
|
$this->init_hooks();
|
|
}
|
|
|
|
private function init_hooks() {
|
|
add_action('wp_ajax_filtrar_ramais', array($this, 'ajax_filter_ramais'));
|
|
add_action('wp_ajax_nopriv_filtrar_ramais', array($this, 'ajax_filter_ramais'));
|
|
}
|
|
|
|
public function ajax_filter_ramais() {
|
|
check_ajax_referer('ramais_telefonicos_nonce', 'nonce');
|
|
|
|
$page = isset($_POST['page']) ? absint($_POST['page']) : 1;
|
|
$filters = [
|
|
'search' => isset($_POST['search']) ? sanitize_text_field($_POST['search']) : '',
|
|
'secretaria' => isset($_POST['secretaria']) ? sanitize_text_field($_POST['secretaria']) : '',
|
|
'setor' => isset($_POST['setor']) ? sanitize_text_field($_POST['setor']) : ''
|
|
];
|
|
|
|
$data = $this->database->get_filtered_ramais($filters, $page);
|
|
$ramais = $data['data'];
|
|
$total_pages = $data['pages'];
|
|
$current_page = $data['current_page'];
|
|
|
|
// Indica que é apenas a seção de resultados
|
|
$is_results_section = true;
|
|
|
|
ob_start();
|
|
include RAMAIS_TELEFONICOS_PLUGIN_DIR . 'templates/lista-ramais.php';
|
|
$html = ob_get_clean();
|
|
|
|
wp_send_json_success($html);
|
|
}
|
|
} |