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

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

by James Todd -
Number of replies: 7

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


Currently the date that shows up on the certificate is the date attendance was marked, which could be a week after the course.

We would like the course date to show up.

I'm guessing I need to create a variable and call it up in the type file.


Thanks Jimi

Average of ratings: -
In reply to James Todd

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

by James Todd -

Is it possible to add information from a field in the database

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

Totally.

https://docs.moodle.org/31/en/Certificate_customizing

Basically - edit the code in mod/certificate/type/<typeyouareusing/certificate.php to perform a DB query and print out the field. I would suggest creating a new certificate type, rather than editing the existing ones.

In reply to Mark Nelson

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

by James Todd -

Thanks Mark


I've spent a couple of days trying different ways to accept a DB query to pull through to no avail.

Do I need to use sql to connect to the database then echo the fields.

If so  how do I display the date of the course for the user clicking on the certificate link.

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

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