Skip to content

Commit

Permalink
Webservice: List issued certificates
Browse files Browse the repository at this point in the history
This does not resolve Call list of certificates for a user via API mdjnelson#419 as that specifies getting certificates for a user, not from a date.
Added filter userid and customcertid
  • Loading branch information
michallohnisky committed Oct 2, 2024
1 parent 0a41b40 commit 5d1b2df
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
),
]
);
}
Expand All @@ -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 = [
Expand All @@ -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)) {

Expand Down

0 comments on commit 5d1b2df

Please sign in to comment.