Adding the date of a face to face course to the certificate

Re: Adding the date of a face to face course to the certificate

by Mark Nelson -
Number of replies: 3
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers

You will need to use the database layer in Moodle to retrieve the data you want to display (have a look at https://docs.moodle.org/dev/Data_manipulation_API). Once you have the value, you won't be echoing it, you will be passing it to the certificate_print_text() function. For an example of its use take a look at mod/certificate/type/A4_embedded/certificate.php.

Average of ratings: Useful (1)
In reply to Mark Nelson

Re: Adding the date of a face to face course to the certificate

by James Todd -

I've read the doc and read a few forums with similar question.

My head is hurting, how do I use the database layer.

Do I create a new file or add the code to the certificate.

I'm normally good with SQL and PHP but I'm sure I must be missing something. 

In reply to James Todd

Re: Adding the date of a face to face course to the certificate

by Mark Nelson -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Testers
All the code is done in the certificate.php file I mentioned above. You simply need to use the global $DB to retrieve the data you want from the database to display. There are plenty of examples in core and the docs that show how this can be done. Have a look in core for 'get_record', 'get_record_sql' etc.
In reply to Mark Nelson

Re: Adding the date of a face to face course to the certificate

by James Todd -

I'm back


I've got it mostly working but can't get the time to convert all the usual unix converters either give a page error or do nothing.

How do I join tables in the Global $db.

It looks like it works at first but my certificate put a different unix date on.

Have a look at to see where I'm going wrong please


$sql = " SELECT *
FROM {facetoface} f
JOIN {facetoface_sessions} fs ON f.id = fs.facetoface
JOIN {facetoface_sessions_dates} fsd ON fs.id = fsd.sessionid
JOIN {facetoface_signups} fsu ON fs.id = fsu.sessionid
JOIN {user} u ON fsu.userid = u.id";

$f2fdate = $DB->get_record_sql('SELECT timefinish FROM {facetoface_sessions_dates}');


certificate_print_text($pdf, $x, $y + 92, 'C', 'freesans', '', 20, $f2fdate->timefinish);


Thanks Jimi