From 5d1b2df031e5bc8ee574870322699bbe2611f05c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Lohnisk=C3=BD?= Date: Wed, 2 Oct 2024 14:49:55 +0200 Subject: [PATCH] Webservice: List issued certificates This does not resolve Call list of certificates for a user via API #419 as that specifies getting certificates for a user, not from a date. Added filter userid and customcertid --- classes/external.php | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/classes/external.php b/classes/external.php index 9d0cbc9c..33312412 100644 --- a/classes/external.php +++ b/classes/external.php @@ -244,6 +244,16 @@ public static function list_issues_parameters() { 'Timestamp. Returns items created after this date (included).', VALUE_OPTIONAL ), + 'userid' => new external_value( + PARAM_INT, + 'User id. Returns items for this user.', + VALUE_OPTIONAL + ), + 'customcertid' => new external_value( + PARAM_INT, + 'Customcert id. Returns items for this customcert.', + VALUE_OPTIONAL + ), ] ); } @@ -252,9 +262,11 @@ public static function list_issues_parameters() { * Returns array of issued certificates. * * @param ?int $timecreatedfrom Timestamp. Returns items created after this date (included). + * @param ?int $userid User id. Returns items for this user. + * @param ?int $customcertid Customcert id. Returns items for this customcert. * @return array */ - public static function list_issues($timecreatedfrom = null) { + public static function list_issues($timecreatedfrom = null, $userid = null, $customcertid = null) { global $DB; $params = [ @@ -273,10 +285,22 @@ public static function list_issues($timecreatedfrom = null) { ON ci.customcertid = c.id JOIN {customcert_templates} ct ON c.templateid = ct.id"; + $conditions = []; if ($timecreatedfrom) { - $sql .= " WHERE ci.timecreated >= :timecreatedfrom"; + $conditions[] = "ci.timecreated >= :timecreatedfrom"; $nameparams['timecreatedfrom'] = $timecreatedfrom; } + if ($userid) { + $conditions[] = "ci.userid = :userid"; + $nameparams['userid'] = $userid; + } + if ($customcertid) { + $conditions[] = "ci.customcertid = :customcertid"; + $nameparams['customcertid'] = $customcertid; + } + if ($conditions) { + $sql .= " WHERE " . implode(" AND ", $conditions); + } if ($issues = $DB->get_records_sql($sql, $nameparams)) {