Guía para integrar con WP_List_Table
Cuando ejecutas un informe con SDL Bridge:
$result = SDLBridge::report('mi_informe')->execute();
La variable $result es un objeto estándar con estas propiedades:
| Propiedad | Tipo | Descripción |
|---|---|---|
->rows |
array |
Datos del informe: array de filas, cada fila es un array asociativo. |
->sql |
string |
Consulta SQL generada (solo para debugging). |
->metadata |
array |
Metadatos del informe (si se definen en el .sdl). |
->rowsSi tu consulta SDL es:
SELECT product_id, product_name, total_views
FROM ...
Entonces $result->rows será:
[
['product_id' => 101, 'product_name' => 'Camiseta', 'total_views' => 42],
['product_id' => 102, 'product_name' => 'Pantalón', 'total_views' => 28],
// ...
]
Cada fila es un array asociativo con claves = nombres de columna del SELECT.
WP_List_TableEn tu clase que extiende WP_List_Table:
class Mi_Reporte_Table extends WP_List_Table
{
private $data;
public function __construct() {
parent::__construct(['singular' => 'reporte', 'plural' => 'reportes']);
// Ejecutar el informe una vez
$result = SDLBridge::report('mi_informe')->execute();
$this->data = $result->rows;
}
public function prepare_items() {
$columns = $this->get_columns();
$hidden = [];
$sortable = $this->get_sortable_columns();
$this->_column_headers = [$columns, $hidden, $sortable];
$this->items = $this->data; // ← ¡Así de simple!
}
public function get_columns() {
return [
'product_id' => 'ID',
'product_name' => 'Producto',
'total_views' => 'Vistas'
];
}
// Métodos column_... según WP_List_Table
public function column_product_name($item) {
return esc_html($item['product_name']);
}
}
SELECT (ej: tasa_abandono_por_producto_pct).column_product_name),LIMIT y OFFSET en tu SDL (con variables {{limit:int}}, {{offset:int}}).SELECT COUNT(*) ...).Archivo: ventas.sdl
SELECT order_id, customer, total
FROM wp_orders
ORDER BY order_id
LIMIT {{limit:int}} OFFSET {{offset:int}}
En PHP:
$page = $_GET['paged'] ?? 1;
$limit = 20;
$offset = ($page - 1) * $limit;
$result = SDLBridge::report('ventas')
->withParams(['limit' => $limit, 'offset' => $offset])
->execute();
$result->rows = array listo para $this->items.WP_List_Table.