0

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?`

Adriaan
  • 17,741
  • 7
  • 42
  • 75
kritika
  • 3
  • 2
  • Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange network, you've granted a non-revocable right, under the [CC BY-SA 4.0 license](https://creativecommons.org/licenses/by-sa/4.0/), for Stack Exchange to distribute that content (i.e. regardless of your future choices). By Stack Exchange policy, the non-vandalized version of the post is the one which is distributed. Thus, any vandalism will be reverted. If you want to know more about deleting a post please see: [How does deleting work?](https://meta.stackexchange.com/q/5221) – Adriaan Jan 18 '23 at 11:02

1 Answers1

0

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);
Russell England
  • 9,436
  • 1
  • 27
  • 41
  • that is really a good answer and i made changes but i need to download all certificates when selected i have created a checkbox for that with value='$certificate' . When i print $certlist array comes with a link for ex : Array ( [0] => https://google.com/lms/pluginfile.php/694402/mod_certificate/issue/484123/Abuse 2022_Abuse, Neglect, and Exploitation Certificate.pdf ) i am not sure what changes are required in $files = array('what to pass '); – kritika Jan 17 '23 at 12:31