#119 Add ability to delete issued certificates
This commit is contained in:
parent
a7b14ab48d
commit
4232b1da86
5 changed files with 90 additions and 1 deletions
|
@ -265,7 +265,7 @@ class certificate {
|
||||||
|
|
||||||
// Return the issues.
|
// Return the issues.
|
||||||
$ufields = \user_picture::fields('u');
|
$ufields = \user_picture::fields('u');
|
||||||
$sql = "SELECT $ufields, ci.code, ci.timecreated
|
$sql = "SELECT $ufields, ci.id as issueid, ci.code, ci.timecreated
|
||||||
FROM {user} u
|
FROM {user} u
|
||||||
INNER JOIN {customcert_issues} ci
|
INNER JOIN {customcert_issues} ci
|
||||||
ON u.id = ci.userid
|
ON u.id = ci.userid
|
||||||
|
|
|
@ -86,6 +86,11 @@ class report_table extends \table_sql {
|
||||||
$headers[] = get_string('file');
|
$headers[] = get_string('file');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (has_capability('mod/customcert:manage', \context_module::instance($cm->id))) {
|
||||||
|
$columns[] = 'actions';
|
||||||
|
$headers[] = '';
|
||||||
|
}
|
||||||
|
|
||||||
$this->define_columns($columns);
|
$this->define_columns($columns);
|
||||||
$this->define_headers($headers);
|
$this->define_headers($headers);
|
||||||
$this->collapsible(false);
|
$this->collapsible(false);
|
||||||
|
@ -149,6 +154,27 @@ class report_table extends \table_sql {
|
||||||
return $OUTPUT->action_link($link, '', null, null, $icon);
|
return $OUTPUT->action_link($link, '', null, null, $icon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generate the actions column.
|
||||||
|
*
|
||||||
|
* @param \stdClass $user
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function col_actions($user) {
|
||||||
|
global $OUTPUT;
|
||||||
|
|
||||||
|
$icon = new \pix_icon('i/delete', get_string('delete'));
|
||||||
|
$link = new \moodle_url('/mod/customcert/report.php',
|
||||||
|
[
|
||||||
|
'id' => $this->cm->id,
|
||||||
|
'deleteissue' => $user->issueid,
|
||||||
|
'sesskey' => sesskey()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
return $OUTPUT->action_icon($link, $icon, null, ['class' => 'action-icon delete-icon']);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query the reader.
|
* Query the reader.
|
||||||
*
|
*
|
||||||
|
|
|
@ -43,6 +43,7 @@ $string['deletecertpage'] = 'Delete page';
|
||||||
$string['deleteconfirm'] = 'Delete confirmation';
|
$string['deleteconfirm'] = 'Delete confirmation';
|
||||||
$string['deleteelement'] = 'Delete element';
|
$string['deleteelement'] = 'Delete element';
|
||||||
$string['deleteelementconfirm'] = 'Are you sure you want to delete this element?';
|
$string['deleteelementconfirm'] = 'Are you sure you want to delete this element?';
|
||||||
|
$string['deleteissueconfirm'] = 'Are you sure you want to delete this certificate issue?';
|
||||||
$string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?';
|
$string['deletepageconfirm'] = 'Are you sure you want to delete this certificate page?';
|
||||||
$string['deletetemplateconfirm'] = 'Are you sure you want to delete this certificate template?';
|
$string['deletetemplateconfirm'] = 'Are you sure you want to delete this certificate template?';
|
||||||
$string['description'] = 'Description';
|
$string['description'] = 'Description';
|
||||||
|
|
36
report.php
36
report.php
|
@ -27,6 +27,8 @@ require_once('../../config.php');
|
||||||
$id = required_param('id', PARAM_INT);
|
$id = required_param('id', PARAM_INT);
|
||||||
$download = optional_param('download', null, PARAM_ALPHA);
|
$download = optional_param('download', null, PARAM_ALPHA);
|
||||||
$downloadcert = optional_param('downloadcert', '', PARAM_BOOL);
|
$downloadcert = optional_param('downloadcert', '', PARAM_BOOL);
|
||||||
|
$deleteissue = optional_param('deleteissue', 0, PARAM_INT);
|
||||||
|
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||||
if ($downloadcert) {
|
if ($downloadcert) {
|
||||||
$userid = required_param('userid', PARAM_INT);
|
$userid = required_param('userid', PARAM_INT);
|
||||||
}
|
}
|
||||||
|
@ -46,6 +48,40 @@ require_login($course, false, $cm);
|
||||||
$context = context_module::instance($cm->id);
|
$context = context_module::instance($cm->id);
|
||||||
require_capability('mod/customcert:viewreport', $context);
|
require_capability('mod/customcert:viewreport', $context);
|
||||||
|
|
||||||
|
if ($deleteissue && confirm_sesskey()) {
|
||||||
|
require_capability('mod/customcert:manage', $context);
|
||||||
|
|
||||||
|
if (!$confirm) {
|
||||||
|
$nourl = new moodle_url('/mod/customcert/report.php', ['id' => $id]);
|
||||||
|
$yesurl = new moodle_url('/mod/customcert/report.php',
|
||||||
|
[
|
||||||
|
'id' => $id,
|
||||||
|
'deleteissue' => $deleteissue,
|
||||||
|
'confirm' => 1,
|
||||||
|
'sesskey' => sesskey()
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show a confirmation page.
|
||||||
|
$strheading = get_string('deleteconfirm', 'customcert');
|
||||||
|
$PAGE->navbar->add($strheading);
|
||||||
|
$PAGE->set_title($strheading);
|
||||||
|
$PAGE->set_url($url);
|
||||||
|
$message = get_string('deleteissueconfirm', 'customcert');
|
||||||
|
echo $OUTPUT->header();
|
||||||
|
echo $OUTPUT->heading($strheading);
|
||||||
|
echo $OUTPUT->confirm($message, $yesurl, $nourl);
|
||||||
|
echo $OUTPUT->footer();
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete the issue.
|
||||||
|
$DB->delete_records('customcert_issues', array('id' => $deleteissue, 'customcertid' => $customcert->id));
|
||||||
|
|
||||||
|
// Redirect back to the manage templates page.
|
||||||
|
redirect(new moodle_url('/mod/customcert/report.php', array('id' => $id)));
|
||||||
|
}
|
||||||
|
|
||||||
// Check if we requested to download another user's certificate.
|
// Check if we requested to download another user's certificate.
|
||||||
if ($downloadcert) {
|
if ($downloadcert) {
|
||||||
$template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid), '*', MUST_EXIST);
|
$template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid), '*', MUST_EXIST);
|
||||||
|
|
|
@ -39,3 +39,29 @@ Feature: Being able to view the certificates that have been issued
|
||||||
And I follow "View 2 issued certificates"
|
And I follow "View 2 issued certificates"
|
||||||
And I should see "Student 1"
|
And I should see "Student 1"
|
||||||
And I should see "Student 2"
|
And I should see "Student 2"
|
||||||
|
|
||||||
|
Scenario: Delete an issued certificate
|
||||||
|
And I log in as "student1"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I follow "Custom certificate 1"
|
||||||
|
And I press "Download certificate"
|
||||||
|
And I log out
|
||||||
|
And I log in as "student2"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I follow "Custom certificate 1"
|
||||||
|
And I press "Download certificate"
|
||||||
|
And I log out
|
||||||
|
And I log in as "teacher1"
|
||||||
|
And I am on "Course 1" course homepage
|
||||||
|
And I follow "Custom certificate 1"
|
||||||
|
And I follow "View 2 issued certificates"
|
||||||
|
And I should see "Student 1"
|
||||||
|
And I should see "Student 2"
|
||||||
|
And I click on ".delete-icon" "css_element" in the "Student 2" "table_row"
|
||||||
|
And I press "Cancel"
|
||||||
|
And I should see "Student 1"
|
||||||
|
And I should see "Student 2"
|
||||||
|
And I click on ".delete-icon" "css_element" in the "Student 2" "table_row"
|
||||||
|
And I press "Continue"
|
||||||
|
And I should see "Student 1"
|
||||||
|
And I should not see "Student 2"
|
||||||
|
|
Loading…
Reference in a new issue