Code to download all certificates:
<?php
require_once('../../config.php');
global $DB,$CFG;
$certlist = $_POST['select_cert'];
print_r($certlist);
$files = array('niBMkaooT.jpg');
$zip = new ZipArchive();
$zip_name = time().".zip";
$zip->open($zip_name, ZipArchive::CREATE);
foreach ($files as $file) {
$path = $file;
if(file_exists($path)){
$zip->addFromString(basename($path), file_get_contents($path));
}
else{
echo"file does not exist";
}
}
$zip->close();
?>
if($certificate!=''){
echo "<input type='checkbox' class='checkboxcert' name='select_cert[]' value='$certificate'>";
}
echo "</td>";
echo "<td>";
Also below i am getting $certificate and when i am downloading individual certificates this is working fine . But when selecting multiple document i am not able to download all
$certificate = get_certificate($userid,$c_id);
Please find the array which i have printed (print_r($certlist))
Array ( [0] => https://google.com/lms/plufile.php/69402/mod_certificate/issue/484123/Abu 2021_Abu, Neglecting, and Exploitation.pdf [1] =>
Please advise what changes are required?`
CodePudding user response:
The certificate PDF isn't always saved, so the file might not always be available
I'd suggest creating and saving the PDF in your own code
Have a look at how the PDF is saved in the view code
https://github.com/mdjnelson/moodle-mod_certificate/blob/master/view.php
if ($certificate->savecert == 1) {
certificate_save_pdf($filecontents, $certrecord->id, $filename, $context->id);
}
Then work backwards from there to see how the variables are created
eg. $USER
is the current user
$certrecord = certificate_get_issue($course, $USER, $certificate, $cm);
So you will need to replace that with the required $user
in your code
$certrecord = certificate_get_issue($course, $user, $certificate, $cm);