@@ -48,6 +48,11 @@ class template {
48
48
*/
49
49
protected $ contextid ;
50
50
51
+ /**
52
+ * @var \mod_customcert\localfile the local file for the template.
53
+ */
54
+ protected $ localfile ;
55
+
51
56
/**
52
57
* The constructor.
53
58
*
@@ -57,6 +62,7 @@ public function __construct($template) {
57
62
$ this ->id = $ template ->id ;
58
63
$ this ->name = $ template ->name ;
59
64
$ this ->contextid = $ template ->contextid ;
65
+ $ this ->localfile = new localfile ($ this );
60
66
}
61
67
62
68
/**
@@ -326,6 +332,13 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re
326
332
$ deliveryoption = $ customcert ->deliveryoption ;
327
333
}
328
334
335
+ if ($ customcert ->keeplocalcopy ) {
336
+ $ retval = $ this ->localfile ->sendPDF ($ userid , $ deliveryoption , $ return );
337
+ if ($ return && !empty ($ retval )) {
338
+ return $ retval ;
339
+ }
340
+ }
341
+
329
342
// Remove full-stop at the end, if it exists, to avoid "..pdf" being created and being filtered by clean_filename.
330
343
$ filename = rtrim (format_string ($ this ->name , true , ['context ' => $ this ->get_context ()]), '. ' );
331
344
@@ -374,6 +387,10 @@ public function generate_pdf(bool $preview = false, int $userid = null, bool $re
374
387
}
375
388
}
376
389
390
+ if ($ customcert ->keeplocalcopy ) {
391
+ $ this ->localfile ->savePDF ($ pdf ->Output ('' , 'S ' ), $ userid );
392
+ }
393
+
377
394
if ($ return ) {
378
395
return $ pdf ->Output ('' , 'S ' );
379
396
}
0 commit comments