#207 Follow-up UX improvements

The majority of this change involved moving
the report page logic into the view page for
both browser and mobile.
This commit is contained in:
Mark Nelson 2018-07-01 20:18:09 +08:00
parent 9589bad2d8
commit 2736eceb6a
14 changed files with 194 additions and 335 deletions

View file

@ -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;
}

View file

@ -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');
}

View file

@ -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.
*

View file

@ -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,

View file

@ -44,8 +44,7 @@ $addons = array(
['pluginname', 'customcert'],
['receiveddate', 'customcert'],
['requiredtimenotmet', 'customcert'],
['selectagroup', 'moodle'],
['viewcustomcertissues', 'customcert']
['selectagroup', 'moodle']
],
]
);

View file

@ -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.';

View file

@ -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 <markn@moodle.com>
* @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]));

View file

@ -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 <http://www.gnu.org/licenses/>.
}}
{{!
@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"
}
}}
{{=<% %>=}}
<div>
<core-course-module-description description="<% certificate.intro %>" component="mod_customcert" componentId="<% cmid %>"></core-course-module-description>
<%#showgroups%>
<ion-item>
<ion-label>{{ 'plugin.mod_customcert.selectagroup' | translate }}</ion-label>
<ion-select (ionChange)="updateContent({cmid: <% cmid %>, courseid: <% certificate.course %>, group: $event})" interface="popover">
<%#groups%>
<ion-option value="<% id %>" <%#selected%>selected<%/selected%>><% name %></ion-option>
<%/groups%>
</ion-select>
</ion-item>
<%/showgroups%>
<ion-item class="text-center">
<p class="item-heading">{{ 'plugin.mod_customcert.listofissues' | translate }}</p>
</ion-item>
<%#hasissues%>
<ion-list>
<%#issues%>
<ion-item>
<ion-grid>
<ion-row>
<ion-col col-6 class="text-left">
<% displayname %>
<br />
{{ <% timecreated %> | coreToLocaleString }}
</ion-col>
<ion-col col-6 class="text-right">
<button ion-button icon-only clear [core-download-file]="{fileurl: '<% fileurl %>', timemodified: '<% currenttimestamp %>'}" moduleId="<% cmid %>" courseId="<% certificate.course %>" component="mod_customcert">
<ion-icon name="download"></ion-icon>
</button>
<%#canmanage%>
<button ion-button icon-only clear core-site-plugins-call-ws name="mod_customcert_delete_issue"
[params]="{certificateid: <% certificate.id %>, issueid: <% issueid %>}"
[preSets]="{getFromCache: 0, saveToCache: 0, typeExpected: 'boolean'}"
confirmMessage="{{ 'plugin.mod_customcert.deleteissueconfirm' | translate }}"
refreshOnSuccess="true">
<ion-icon name="trash"></ion-icon>
</button>
<%/canmanage%>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
<%/issues%>
</ion-list>
<%/hasissues%>
<%^hasissues%>
<ion-item class="text-center">
{{ 'plugin.mod_customcert.nothingtodisplay' | translate }}
</ion-item>
<%/hasissues%>
</div>

View file

@ -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"
}
}}
{{=<% %>=}}
<div>
<core-course-module-description description="<% certificate.intro %>" component="mod_customcert" componentId="<% cmid %>"></core-course-module-description>
<%#showreport%>
<a ion-item class="text-right" core-site-plugins-new-content component="mod_customcert" method="mobile_view_report" [args]="{cmid: <% cmid %>}">
{{ 'plugin.mod_customcert.viewcustomcertissues' | translate: {$a: <% numissuesinreport %>} }}
</a>
<%/showreport%>
<%#hasissues%>
<%^canmanage%>
<ion-list>
@ -94,4 +111,55 @@
<p>{{ 'plugin.mod_customcert.requiredtimenotmet' | translate: {$a: { requiredtime: <% certificate.requiredtime %>} } }}</p>
</ion-item>
<%/candownload%>
<%#showreport%>
<ion-item>
{{ 'plugin.mod_customcert.listofissues' | translate }}
</ion-item>
<%#showgroups%>
<ion-item>
<ion-label>{{ 'plugin.mod_customcert.selectagroup' | translate }}</ion-label>
<ion-select (ionChange)="updateContent({cmid: <% cmid %>, courseid: <% certificate.course %>, group: $event})" interface="popover">
<%#groups%>
<ion-option value="<% id %>" <%#selected%>selected<%/selected%>><% name %></ion-option>
<%/groups%>
</ion-select>
</ion-item>
<%/showgroups%>
<%#hasrecipients%>
<ion-list>
<%#recipients%>
<ion-item>
<ion-grid>
<ion-row>
<ion-col col-6 class="text-left">
<% displayname %>
<br />
{{ <% timecreated %> | coreToLocaleString }}
</ion-col>
<ion-col col-6 class="text-right">
<button ion-button icon-only clear [core-download-file]="{fileurl: '<% fileurl %>', timemodified: '<% currenttimestamp %>'}" moduleId="<% cmid %>" courseId="<% certificate.course %>" component="mod_customcert">
<ion-icon name="download"></ion-icon>
</button>
<%#canmanage%>
<button ion-button icon-only clear core-site-plugins-call-ws name="mod_customcert_delete_issue"
[params]="{certificateid: <% certificate.id %>, issueid: <% issueid %>}"
[preSets]="{getFromCache: 0, saveToCache: 0, typeExpected: 'boolean'}"
confirmMessage="{{ 'plugin.mod_customcert.deleteissueconfirm' | translate }}"
refreshOnSuccess="true">
<ion-icon name="trash"></ion-icon>
</button>
<%/canmanage%>
</ion-col>
</ion-row>
</ion-grid>
</ion-item>
<%/recipients%>
</ion-list>
<%/hasrecipients%>
<%^hasrecipients%>
<ion-item>
{{ 'plugin.mod_customcert.nothingtodisplay' | translate }}
</ion-item>
<%/hasrecipients%>
<%/showreport%>
</div>

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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"

View file

@ -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,20 +144,27 @@ 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;
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;
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);
@ -128,6 +173,9 @@ if (empty($action)) {
// 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();
}