script to regenerate saved certificates for all users

Re: script to regenerate saved certificates for all users

by Michael E -
Number of replies: 0
Picture of Core developers Picture of Testers

Jamie, Thank you! That was exactly what I was looking for.

I went ahead and added a small feature to integrate it directly into the module. The report page now has a button to access the script and the script itself has a "back" button to go back to the report. This allows my instructors to regenerate the PDFs themselves without having to contact me first.

In regeneratecertificates.php, above

session_set_user($realuser);

add the following:

$reporturl = $CFG->wwwroot.'/mod/certificate/report.php?id='.$id;
echo "<p><a href='{$reporturl}'>Return to report</a></p>";

 

In report.php look for the following code around line 255:

// Create table to store buttons
$tablebutton = new html_table();
$tablebutton->attributes['class'] = 'downloadreport';
$btndownloadods = $OUTPUT->single_button(new moodle_url("report.php", array('id'=>$cm->id, 'download'=>'ods')), get_string("downloadods"));
$btndownloadxls = $OUTPUT->single_button(new moodle_url("report.php", array('id'=>$cm->id, 'download'=>'xls')), get_string("downloadexcel"));
$btndownloadtxt = $OUTPUT->single_button(new moodle_url("report.php", array('id'=>$cm->id, 'download'=>'txt')), get_string("downloadtext"));

Below that, add the following code:

$btnregenerate = $OUTPUT->single_button(new moodle_url("regeneratecertificates.php", array('id'=>$cm->id)), "Regenerate PDFs");

 

Look for the following code (just below the previous code):

$tablebutton->data[] = array($btndownloadods, $btndownloadxls, $btndownloadtxt);

and replace it with:

$tablebutton->data[] = array($btndownloadods, $btndownloadxls, $btndownloadtxt, $btnregenerate);

 

Further suggestions for future work could be that the design uses the current theme and that the text from the button is stored in the language file.

Because I believe your work could be helpful to others as well, I filed an improvement in the tracker: https://tracker.moodle.org/browse/CONTRIB-4220