Add pagination support for retrieving blacklist entries

This commit is contained in:
netkas 2025-06-05 15:06:48 -04:00
parent eb34a1027c
commit 339db05013
Signed by: netkas
GPG key ID: 4D8629441B76E4CC

View file

@ -174,6 +174,39 @@
}
}
/**
* Returns an array of blacklist records in a pagination style for the global database
*
* @param int $limit The total amount of records to return in this database query
* @param int $page The current page, must start from 1.
* @return BlacklistRecord[] An array of blacklist records as the result
* @throws DatabaseOperationException Thrown if there was a database issue
*/
public static function getEntries(int $limit=100, int $page=1): array
{
if($limit <= 0 || $page <= 0)
{
throw new InvalidArgumentException("Limit and page must be greater than zero.");
}
$offset = ($page - 1) * $limit;
try
{
$stmt = DatabaseConnection::getConnection()->prepare("SELECT * FROM blacklist ORDER BY created DESC LIMIT :limit OFFSET :offset");
$stmt->bindParam(':limit', $limit, PDO::PARAM_INT);
$stmt->bindParam(':offset', $offset, PDO::PARAM_INT);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
return array_map(fn($data) => new BlacklistRecord($data), $results);
}
catch (PDOException $e)
{
throw new DatabaseOperationException("Failed to retrieve blacklist entries by operator: " . $e->getMessage(), 0, $e);
}
}
/**
* Retrieves all blacklist entries for a specific entity.
*