|
29 | 29 | $downloadtable = optional_param('download', null, PARAM_ALPHA);
|
30 | 30 | $downloadissue = optional_param('downloadissue', 0, PARAM_INT);
|
31 | 31 | $deleteissue = optional_param('deleteissue', 0, PARAM_INT);
|
| 32 | +$deletelocalcopy = optional_param('deletelocalcopy', 0, PARAM_INT); |
32 | 33 | $confirm = optional_param('confirm', false, PARAM_BOOL);
|
33 | 34 | $page = optional_param('page', 0, PARAM_INT);
|
34 | 35 | $perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT);
|
|
46 | 47 | $canreceive = has_capability('mod/customcert:receiveissue', $context);
|
47 | 48 | $canmanage = has_capability('mod/customcert:manage', $context);
|
48 | 49 | $canviewreport = has_capability('mod/customcert:viewreport', $context);
|
| 50 | +$candeletelocalcopy = has_capability('mod/customcert:deletelocalcopy', $context); |
49 | 51 |
|
50 | 52 | // Initialise $PAGE.
|
51 | 53 | $pageurl = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id));
|
|
70 | 72 | [
|
71 | 73 | 'id' => $id,
|
72 | 74 | 'deleteissue' => $deleteissue,
|
| 75 | + 'deletelocalcopy' => $deletelocalcopy, |
73 | 76 | 'confirm' => 1,
|
74 | 77 | 'sesskey' => sesskey()
|
75 | 78 | ]
|
76 | 79 | );
|
77 | 80 |
|
78 | 81 | // Show a confirmation page.
|
79 |
| - $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); |
80 |
| - $message = get_string('deleteissueconfirm', 'customcert'); |
| 82 | + if ($deletelocalcopy) { |
| 83 | + $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); |
| 84 | + $message = get_string('deletelocalcopyconfirm', 'customcert'); |
| 85 | + } else if ($deleteissue) { |
| 86 | + $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); |
| 87 | + $message = get_string('deleteissueconfirm', 'customcert'); |
| 88 | + } |
81 | 89 | echo $OUTPUT->header();
|
82 | 90 | echo $OUTPUT->heading(format_string($customcert->name));
|
83 | 91 | echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
84 | 92 | echo $OUTPUT->footer();
|
85 | 93 | exit();
|
86 | 94 | }
|
87 | 95 |
|
88 |
| - // Delete the issue. |
89 |
| - $DB->delete_records('customcert_issues', array('id' => $deleteissue, 'customcertid' => $customcert->id)); |
| 96 | + // Always delete local copy. |
| 97 | + if ($candeletelocalcopy) { |
| 98 | + $issues = $DB->get_records('customcert_issues', array('id' => $deleteissue, 'customcertid' => $customcert->id)); |
| 99 | + if (!empty($issues)) { |
| 100 | + $lf = new \mod_customcert\localfile(new \mod_customcert\template($template)); |
| 101 | + array_map(fn($issue) => $lf->deletePDF($issue->userid), $issues); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + if (!$deletelocalcopy) { |
| 106 | + // Delete the issue. |
| 107 | + $DB->delete_records('customcert_issues', array('id' => $deleteissue, 'customcertid' => $customcert->id)); |
| 108 | + } |
90 | 109 |
|
91 | 110 | // Redirect back to the manage templates page.
|
92 | 111 | redirect(new moodle_url('/mod/customcert/view.php', array('id' => $id)));
|
|
0 commit comments