MDL-67795 contentbank: clean all the content when uninstalling plugin
[moodle.git] / contentbank / view.php
CommitLineData
33b8ca26
AA
1<?php
2// This file is part of 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 * Generic content bank visualizer.
19 *
20 * @package core_contentbank
21 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25require('../config.php');
26
27require_login();
28
29$id = required_param('id', PARAM_INT);
30$record = $DB->get_record('contentbank_content', ['id' => $id], '*', MUST_EXIST);
31$context = context::instance_by_id($record->contextid, MUST_EXIST);
32require_capability('moodle/contentbank:access', $context);
33
34$returnurl = new \moodle_url('/contentbank/index.php');
35$plugin = core_plugin_manager::instance()->get_plugin_info($record->contenttype);
36if (!$plugin || !$plugin->is_enabled()) {
37 print_error('unsupported', 'core_contentbank', $returnurl);
38}
39
40$title = get_string('contentbank');
41\core_contentbank\helper::get_page_ready($context, $title, true);
42if ($PAGE->course) {
43 require_login($PAGE->course->id);
44}
45$returnurl = new \moodle_url('/contentbank/index.php', ['contextid' => $context->id]);
46
47$PAGE->set_url(new \moodle_url('/contentbank/view.php', ['id' => $id]));
48$PAGE->set_context($context);
49$PAGE->navbar->add($record->name);
50$PAGE->set_heading($title);
51$title .= ": ".$record->name;
52$PAGE->set_title($title);
53$PAGE->set_pagetype('contenbank');
54
55echo $OUTPUT->header();
56echo $OUTPUT->box_start('generalbox');
57
58$managerlass = "\\$record->contenttype\\contenttype";
59if (class_exists($managerlass)) {
60 $manager = new $managerlass($context);
61 if ($manager->can_access()) {
62 echo $manager->get_view_content($record);
63 }
64}
65
66echo $OUTPUT->box_end();
67echo $OUTPUT->footer();