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 |
* This page lists all the instances of customcert in a particular course.
|
|
|
19 |
*
|
|
|
20 |
* @package mod_customcert
|
|
|
21 |
* @copyright 2013 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 |
$id = required_param('id', PARAM_INT); // Course ID.
|
|
|
28 |
|
|
|
29 |
$course = $DB->get_record('course', ['id' => $id], '*', MUST_EXIST);
|
|
|
30 |
|
|
|
31 |
// Requires a login.
|
|
|
32 |
require_login($course);
|
|
|
33 |
|
|
|
34 |
// Set up the page variables.
|
|
|
35 |
$pageurl = new moodle_url('/mod/customcert/index.php', ['id' => $course->id]);
|
|
|
36 |
\mod_customcert\page_helper::page_setup($pageurl, context_course::instance($id),
|
|
|
37 |
get_string('modulenameplural', 'customcert'));
|
|
|
38 |
|
|
|
39 |
// Additional page setup needed.
|
|
|
40 |
$PAGE->set_pagelayout('incourse');
|
|
|
41 |
$PAGE->navbar->add(get_string('modulenameplural', 'customcert'));
|
|
|
42 |
|
|
|
43 |
// Add the page view to the Moodle log.
|
|
|
44 |
$event = \mod_customcert\event\course_module_instance_list_viewed::create([
|
|
|
45 |
'context' => context_course::instance($course->id),
|
|
|
46 |
]);
|
|
|
47 |
$event->add_record_snapshot('course', $course);
|
|
|
48 |
$event->trigger();
|
|
|
49 |
|
|
|
50 |
// Get the customcerts, if there are none display a notice.
|
|
|
51 |
if (!$customcerts = get_all_instances_in_course('customcert', $course)) {
|
|
|
52 |
echo $OUTPUT->header();
|
|
|
53 |
notice(get_string('nocustomcerts', 'customcert'), new moodle_url('/course/view.php', ['id' => $course->id]));
|
|
|
54 |
echo $OUTPUT->footer();
|
|
|
55 |
exit();
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
// Create the table to display the different custom certificates.
|
|
|
59 |
$table = new html_table();
|
|
|
60 |
|
|
|
61 |
if ($usesections = course_format_uses_sections($course->format)) {
|
|
|
62 |
$table->head = [get_string('sectionname', 'format_'.$course->format), get_string('name'),
|
|
|
63 |
get_string('receiveddate', 'customcert')];
|
|
|
64 |
} else {
|
|
|
65 |
$table->head = [get_string('name'), get_string('receiveddate', 'customcert')];
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$currentsection = '';
|
|
|
69 |
foreach ($customcerts as $customcert) {
|
|
|
70 |
// Check if the customcert is visible, if so show text as normal, else show it as dimmed.
|
|
|
71 |
if ($customcert->visible) {
|
|
|
72 |
$link = html_writer::tag('a', $customcert->name, ['href' => new moodle_url('/mod/customcert/view.php',
|
|
|
73 |
['id' => $customcert->coursemodule])]);
|
|
|
74 |
} else {
|
|
|
75 |
$link = html_writer::tag('a', $customcert->name, ['class' => 'dimmed',
|
|
|
76 |
'href' => new moodle_url('/mod/customcert/view.php', ['id' => $customcert->coursemodule])]);
|
|
|
77 |
}
|
|
|
78 |
// If we are at a different section then print a horizontal rule.
|
|
|
79 |
if ($customcert->section !== $currentsection) {
|
|
|
80 |
if ($currentsection !== '') {
|
|
|
81 |
$table->data[] = 'hr';
|
|
|
82 |
}
|
|
|
83 |
$currentsection = $customcert->section;
|
|
|
84 |
}
|
|
|
85 |
// Check if there is was an issue provided for this user.
|
|
|
86 |
if ($certrecord = $DB->get_record('customcert_issues', ['userid' => $USER->id, 'customcertid' => $customcert->id])) {
|
|
|
87 |
$issued = userdate($certrecord->timecreated);
|
|
|
88 |
} else {
|
|
|
89 |
$issued = get_string('notissued', 'customcert');
|
|
|
90 |
}
|
|
|
91 |
// Only display the section column if the course format uses sections.
|
|
|
92 |
if ($usesections) {
|
|
|
93 |
$table->data[] = [$customcert->section, $link, $issued];
|
|
|
94 |
} else {
|
|
|
95 |
$table->data[] = [$link, $issued];
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
echo $OUTPUT->header();
|
|
|
100 |
echo html_writer::table($table);
|
|
|
101 |
echo $OUTPUT->footer();
|