| Línea 20... |
Línea 20... |
| 20 |
* @package core
|
20 |
* @package core
|
| 21 |
* @subpackage badges
|
21 |
* @subpackage badges
|
| 22 |
* @copyright 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
|
22 |
* @copyright 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
|
| 23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
| 24 |
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
|
24 |
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
|
| - |
|
25 |
* @deprecated since 4.5. Use badges/index.php instead.
|
| - |
|
26 |
* @todo MDL-82383 This file will be deleted in Moodle 6.0.
|
| 25 |
*/
|
27 |
*/
|
| Línea 26... |
Línea 28... |
| 26 |
|
28 |
|
| 27 |
require_once(__DIR__ . '/../config.php');
|
29 |
require_once(__DIR__ . '/../config.php');
|
| Línea 28... |
Línea 30... |
| 28 |
require_once($CFG->libdir . '/badgeslib.php');
|
30 |
require_once($CFG->libdir . '/badgeslib.php');
|
| 29 |
|
31 |
|
| Línea 30... |
Línea -... |
| 30 |
$type = required_param('type', PARAM_INT);
|
- |
|
| 31 |
$courseid = optional_param('id', 0, PARAM_INT);
|
- |
|
| 32 |
|
- |
|
| 33 |
require_login();
|
- |
|
| 34 |
|
- |
|
| 35 |
if (empty($CFG->enablebadges)) {
|
- |
|
| 36 |
throw new \moodle_exception('badgesdisabled', 'badges');
|
- |
|
| 37 |
}
|
- |
|
| 38 |
|
- |
|
| 39 |
if (empty($CFG->badges_allowcoursebadges) && $courseid != 0) {
|
- |
|
| 40 |
throw new \moodle_exception('coursebadgesdisabled', 'badges');
|
- |
|
| 41 |
}
|
32 |
$type = required_param('type', PARAM_INT);
|
| 42 |
|
- |
|
| 43 |
if ($course = $DB->get_record('course', array('id' => $courseid))) {
|
- |
|
| 44 |
$PAGE->set_url('/badges/view.php', ['type' => $type, 'id' => $course->id]);
|
- |
|
| 45 |
} else {
|
- |
|
| 46 |
$PAGE->set_url('/badges/view.php', ['type' => $type]);
|
- |
|
| 47 |
}
|
- |
|
| 48 |
|
- |
|
| 49 |
$PAGE->add_body_class('limitedwidth');
|
- |
|
| 50 |
|
- |
|
| 51 |
if ($type == BADGE_TYPE_SITE) {
|
- |
|
| 52 |
$PAGE->set_context(context_system::instance());
|
- |
|
| 53 |
$PAGE->set_pagelayout('admin');
|
- |
|
| 54 |
$PAGE->set_heading(get_string('administrationsite'));
|
- |
|
| 55 |
$title = get_string('sitebadges', 'badges');
|
- |
|
| 56 |
$eventotherparams = array('badgetype' => BADGE_TYPE_SITE);
|
- |
|
| 57 |
} else {
|
- |
|
| 58 |
require_login($course);
|
- |
|
| 59 |
$coursename = format_string($course->fullname, true, array('context' => context_course::instance($course->id)));
|
- |
|
| 60 |
$title = get_string('coursebadges', 'badges');
|
- |
|
| 61 |
$PAGE->set_context(context_course::instance($course->id));
|
- |
|
| 62 |
$PAGE->set_pagelayout('incourse');
|
- |
|
| 63 |
$PAGE->set_heading($coursename);
|
- |
|
| 64 |
$eventotherparams = array('badgetype' => BADGE_TYPE_COURSE, 'courseid' => $course->id);
|
- |
|
| 65 |
}
|
- |
|
| 66 |
|
- |
|
| 67 |
require_capability('moodle/badges:viewbadges', $PAGE->context);
|
- |
|
| 68 |
|
- |
|
| 69 |
$PAGE->set_title($title);
|
- |
|
| 70 |
$output = $PAGE->get_renderer('core', 'badges');
|
- |
|
| 71 |
|
- |
|
| 72 |
// Display "Manage badges" button to users with proper capabilities.
|
- |
|
| 73 |
$isfrontpage = (empty($courseid) || $courseid == $SITE->id);
|
- |
|
| 74 |
if ($isfrontpage) {
|
- |
|
| 75 |
$context = context_system::instance();
|
- |
|
| 76 |
} else {
|
- |
|
| 77 |
$context = context_course::instance($courseid);
|
- |
|
| 78 |
}
|
- |
|
| 79 |
$canmanage = has_any_capability(array('moodle/badges:viewawarded',
|
- |
|
| 80 |
'moodle/badges:createbadge',
|
- |
|
| 81 |
'moodle/badges:awardbadge',
|
- |
|
| 82 |
'moodle/badges:configurecriteria',
|
- |
|
| 83 |
'moodle/badges:configuremessages',
|
- |
|
| 84 |
'moodle/badges:configuredetails',
|
- |
|
| 85 |
'moodle/badges:deletebadge'), $context);
|
- |
|
| 86 |
|
- |
|
| 87 |
if ($canmanage) {
|
- |
|
| 88 |
// Check there are non archived badges on the course.
|
- |
|
| 89 |
$allbadgescount = count(badges_get_badges($type, $courseid));
|
- |
|
| 90 |
$canmanage = ($allbadgescount > 0);
|
- |
|
| 91 |
}
|
- |
|
| 92 |
$actionbar = new \core_badges\output\standard_action_bar($PAGE, $type, $canmanage);
|
- |
|
| 93 |
echo $output->header();
|
- |
|
| 94 |
echo $output->render_tertiary_navigation($actionbar);
|
- |
|
| 95 |
echo $OUTPUT->heading($title);
|
- |
|
| 96 |
|
- |
|
| 97 |
if ($course && $course->startdate > time()) {
|
- |
|
| 98 |
echo $OUTPUT->box(get_string('error:notifycoursedate', 'badges'), 'generalbox notifyproblem');
|
- |
|
| 99 |
}
|
- |
|
| 100 |
|
- |
|
| 101 |
$report = \core_reportbuilder\system_report_factory::create(\core_badges\reportbuilder\local\systemreports\course_badges::class,
|
- |
|
| 102 |
$PAGE->context, '', '', 0, ['type' => $type, 'courseid' => $courseid]);
|
- |
|
| 103 |
$report->set_default_no_results_notice(new lang_string('nobadges', 'badges'));
|
- |
|
| 104 |
echo $report->output();
|
- |
|
| 105 |
|
- |
|
| 106 |
// Trigger event, badge listing viewed.
|
- |
|
| 107 |
$eventparams = array('context' => $PAGE->context, 'other' => $eventotherparams);
|
- |
|
| 108 |
$event = \core\event\badge_listing_viewed::create($eventparams);
|
- |
|