Skip to content

Commit

Permalink
IOMAD: regenerating a certificate may not work if the user is current…
Browse files Browse the repository at this point in the history
…ly re-enrolled on a course and doesn't haveaccess to the certificate
  • Loading branch information
turf212 committed Sep 18, 2023
1 parent 7f5d248 commit f488af9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion admin/tool/redocerts/cli/redocerts.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
}
$DB->delete_records('files', array('itemid' => $track->id, 'component' => 'local_iomad_track'));
mtrace ("adding Certificate");
xmldb_local_iomad_track_record_certificates($track->courseid, $track->userid, $track->id);
xmldb_local_iomad_track_record_certificates($track->courseid, $track->userid, $track->id, true, false);

$count++;
}
Expand Down
2 changes: 1 addition & 1 deletion admin/tool/redocerts/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function do_redocerts($user = 0, $course = 0, $company = 0, $idnumber = 0, $from
echo html_writer::end_tag('br');
local_iomad_track_delete_entry($track->id);
echo format_string('recreatingcertificate', 'tool_redocerts');
if (xmldb_local_iomad_track_record_certificates($track->courseid, $track->userid, $track->id)) {
if (xmldb_local_iomad_track_record_certificates($track->courseid, $track->userid, $track->id, true, false)) {
echo format_string('success');
} else {
echo format_string('falied', 'scorm');
Expand Down
4 changes: 2 additions & 2 deletions local/iomad_track/db/install.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function xmldb_local_iomad_track_save_certificate($trackid, $filename) {
/**
* Process (any) certificates in the course
*/
function xmldb_local_iomad_track_record_certificates($courseid, $userid, $trackid, $showresult = true) {
function xmldb_local_iomad_track_record_certificates($courseid, $userid, $trackid, $showresult = true, $onlyvisible = true) {
global $DB;

// Get course.
Expand Down Expand Up @@ -156,7 +156,7 @@ function xmldb_local_iomad_track_record_certificates($courseid, $userid, $tracki
$cm = $modinfo->get_cm($cm->id);

// Can the user see this certificate?
if (!$cm->uservisible) {
if ($onlyvisible && !$cm->uservisible) {
continue;
}

Expand Down
8 changes: 4 additions & 4 deletions local/report_completion/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@
if ($trackrec = $DB->get_record('local_iomad_track', array('id' => $redocertificate))) {
echo html_writer::start_tag('p');
local_iomad_track_delete_entry($redocertificate);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, true, false);
echo html_writer::end_tag('p');
}
}
Expand Down Expand Up @@ -318,7 +318,7 @@
// Re-generate the certificate.
if ($trackrec = $DB->get_record('local_iomad_track', array('id' => $key))) {
local_iomad_track_delete_entry($key);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false, true);
}
}
}
Expand Down Expand Up @@ -362,7 +362,7 @@

// Re-generate the certificate.
local_iomad_track_delete_entry($key);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false, true);
}
}
}
Expand All @@ -376,7 +376,7 @@
if ($action == 'redocert' && !empty($redocertificate)) {
if ($trackrec = $DB->get_record('local_iomad_track', array('id' => $redocertificate))) {
local_iomad_track_delete_entry($redocertificate);
if (xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false)) {
if (xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false, true)) {
redirect(new moodle_url('/local/report_completion/index.php', $params),
get_string($action . "_successful", 'local_report_users'),
null,
Expand Down
2 changes: 1 addition & 1 deletion local/report_users/newentry.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@
$trackid = $DB->insert_record('local_iomad_track', $newentry);

// Create a certificate, if required.
xmldb_local_iomad_track_record_certificates($newentry->courseid, $newentry->userid, $trackid, false);
xmldb_local_iomad_track_record_certificates($newentry->courseid, $newentry->userid, $trackid, false, true);

// Return success.
redirect($returnurl,
Expand Down
8 changes: 4 additions & 4 deletions local/report_users/userdisplay.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@
if ($trackrec = $DB->get_record('local_iomad_track', array('id' => $redocertificate))) {
echo html_writer::start_tag('p');
local_iomad_track_delete_entry($redocertificate);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, true, false);
echo html_writer::end_tag('p');
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@
// Re-generate the certificate.
if ($trackrec = $DB->get_record('local_iomad_track', array('id' => $key))) {
local_iomad_track_delete_entry($key);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false, true);
}
}
}
Expand Down Expand Up @@ -250,7 +250,7 @@

// Re-generate the certificate.
local_iomad_track_delete_entry($key);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false);
xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false, true);
}
}
}
Expand All @@ -272,7 +272,7 @@
if ($action == 'redocert' && !empty($redocertificate)) {
if ($trackrec = $DB->get_record('local_iomad_track', array('id' => $redocertificate))) {
local_iomad_track_delete_entry($redocertificate);
if (xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false)) {
if (xmldb_local_iomad_track_record_certificates($trackrec->courseid, $trackrec->userid, $trackrec->id, false, true)) {
redirect(new moodle_url('/local/report_users/userdisplay.php', array('userid' => $userid)),
get_string($action . "_successful", 'local_report_users'),
null,
Expand Down

0 comments on commit f488af9

Please sign in to comment.