Add pagination support for retrieving blacklist entries
This commit is contained in:
parent
eb34a1027c
commit
339db05013
1 changed files with 33 additions and 0 deletions
|
@ -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.
|
* Retrieves all blacklist entries for a specific entity.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue