Skip to content

Commit 5d1b2df

Browse files
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
1 parent 0a41b40 commit 5d1b2df

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

classes/external.php

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ public static function list_issues_parameters() {
244244
'Timestamp. Returns items created after this date (included).',
245245
VALUE_OPTIONAL
246246
),
247+
'userid' => new external_value(
248+
PARAM_INT,
249+
'User id. Returns items for this user.',
250+
VALUE_OPTIONAL
251+
),
252+
'customcertid' => new external_value(
253+
PARAM_INT,
254+
'Customcert id. Returns items for this customcert.',
255+
VALUE_OPTIONAL
256+
),
247257
]
248258
);
249259
}
@@ -252,9 +262,11 @@ public static function list_issues_parameters() {
252262
* Returns array of issued certificates.
253263
*
254264
* @param ?int $timecreatedfrom Timestamp. Returns items created after this date (included).
265+
* @param ?int $userid User id. Returns items for this user.
266+
* @param ?int $customcertid Customcert id. Returns items for this customcert.
255267
* @return array
256268
*/
257-
public static function list_issues($timecreatedfrom = null) {
269+
public static function list_issues($timecreatedfrom = null, $userid = null, $customcertid = null) {
258270
global $DB;
259271

260272
$params = [
@@ -273,10 +285,22 @@ public static function list_issues($timecreatedfrom = null) {
273285
ON ci.customcertid = c.id
274286
JOIN {customcert_templates} ct
275287
ON c.templateid = ct.id";
288+
$conditions = [];
276289
if ($timecreatedfrom) {
277-
$sql .= " WHERE ci.timecreated >= :timecreatedfrom";
290+
$conditions[] = "ci.timecreated >= :timecreatedfrom";
278291
$nameparams['timecreatedfrom'] = $timecreatedfrom;
279292
}
293+
if ($userid) {
294+
$conditions[] = "ci.userid = :userid";
295+
$nameparams['userid'] = $userid;
296+
}
297+
if ($customcertid) {
298+
$conditions[] = "ci.customcertid = :customcertid";
299+
$nameparams['customcertid'] = $customcertid;
300+
}
301+
if ($conditions) {
302+
$sql .= " WHERE " . implode(" AND ", $conditions);
303+
}
280304

281305
if ($issues = $DB->get_records_sql($sql, $nameparams)) {
282306

0 commit comments

Comments
 (0)