on-demand release 3.9dev+
[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);
45192e9a
SA
30$deletecontent = optional_param('deletecontent', null, PARAM_INT);
31
32$PAGE->requires->js_call_amd('core_contentbank/actions', 'init');
33
33b8ca26
AA
34$record = $DB->get_record('contentbank_content', ['id' => $id], '*', MUST_EXIST);
35$context = context::instance_by_id($record->contextid, MUST_EXIST);
36require_capability('moodle/contentbank:access', $context);
37
38$returnurl = new \moodle_url('/contentbank/index.php');
39$plugin = core_plugin_manager::instance()->get_plugin_info($record->contenttype);
40if (!$plugin || !$plugin->is_enabled()) {
41 print_error('unsupported', 'core_contentbank', $returnurl);
42}
43
44$title = get_string('contentbank');
45\core_contentbank\helper::get_page_ready($context, $title, true);
46if ($PAGE->course) {
47 require_login($PAGE->course->id);
48}
49$returnurl = new \moodle_url('/contentbank/index.php', ['contextid' => $context->id]);
50
51$PAGE->set_url(new \moodle_url('/contentbank/view.php', ['id' => $id]));
52$PAGE->set_context($context);
53$PAGE->navbar->add($record->name);
54$PAGE->set_heading($title);
55$title .= ": ".$record->name;
56$PAGE->set_title($title);
57$PAGE->set_pagetype('contenbank');
58
45192e9a
SA
59$contenttypeclass = "\\$record->contenttype\\contenttype";
60$contenttype = new $contenttypeclass($context);
61$contentclass = "\\$record->contenttype\\content";
62$content = new $contentclass($record);
63if ($contenttype->can_delete($content)) {
64 // Create the cog menu with all the secondary actions, such as delete, rename...
65 $actionmenu = new action_menu();
66 $actionmenu->set_alignment(action_menu::TR, action_menu::BR);
67 // Add the delete content item to the menu.
68 $attributes = [
69 'data-action' => 'deletecontent',
70 'data-contentname' => $content->get_name(),
71 'data-contentid' => $content->get_id(),
72 'data-contextid' => $context->id,
73 ];
74 $actionmenu->add_secondary_action(new action_menu_link(
75 new moodle_url('#'),
76 new pix_icon('t/delete', get_string('delete')),
77 get_string('delete'),
78 false,
79 $attributes
80 ));
81
82 // Add the cog menu to the header.
83 $PAGE->add_header_action(html_writer::div(
84 $OUTPUT->render($actionmenu),
85 'd-print-none',
86 ['id' => 'region-main-settings-menu']
87 ));
88}
89
33b8ca26
AA
90echo $OUTPUT->header();
91echo $OUTPUT->box_start('generalbox');
92
45192e9a
SA
93if ($contenttype->can_access()) {
94 echo $contenttype->get_view_content($record);
33b8ca26
AA
95}
96
97echo $OUTPUT->box_end();
98echo $OUTPUT->footer();