Skip to content

Commit 8ecc09a

Browse files
committed
add logic to store and serve local PDF files
1 parent 22ca94e commit 8ecc09a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

classes/template.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ class template {
4848
*/
4949
protected $contextid;
5050

51+
/**
52+
* @var \mod_customcert\localfile the local file for the template.
53+
*/
54+
protected $localfile;
55+
5156
/**
5257
* The constructor.
5358
*
@@ -57,6 +62,7 @@ public function __construct($template) {
5762
$this->id = $template->id;
5863
$this->name = $template->name;
5964
$this->contextid = $template->contextid;
65+
$this->localfile = new localfile($this);
6066
}
6167

6268
/**
@@ -326,6 +332,13 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re
326332
$deliveryoption = $customcert->deliveryoption;
327333
}
328334

335+
if ($customcert->keeplocalcopy) {
336+
$retval = $this->localfile->sendPDF($userid, $deliveryoption, $return);
337+
if ($return && !empty($retval)) {
338+
return $retval;
339+
}
340+
}
341+
329342
// Remove full-stop at the end, if it exists, to avoid "..pdf" being created and being filtered by clean_filename.
330343
$filename = rtrim(format_string($this->name, true, ['context' => $this->get_context()]), '.');
331344

@@ -374,6 +387,10 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re
374387
}
375388
}
376389

390+
if ($customcert->keeplocalcopy) {
391+
$this->localfile->savePDF($pdf->Output('', 'S'), $userid);
392+
}
393+
377394
if ($return) {
378395
return $pdf->Output('', 'S');
379396
}

0 commit comments

Comments
 (0)