diff --git a/backup/moodle2/restore_customcert_activity_task.class.php b/backup/moodle2/restore_customcert_activity_task.class.php index 609dc21..dbb58f2 100644 --- a/backup/moodle2/restore_customcert_activity_task.class.php +++ b/backup/moodle2/restore_customcert_activity_task.class.php @@ -86,8 +86,8 @@ class restore_customcert_activity_task extends restore_activity_task { $rules[] = new restore_log_rule('customcert', 'add', 'view.php?id={course_module}', '{customcert}'); $rules[] = new restore_log_rule('customcert', 'update', 'view.php?id={course_module}', '{customcert}'); $rules[] = new restore_log_rule('customcert', 'view', 'view.php?id={course_module}', '{customcert}'); - $rules[] = new restore_log_rule('customcert', 'received', 'report.php?a={customcert}', '{customcert}'); - $rules[] = new restore_log_rule('customcert', 'view report', 'report.php?id={customcert}', '{customcert}'); + $rules[] = new restore_log_rule('customcert', 'received', 'view.php?id={course_module}', '{customcert}'); + $rules[] = new restore_log_rule('customcert', 'view report', 'view.php?id={course_module}', '{customcert}'); return $rules; } diff --git a/classes/output/email_certificate.php b/classes/output/email_certificate.php index 9c45c68..c113f48 100644 --- a/classes/output/email_certificate.php +++ b/classes/output/email_certificate.php @@ -107,7 +107,7 @@ class email_certificate implements \renderable, \templatable { } else { $data->emailgreeting = get_string('emailnonstudentgreeting', 'customcert'); $data->emailbody = get_string('emailnonstudentbody', 'customcert', $info); - $data->emailcertificatelink = new \moodle_url('/mod/customcert/report.php', array('id' => $this->cmid)); + $data->emailcertificatelink = new \moodle_url('/mod/customcert/view.php', array('id' => $this->cmid)); $data->emailcertificatetext = get_string('emailnonstudentcertificatelinktext', 'customcert'); } diff --git a/classes/output/mobile.php b/classes/output/mobile.php index fb503b6..1e36d63 100644 --- a/classes/output/mobile.php +++ b/classes/output/mobile.php @@ -46,6 +46,7 @@ class mobile { $args = (object) $args; $cmid = $args->cmid; + $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. // Capabilities check. $cm = get_coursemodule_from_id('customcert', $cmid); @@ -77,15 +78,24 @@ class mobile { } $showreport = false; - $numissues = 0; + $groups = []; + $recipients = []; if (has_capability('mod/customcert:viewreport', $context)) { - // Get the total number of issues. $showreport = true; + + // Get the groups (if any) to display - also sets active group. + $groups = self::get_groups($cm, $groupid, $USER->id); $groupmode = groups_get_activity_groupmode($cm); if (has_capability('moodle/site:accessallgroups', $context)) { $groupmode = 'aag'; } - $numissues = \mod_customcert\certificate::get_number_of_issues($certificate->id, $cm, $groupmode); + + $recipients = \mod_customcert\certificate::get_issues($certificate->id, $groupmode, $cm, 0, 0); + foreach ($recipients as $recipient) { + $recipient->displayname = fullname($recipient); + $recipient->fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id, + 'userid' => $recipient->id]); + } } $data = [ @@ -93,11 +103,14 @@ class mobile { 'cmid' => $cm->id, 'hasissues' => !empty($issues), 'issues' => array_values($issues), + 'showgroups' => !empty($groups), + 'groups' => array_values($groups), 'canmanage' => $canmanage, 'candownload' => $candownload, 'fileurl' => $fileurl, 'showreport' => $showreport, - 'numissuesinreport' => $numissues, + 'hasrecipients' => !empty($recipients), + 'recipients' => array_values($recipients), 'currenttimestamp' => time() ]; @@ -113,69 +126,6 @@ class mobile { ]; } - /** - * Returns the list of issues certificates for the activity for the mobile app. - * - * @param array $args Arguments from tool_mobile_get_content WS - * @return array HTML, javascript and other data - */ - public static function mobile_view_report($args) { - global $DB, $OUTPUT, $USER; - - $args = (object) $args; - - $cmid = $args->cmid; - $groupid = empty($args->group) ? 0 : $args->group; // By default, group 0. - - // Capabilities check. - $cm = get_coursemodule_from_id('customcert', $cmid); - $context = \context_module::instance($cm->id); - - self::require_capability($cm, $context, 'mod/customcert:viewreport'); - - // Get the groups (if any) to display - also sets active group. - $groups = self::get_groups($cm, $groupid, $USER->id); - - $certificate = $DB->get_record('customcert', ['id' => $cm->instance], '*', MUST_EXIST); - $certificate->name = format_string($certificate->name); - list($certificate->intro, $certificate->introformat) = external_format_text($certificate->intro, - $certificate->introformat, $context->id, 'mod_customcert', 'intro'); - - $groupmode = groups_get_activity_groupmode($cm); - if (has_capability('moodle/site:accessallgroups', $context)) { - $groupmode = 'aag'; - } - - $issues = \mod_customcert\certificate::get_issues($certificate->id, $groupmode, $cm, 0, 0); - foreach ($issues as $issue) { - $issue->displayname = fullname($issue); - $issue->fileurl = new \moodle_url('/mod/customcert/mobile/pluginfile.php', ['certificateid' => $certificate->id, - 'userid' => $issue->id]); - } - - $data = [ - 'certificate' => $certificate, - 'cmid' => $cmid, - 'showgroups' => !empty($groups), - 'groups' => array_values($groups), - 'canmanage' => has_capability('mod/customcert:manage', $context), - 'hasissues' => !empty($issues), - 'issues' => array_values($issues), - 'currenttimestamp' => time() - ]; - - return [ - 'templates' => [ - [ - 'id' => 'main', - 'html' => $OUTPUT->render_from_template('mod_customcert/mobile_report_page', $data), - ], - ], - 'javascript' => '', - 'otherdata' => '' - ]; - } - /** * Returns an array of groups to be displayed (if applicable) for the activity. * diff --git a/classes/report_table.php b/classes/report_table.php index f3eddd5..978a6fe 100644 --- a/classes/report_table.php +++ b/classes/report_table.php @@ -137,10 +137,12 @@ class report_table extends \table_sql { global $OUTPUT; $icon = new \pix_icon('download', get_string('download'), 'customcert'); - $link = new \moodle_url('/mod/customcert/report.php', - array('id' => $this->cm->id, - 'downloadcert' => '1', - 'userid' => $user->id)); + $link = new \moodle_url('/mod/customcert/view.php', + [ + 'id' => $this->cm->id, + 'downloadissue' => $user->id + ] + ); return $OUTPUT->action_link($link, '', null, null, $icon); } @@ -155,7 +157,7 @@ class report_table extends \table_sql { global $OUTPUT; $icon = new \pix_icon('i/delete', get_string('delete')); - $link = new \moodle_url('/mod/customcert/report.php', + $link = new \moodle_url('/mod/customcert/view.php', [ 'id' => $this->cm->id, 'deleteissue' => $user->issueid, diff --git a/db/mobile.php b/db/mobile.php index 5e76dfa..5e48962 100644 --- a/db/mobile.php +++ b/db/mobile.php @@ -44,8 +44,7 @@ $addons = array( ['pluginname', 'customcert'], ['receiveddate', 'customcert'], ['requiredtimenotmet', 'customcert'], - ['selectagroup', 'moodle'], - ['viewcustomcertissues', 'customcert'] + ['selectagroup', 'moodle'] ], ] ); diff --git a/lang/en/customcert.php b/lang/en/customcert.php index c8b3baa..9c3172f 100644 --- a/lang/en/customcert.php +++ b/lang/en/customcert.php @@ -83,7 +83,7 @@ $string['fontcolour'] = 'Colour'; $string['fontcolour_help'] = 'The colour of the font.'; $string['fontsize'] = 'Size'; $string['fontsize_help'] = 'The size of the font in points.'; -$string['getcustomcert'] = 'Download certificate'; +$string['getcustomcert'] = 'View certificate'; $string['height'] = 'Height'; $string['height_help'] = 'This is the height of the certificate PDF in mm. For reference an A4 piece of paper is 297mm high and a letter is 279mm high.'; $string['invalidcode'] = 'Invalid code supplied.'; @@ -113,6 +113,7 @@ $string['name'] = 'Name'; $string['nametoolong'] = 'You have exceeded the maximum length allowed for the name'; $string['nocustomcerts'] = 'There are no certificates for this course'; $string['noimage'] = 'No image'; +$string['norecipients'] = 'No recipients'; $string['notemplates'] = 'No templates'; $string['notissued'] = 'Not issued'; $string['notverified'] = 'Not verified'; @@ -173,6 +174,5 @@ $string['verifycertificate'] = 'Verify certificate'; $string['verifycertificatedesc'] = 'This link will take you to a new screen where you will be able to verify certificates on the site'; $string['verifycertificateanyone'] = 'Allow anyone to verify a certificate'; $string['verifycertificateanyone_help'] = 'This setting enables anyone with the certificate verification link (including users not logged in) to verify a certificate.'; -$string['viewcustomcertissues'] = 'View {$a} issued certificates'; $string['width'] = 'Width'; $string['width_help'] = 'This is the width of the certificate PDF in mm. For reference an A4 piece of paper is 210mm wide and a letter is 216mm wide.'; diff --git a/report.php b/report.php index 9c6f642..fde4f26 100644 --- a/report.php +++ b/report.php @@ -17,6 +17,8 @@ /** * Handles viewing a report that shows who has received a customcert. * + * This is now just a stub page - all logic has been moved to view.php. + * * @package mod_customcert * @copyright 2013 Mark Nelson * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later @@ -25,96 +27,10 @@ require_once('../../config.php'); $id = required_param('id', PARAM_INT); -$download = optional_param('download', null, PARAM_ALPHA); -$downloadcert = optional_param('downloadcert', '', PARAM_BOOL); -$deleteissue = optional_param('deleteissue', 0, PARAM_INT); -$confirm = optional_param('confirm', 0, PARAM_BOOL); -if ($downloadcert) { - $userid = required_param('userid', PARAM_INT); -} - -$page = optional_param('page', 0, PARAM_INT); -$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT); -$pageurl = $url = new moodle_url('/mod/customcert/report.php', array('id' => $id, 'page' => $page, 'perpage' => $perpage)); $cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); -$customcert = $DB->get_record('customcert', array('id' => $cm->instance), '*', MUST_EXIST); -// Requires a course login. require_login($course, false, $cm); -// Check capabilities. -$context = context_module::instance($cm->id); -require_capability('mod/customcert:viewreport', $context); - -// Set up the page. -$title = $customcert->name; -$heading = format_string($title); -\mod_customcert\page_helper::page_setup($pageurl, $context, $title); - -// Additional page setup. -if ($deleteissue && confirm_sesskey()) { - $PAGE->navbar->add(get_string('listofissues', 'customcert'), - new moodle_url('/mod/customcert/report.php', ['id' => $id])); -} else { - $PAGE->navbar->add(get_string('listofissues', 'customcert')); -} - -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. - $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); - $message = get_string('deleteissueconfirm', 'customcert'); - echo $OUTPUT->header(); - echo $OUTPUT->heading($heading); - 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. -if ($downloadcert) { - $template = $DB->get_record('customcert_templates', array('id' => $customcert->templateid), '*', MUST_EXIST); - $template = new \mod_customcert\template($template); - $template->generate_pdf(false, $userid); - exit(); -} - -// Check if we are in group mode. -if ($groupmode = groups_get_activity_groupmode($cm)) { - groups_get_activity_group($cm, true); -} - -$table = new \mod_customcert\report_table($customcert->id, $cm, $groupmode, $download); -$table->define_baseurl($pageurl); - -if ($table->is_downloading()) { - $table->download(); - exit(); -} - -echo $OUTPUT->header(); -echo $OUTPUT->heading(format_string($customcert->name), 2); -groups_print_activity_menu($cm, $url); -$table->out($perpage, false); -echo $OUTPUT->footer(); +redirect(new moodle_url('/mod/customcert/view.php', ['id' => $id])); diff --git a/templates/mobile_report_page.mustache b/templates/mobile_report_page.mustache deleted file mode 100644 index 4ddda76..0000000 --- a/templates/mobile_report_page.mustache +++ /dev/null @@ -1,122 +0,0 @@ -{{! - This file is part of Moodle - http://moodle.org/ - - Moodle is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Moodle is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Moodle. If not, see . -}} -{{! - @template mod_customcert/mobile_report_page - - The page that lists the custom certificates issued - - Classes required for JS: - * None - - Data attibutes required for JS: - * All data attributes are required - - Context variables required for this template: - * certificate - * cmid - * showgroups - * groups - * canmanage - * hasissues - * issues - * currenttimestamp - - Example context (json): - { - "certificate": { - "id": "1", - "course": "2", - "name": "A rad certificate name!", - "intro": "A certificate" - }, - "cmid": "25", - "showgroups": "true", - "groups": [ - { - "id": "2", - "selected": "false", - "name": "Group A" - } - ], - "canmanage": "true", - "hasissues": "true", - "issues": [ - { - "id": "2", - "issueid": "3", - "displayname": "Michaelangelo (Mickey)", - "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", - "code": "Xyt78axR", - "timecreated": "1528370177" - } - ], - "currenttimestamp": "1528370177" - } -}} -{{=<% %>=}} -
- - <%#showgroups%> - - {{ 'plugin.mod_customcert.selectagroup' | translate }} - - <%#groups%> - selected<%/selected%>><% name %> - <%/groups%> - - - <%/showgroups%> - -

{{ 'plugin.mod_customcert.listofissues' | translate }}

-
- <%#hasissues%> - - <%#issues%> - - - - - <% displayname %> -
- {{ <% timecreated %> | coreToLocaleString }} -
- - - <%#canmanage%> - - <%/canmanage%> - -
-
-
- <%/issues%> -
- <%/hasissues%> - <%^hasissues%> - - {{ 'plugin.mod_customcert.nothingtodisplay' | translate }} - - <%/hasissues%> -
diff --git a/templates/mobile_view_activity_page.mustache b/templates/mobile_view_activity_page.mustache index 34d3a5c..6371257 100644 --- a/templates/mobile_view_activity_page.mustache +++ b/templates/mobile_view_activity_page.mustache @@ -30,10 +30,14 @@ * cmid * hasissues * issues + * showgroups + * groups + * canmanage * candownload + * hasrecipients + * recipients * fileurl * showreport - * numissuesinreport * currenttimestamp Example context (json): @@ -52,21 +56,34 @@ "timecreated": "1528370177" } ], + "showgroups": "true", + "groups": [ + { + "id": "2", + "selected": "false", + "name": "Group A" + } + ], + "canmanage": "true", "candownload": "true", "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", "showreport": "true", - "numissuesinreport": "5", + "hasrecipients": "true", + "recipients": [ + { + "id": "2", + "issueid": "3", + "displayname": "Michaelangelo (Mickey)", + "fileurl": "http://yoursite.com/mod/customcert/mobile/pluginfile.php?id=4", + "timecreated": "1528370177" + } + ], "currenttimestamp": "1528370177" } }} {{=<% %>=}}
- <%#showreport%> - - {{ 'plugin.mod_customcert.viewcustomcertissues' | translate: {$a: <% numissuesinreport %>} }} - - <%/showreport%> <%#hasissues%> <%^canmanage%> @@ -94,4 +111,55 @@

