Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of the customcert module for Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
/**
18
 * Handles viewing the certificates for a certain user.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2016 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once('../../config.php');
26
 
27
$userid = optional_param('userid', $USER->id, PARAM_INT);
28
$download = optional_param('download', null, PARAM_ALPHA);
29
$courseid = optional_param('course', null, PARAM_INT);
30
$downloadcert = optional_param('downloadcert', '', PARAM_BOOL);
31
if ($downloadcert) {
32
    $certificateid = required_param('certificateid', PARAM_INT);
33
    $customcert = $DB->get_record('customcert', ['id' => $certificateid], '*', MUST_EXIST);
34
 
35
    // Check there exists an issued certificate for this user.
36
    if (!$issue = $DB->get_record('customcert_issues', ['userid' => $userid, 'customcertid' => $customcert->id])) {
37
        throw new moodle_exception('You have not been issued a certificate');
38
    }
39
}
40
$page = optional_param('page', 0, PARAM_INT);
41
$perpage = optional_param('perpage', \mod_customcert\certificate::CUSTOMCERT_PER_PAGE, PARAM_INT);
42
$pageurl = $url = new moodle_url('/mod/customcert/my_certificates.php', ['userid' => $userid,
43
    'page' => $page, 'perpage' => $perpage]);
44
 
45
// Requires a login.
46
if ($courseid) {
47
    require_login($courseid);
48
} else {
49
    require_login();
50
}
51
 
52
// Check that we have a valid user.
53
$user = \core_user::get_user($userid, '*', MUST_EXIST);
54
 
55
// If we are viewing certificates that are not for the currently logged in user then do a capability check.
56
if (($userid != $USER->id) && !has_capability('mod/customcert:viewallcertificates', context_system::instance())) {
57
    throw new moodle_exception('You are not allowed to view these certificates');
58
}
59
 
60
$PAGE->set_url($pageurl);
61
$PAGE->set_context(context_user::instance($userid));
62
$PAGE->set_title(get_string('mycertificates', 'customcert'));
63
$PAGE->set_pagelayout('standard');
64
$PAGE->navigation->extend_for_user($user);
65
 
66
// Check if we requested to download a certificate.
67
if ($downloadcert) {
68
    $template = $DB->get_record('customcert_templates', ['id' => $customcert->templateid], '*', MUST_EXIST);
69
    $template = new \mod_customcert\template($template);
70
    $template->generate_pdf(false, $userid);
71
    exit();
72
}
73
 
74
$table = new \mod_customcert\my_certificates_table($userid, $download);
75
$table->define_baseurl($pageurl);
76
 
77
if ($table->is_downloading()) {
78
    $table->download();
79
    exit();
80
}
81
 
82
// Additional page setup.
83
$PAGE->navbar->add(get_string('profile'), new moodle_url('/user/profile.php', ['id' => $userid]));
84
$PAGE->navbar->add(get_string('mycertificates', 'customcert'));
85
 
86
echo $OUTPUT->header();
87
echo $OUTPUT->heading(get_string('mycertificates', 'customcert'));
88
echo html_writer::div(get_string('mycertificatesdescription', 'customcert'));
89
$table->out($perpage, false);
90
echo $OUTPUT->footer();