[DB] Add mechanism for specifying limit and offset in dql query

This commit is contained in:
Hugo Sales 2021-09-20 15:21:38 +01:00
parent 91fd7d1cfa
commit ce80065775
Signed by untrusted user: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0

View File

@ -84,14 +84,23 @@ class DB
/**
* Perform a Doctrine Query Language query
*/
public static function dql(string $query, array $params = [])
public static function dql(string $query, array $params = [], array $options = [])
{
$query = preg_replace(F\map(self::$table_map, function ($_, $s) { return "/\\b{$s}\\b/"; }), self::$table_map, $query);
$query = preg_replace(F\map(self::$table_map, fn ($_, $s) => "/\\b{$s}\\b/"), self::$table_map, $query);
$q = new Query(self::$em);
$q->setDQL($query);
if (isset($options['limit'])) {
$q->setMaxResults($options['limit']);
}
if (isset($options['offset'])) {
$q->setFirstResult($options['offset']);
}
foreach ($params as $k => $v) {
$q->setParameter($k, $v);
}
return $q->getResult();
}