O'Reilly logo

Moodle 3.x Developer's Guide by Ian Wild

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Building a new API

The finished API is available to download from GitHub at https://github.com/iandavidwild/moodle-local_certificateapi. There are two external functions implemented in /externallib.php:

  • get_certificates_by_email()
  • get_certificates_by_username()

As described earlier in the chapter, when interrogating the database, we need to take care that we don't, in any way, overload the database when extracting data. Let's study the get_certificates_by_email() function. This is the complete function:

public static function get_certificates_by_email($hostid = '', $learneremail = '', $starttime='01/01/1970', $endtime='01/01/1970') {       global $USER, $DB;       if(DEBUG_TRACE){error_log('get_certificates_by_email(): function  called $hostid=' ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required