Skip to content

Commit c35d84f

Browse files
committed
add deletelocalcopy logic
1 parent b3c1b99 commit c35d84f

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

view.php

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
$downloadtable = optional_param('download', null, PARAM_ALPHA);
3030
$downloadissue = optional_param('downloadissue', 0, PARAM_INT);
3131
$deleteissue = optional_param('deleteissue', 0, PARAM_INT);
32+
$deletelocalcopy = optional_param('deletelocalcopy', 0, PARAM_INT);
3233
$confirm = optional_param('confirm', false, PARAM_BOOL);
3334
$page = optional_param('page', 0, PARAM_INT);
3435
$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT);
@@ -46,6 +47,7 @@
4647
$canreceive = has_capability('mod/customcert:receiveissue', $context);
4748
$canmanage = has_capability('mod/customcert:manage', $context);
4849
$canviewreport = has_capability('mod/customcert:viewreport', $context);
50+
$candeletelocalcopy = has_capability('mod/customcert:deletelocalcopy', $context);
4951

5052
// Initialise $PAGE.
5153
$pageurl = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id));
@@ -70,23 +72,40 @@
7072
[
7173
'id' => $id,
7274
'deleteissue' => $deleteissue,
75+
'deletelocalcopy' => $deletelocalcopy,
7376
'confirm' => 1,
7477
'sesskey' => sesskey()
7578
]
7679
);
7780

7881
// 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+
}
8189
echo $OUTPUT->header();
8290
echo $OUTPUT->heading(format_string($customcert->name));
8391
echo $OUTPUT->confirm($message, $yesurl, $nourl);
8492
echo $OUTPUT->footer();
8593
exit();
8694
}
8795

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+
}
90109

91110
// Redirect back to the manage templates page.
92111
redirect(new moodle_url('/mod/customcert/view.php', array('id' => $id)));

0 commit comments

Comments
 (0)