{{ 'plugin.mod_customcert.requiredtimenotmet' | translate: {$a: { requiredtime: <% certificate.requiredtime %>} } }}

<%/candownload%> + <%#showreport%> + + {{ 'plugin.mod_customcert.listofissues' | translate }} + + <%#showgroups%> + + {{ 'plugin.mod_customcert.selectagroup' | translate }} + + <%#groups%> + selected<%/selected%>><% name %> + <%/groups%> + + + <%/showgroups%> + <%#hasrecipients%> + + <%#recipients%> + + + + + <% displayname %> +
+ {{ <% timecreated %> | coreToLocaleString }} +
+ + + <%#canmanage%> + + <%/canmanage%> + +
+
+
+ <%/recipients%> +
+ <%/hasrecipients%> + <%^hasrecipients%> + + {{ 'plugin.mod_customcert.nothingtodisplay' | translate }} + + <%/hasrecipients%> + <%/showreport%>
diff --git a/tests/behat/my_certificates.feature b/tests/behat/my_certificates.feature index 1ad4416..cc59261 100644 --- a/tests/behat/my_certificates.feature +++ b/tests/behat/my_certificates.feature @@ -25,14 +25,14 @@ Feature: Being able to view the certificates you have been issued 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 press "View certificate" And I follow "Profile" in the user menu And I follow "My certificates" And I should see "Custom certificate 1" And I should not see "Custom certificate 2" And I am on "Course 2" course homepage And I follow "Custom certificate 2" - And I press "Download certificate" + And I press "View certificate" And I follow "Profile" in the user menu And I follow "My certificates" And I should see "Custom certificate 1" diff --git a/tests/behat/required_minutes.feature b/tests/behat/required_minutes.feature index 49e85b2..e65cf4d 100644 --- a/tests/behat/required_minutes.feature +++ b/tests/behat/required_minutes.feature @@ -25,7 +25,7 @@ Feature: Being able to set the required minutes in a course before viewing the c And I am on "Course 1" course homepage And I follow "Custom certificate 1" And I should see "You must spend at least a minimum of" - And I should not see "Download certificate" + And I should not see "View certificate" And I press "Continue" And I should see "Custom certificate 1" @@ -36,4 +36,4 @@ Feature: Being able to set the required minutes in a course before viewing the c And I am on "Course 1" course homepage And I follow "Custom certificate 1" And I should not see "You must spend at least a minimum of" - And I should see "Download certificate" + And I should see "View certificate" diff --git a/tests/behat/verify_certificates.feature b/tests/behat/verify_certificates.feature index 7864397..936bdac 100644 --- a/tests/behat/verify_certificates.feature +++ b/tests/behat/verify_certificates.feature @@ -25,7 +25,7 @@ Feature: Being able to verify that a certificate is valid or not 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 press "View certificate" And I log out And I log in as "teacher1" And I am on "Course 1" course homepage @@ -45,7 +45,7 @@ Feature: Being able to verify that a certificate is valid or not And I log in as "student1" And I am on "Course 1" course homepage And I follow "Custom certificate 2" - And I press "Download certificate" + And I press "View certificate" And I log out And I visit the verification url for the "Custom certificate 2" certificate And I set the field "Code" to "NOTAVALIDCODE" @@ -74,10 +74,10 @@ Feature: Being able to verify that a certificate is valid or not 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 press "View certificate" And I am on "Course 1" course homepage And I follow "Custom certificate 2" - And I press "Download certificate" + And I press "View certificate" And I log out And I log in as "admin" # The admin (or anyone with the capability 'mod/customcert:verifyallcertificates') can visit the URL regardless of the setting. @@ -95,10 +95,10 @@ Feature: Being able to verify that a certificate is valid or not 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 press "View certificate" And I am on "Course 1" course homepage And I follow "Custom certificate 2" - And I press "Download certificate" + And I press "View certificate" And I log out And I visit the verification url for the site And I set the field "Code" to "NOTAVALIDCODE" diff --git a/tests/behat/view_issued_certificates.feature b/tests/behat/view_issued_certificates.feature index 5e952e7..f8cb0a5 100644 --- a/tests/behat/view_issued_certificates.feature +++ b/tests/behat/view_issued_certificates.feature @@ -26,17 +26,16 @@ Feature: Being able to view the certificates that have been issued 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 press "View 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 press "View 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" @@ -44,17 +43,16 @@ Feature: Being able to view the certificates that have been issued 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 press "View 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 press "View 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" diff --git a/view.php b/view.php index 7de14f0..a6e9ce8 100644 --- a/view.php +++ b/view.php @@ -25,7 +25,13 @@ require_once('../../config.php'); $id = required_param('id', PARAM_INT); -$action = optional_param('action', '', PARAM_ALPHA); +$downloadown = optional_param('downloadown', false, PARAM_BOOL); +$downloadtable = optional_param('download', null, PARAM_ALPHA); +$downloadissue = optional_param('downloadissue', 0, PARAM_INT); +$deleteissue = optional_param('deleteissue', 0, PARAM_INT); +$confirm = optional_param('confirm', false, PARAM_BOOL); +$page = optional_param('page', 0, PARAM_INT); +$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT); $cm = get_coursemodule_from_id('customcert', $id, 0, false, MUST_EXIST); $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST); @@ -38,6 +44,7 @@ $context = context_module::instance($cm->id); require_capability('mod/customcert:view', $context); $canmanage = has_capability('mod/customcert:manage', $context); +$canviewreport = has_capability('mod/customcert:viewreport', $context); // Initialise $PAGE. $pageurl = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id)); @@ -53,6 +60,36 @@ if ($customcert->requiredtime && !$canmanage) { } } +// Check if we are deleting an issue. +if ($deleteissue && $canmanage && confirm_sesskey()) { + if (!$confirm) { + $nourl = new moodle_url('/mod/customcert/view.php', ['id' => $id]); + $yesurl = new moodle_url('/mod/customcert/view.php', + [ + 'id' => $id, + 'deleteissue' => $deleteissue, + 'confirm' => 1, + 'sesskey' => sesskey() + ] + ); + + // Show a confirmation page. + $PAGE->navbar->add(get_string('deleteconfirm', 'customcert')); + $message = get_string('deleteissueconfirm', 'customcert'); + echo $OUTPUT->header(); + echo $OUTPUT->heading(format_string($customcert->name)); + 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/view.php', array('id' => $id))); +} + $event = \mod_customcert\event\course_module_viewed::create(array( 'objectid' => $customcert->id, 'context' => $context, @@ -61,22 +98,23 @@ $event->add_record_snapshot('course', $course); $event->add_record_snapshot('customcert', $customcert); $event->trigger(); -// Check that no action was passed, if so that means we are not outputting to PDF. -if (empty($action)) { +// Check that we are not downloading a certificate PDF. +if (!$downloadown && !$downloadissue) { // Get the current groups mode. if ($groupmode = groups_get_activity_groupmode($cm)) { groups_get_activity_group($cm, true); } - // Generate the link to the report if there are issues to display. - $reportlink = ''; - if (has_capability('mod/customcert:viewreport', $context)) { + // Generate the table to the report if there are issues to display. + if ($canviewreport) { // Get the total number of issues. - $numissues = \mod_customcert\certificate::get_number_of_issues($customcert->id, $cm, $groupmode); - $href = new moodle_urL('/mod/customcert/report.php', array('id' => $cm->id)); - $url = html_writer::tag('a', get_string('viewcustomcertissues', 'customcert', $numissues), - array('href' => $href->out())); - $reportlink = html_writer::tag('div', $url, array('class' => 'reportlink')); + $reporttable = new \mod_customcert\report_table($customcert->id, $cm, $groupmode, $downloadtable); + $reporttable->define_baseurl($pageurl); + + if ($reporttable->is_downloading()) { + $reporttable->download(); + exit(); + } } // Generate the intro content if it exists. @@ -106,28 +144,38 @@ if (empty($action)) { // Create the button to download the customcert. $linkname = get_string('getcustomcert', 'customcert'); - $link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'action' => 'download')); + $link = new moodle_url('/mod/customcert/view.php', array('id' => $cm->id, 'downloadown' => true)); $downloadbutton = new single_button($link, $linkname); $downloadbutton = html_writer::tag('div', $OUTPUT->render($downloadbutton), array('style' => 'text-align:center')); // Output all the page data. echo $OUTPUT->header(); - echo $OUTPUT->heading(format_string($customcert->name), 2); - echo $reportlink; + echo $OUTPUT->heading(format_string($customcert->name)); echo $intro; echo $issuelist; echo $downloadbutton; - echo $OUTPUT->footer($course); - exit; -} else { // Output to pdf. - // Create new customcert issue record if one does not already exist. - if (!$DB->record_exists('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { - \mod_customcert\certificate::issue_certificate($customcert->id, $USER->id); + if (isset($reporttable)) { + echo $OUTPUT->heading(get_string('listofissues', 'customcert'), 3); + groups_print_activity_menu($cm, $pageurl); + echo $reporttable->out($perpage, false); } + echo $OUTPUT->footer($course); + exit(); +} else { // Output to pdf. + // Set the userid value of who we are downloading the certificate for. + $userid = $USER->id; + if ($downloadown) { + // Create new customcert issue record if one does not already exist. + if (!$DB->record_exists('customcert_issues', array('userid' => $USER->id, 'customcertid' => $customcert->id))) { + \mod_customcert\certificate::issue_certificate($customcert->id, $USER->id); + } - // Set the custom certificate as viewed. - $completion = new completion_info($course); - $completion->set_module_viewed($cm); + // Set the custom certificate as viewed. + $completion = new completion_info($course); + $completion->set_module_viewed($cm); + } else if ($downloadissue && $canviewreport) { + $userid = $downloadissue; + } // Hack alert - don't initiate the download when running Behat. if (defined('BEHAT_SITE_RUNNING')) { @@ -136,6 +184,6 @@ if (empty($action)) { // Now we want to generate the PDF. $template = new \mod_customcert\template($template); - $template->generate_pdf(); + $template->generate_pdf(false, $userid); exit(); }