['document', 'competitor_data']]); [$page, $limit] = pageParams(); $keyword = trim($_REQUEST['keyword'] ?? ''); $fileType = trim($_REQUEST['file_type'] ?? ''); $active = isset($_REQUEST['is_active']) && $_REQUEST['is_active'] !== '' ? (int)$_REQUEST['is_active'] : null; $where = ['is_active = 1']; $params = []; if ($active !== null) { $where = ['is_active = ?']; $params = [$active]; } if ($keyword !== '') { $where[] = '(doc_name LIKE ? OR document_source LIKE ?)'; $like = "%$keyword%"; array_push($params, $like, $like); } if ($fileType !== '') { $where[] = 'file_type = ?'; $params[] = $fileType; } $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->getPdo(); $stmt = $pdo->prepare("SELECT COUNT(*) FROM company_documents WHERE $whereSql"); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT id, doc_name, storage_path, file_type, is_current, publish_date, document_source, tags, is_active, created_at FROM company_documents WHERE $whereSql ORDER BY id DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);