Добавлено логирование сортировки для отладки

This commit is contained in:
Mikhail Chusavitin
2026-01-22 11:14:46 +03:00
parent 198571ecf5
commit 1d4bb980c0
2 changed files with 17 additions and 6 deletions

View File

@@ -103,7 +103,7 @@ $app->post('/api/table/data', function (Request $request, Response $response) us
$columns = $payload['columns'] ?? [];
// ✅ Логирование для отладки
error_log("Data request: page=$page, pageSize=$pageSize, filters=" . json_encode($filters));
error_log("Data request: page=$page, pageSize=$pageSize, filters=" . json_encode($filters) . ", sort=" . json_encode($sort));
$pdo = $container->get('db');
$ds = new \App\DataService($pdo);

View File

@@ -37,12 +37,22 @@ class DataService
$whereSql = $whereParts ? 'WHERE ' . implode(' AND ', $whereParts) : '';
$orderSql = '';
if ($sort && !empty($sort['field']) && in_array($sort['field'], $colNames, true)) {
$dir = strtoupper($sort['dir'] ?? 'ASC');
if (!in_array($dir, ['ASC', 'DESC'], true)) {
$dir = 'ASC';
error_log("=== SORT DEBUG (fetchData) ===");
error_log("Sort param: " . json_encode($sort));
error_log("Column names: " . implode(', ', array_slice($colNames, 0, 5)) . "...");
if ($sort && !empty($sort['field'])) {
$fieldExists = in_array($sort['field'], $colNames, true);
error_log("Field '{$sort['field']}' exists: " . ($fieldExists ? 'YES' : 'NO'));
if ($fieldExists) {
$dir = strtoupper($sort['dir'] ?? 'ASC');
if (!in_array($dir, ['ASC', 'DESC'], true)) {
$dir = 'ASC';
}
$orderSql = "ORDER BY `{$sort['field']}` $dir";
error_log("ORDER SQL: $orderSql");
}
$orderSql = "ORDER BY `{$sort['field']}` $dir";
} else {
error_log("No sort applied");
}
$sql = "SELECT $selectList
@@ -50,6 +60,7 @@ class DataService
$whereSql
$orderSql
LIMIT :limit OFFSET :offset";
error_log("Final SQL: " . preg_replace('/\s+/', ' ', $sql));
$stmt = $this->pdo->prepare($sql);
foreach ($params as $k => $v) {