Added sort fields
Signed-off-by: Valentin Popov <info@valentineus.link>
This commit is contained in:
parent
da306feae3
commit
cb6d5c7e13
@ -126,17 +126,18 @@ final class api {
|
|||||||
/**
|
/**
|
||||||
* Get list records from the database.
|
* Get list records from the database.
|
||||||
*
|
*
|
||||||
* @param array|null $conditions
|
* @param array|null $conditions
|
||||||
* @param int|null $limitfrom
|
* @param string|null $sort
|
||||||
* @param int|null $limitnum
|
* @param int|null $from
|
||||||
|
* @param int|null $limit
|
||||||
*
|
*
|
||||||
* @return \local_webhooks\local\record[]
|
* @return array
|
||||||
* @throws \dml_exception
|
* @throws \dml_exception
|
||||||
*/
|
*/
|
||||||
public static function get_services(array $conditions = null, int $limitfrom = null, int $limitnum = null): array {
|
public static function get_services(array $conditions = null, string $sort = null, int $from = null, int $limit = null): array {
|
||||||
global $DB;
|
global $DB;
|
||||||
|
|
||||||
$records = $DB->get_records(LW_TABLE_SERVICES, $conditions ?? [], '', '*', $limitfrom ?? 0, $limitnum ?? 0);
|
$records = $DB->get_records(LW_TABLE_SERVICES, $conditions ?? [], $sort ?? '', '*', $from ?? 0, $limit ?? 0);
|
||||||
|
|
||||||
$services = [];
|
$services = [];
|
||||||
foreach ($records as $record) {
|
foreach ($records as $record) {
|
||||||
|
@ -291,12 +291,19 @@ final class local_webhooks_api_testcase extends advanced_testcase {
|
|||||||
api::create_service($record);
|
api::create_service($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Testing condition fields.
|
||||||
self::assertCount(1, api::get_services([
|
self::assertCount(1, api::get_services([
|
||||||
'point' => 'http://example.org/test_' . random_int(1, 5),
|
'point' => 'http://example.org/test_' . random_int(1, 5),
|
||||||
]));
|
]));
|
||||||
|
|
||||||
|
// Testing limit fields.
|
||||||
$limit = intdiv($total, 2);
|
$limit = intdiv($total, 2);
|
||||||
self::assertCount($limit, api::get_services([], 1, $limit));
|
self::assertCount($limit, api::get_services([], null, 1, $limit));
|
||||||
|
|
||||||
|
// Testing sort fields.
|
||||||
|
$service1 = api::get_services(null, 'id asc')[0];
|
||||||
|
$service2 = api::get_services(null, 'id desc')[0];
|
||||||
|
self::assertNotEquals($service1->id, $service2->id);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
x
Reference in New Issue
Block a user