2020-04-01 16:23:33 +02:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List content in content bank.
|
|
|
|
*
|
|
|
|
* @package core_contentbank
|
|
|
|
* @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
*/
|
|
|
|
|
|
|
|
require('../config.php');
|
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
$contextid = optional_param('contextid', \context_system::instance()->id, PARAM_INT);
|
2020-04-15 09:15:15 +02:00
|
|
|
$search = optional_param('search', '', PARAM_CLEAN);
|
2020-04-01 16:23:33 +02:00
|
|
|
$context = context::instance_by_id($contextid, MUST_EXIST);
|
|
|
|
|
2020-09-16 17:10:39 +02:00
|
|
|
$cb = new \core_contentbank\contentbank();
|
|
|
|
if (!$cb->is_context_allowed($context)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('contextnotallowed', 'core_contentbank');
|
2020-09-16 17:10:39 +02:00
|
|
|
}
|
|
|
|
|
2020-04-01 16:23:33 +02:00
|
|
|
require_capability('moodle/contentbank:access', $context);
|
|
|
|
|
2020-06-16 16:23:39 +02:00
|
|
|
$statusmsg = optional_param('statusmsg', '', PARAM_ALPHANUMEXT);
|
|
|
|
$errormsg = optional_param('errormsg', '', PARAM_ALPHANUMEXT);
|
2020-04-16 15:04:37 +02:00
|
|
|
|
2020-04-01 16:23:33 +02:00
|
|
|
$title = get_string('contentbank');
|
|
|
|
\core_contentbank\helper::get_page_ready($context, $title);
|
|
|
|
if ($PAGE->course) {
|
|
|
|
require_login($PAGE->course->id);
|
|
|
|
}
|
2022-05-03 16:28:01 +02:00
|
|
|
$PAGE->set_url('/contentbank/index.php', ['contextid' => $contextid]);
|
2021-12-10 12:28:47 +08:00
|
|
|
if ($contextid == \context_system::instance()->id) {
|
|
|
|
$PAGE->set_context(context_course::instance($contextid));
|
|
|
|
} else {
|
|
|
|
$PAGE->set_context($context);
|
|
|
|
}
|
2022-02-22 17:02:32 +08:00
|
|
|
|
|
|
|
if ($context->contextlevel == CONTEXT_COURSECAT) {
|
|
|
|
$PAGE->set_primary_active_tab('home');
|
|
|
|
}
|
|
|
|
|
2020-04-01 16:23:33 +02:00
|
|
|
$PAGE->set_title($title);
|
2021-10-04 16:57:04 +02:00
|
|
|
$PAGE->add_body_class('limitedwidth');
|
2020-06-15 13:35:43 +02:00
|
|
|
$PAGE->set_pagetype('contentbank');
|
2021-12-09 14:43:56 +08:00
|
|
|
$PAGE->set_secondary_active_tab('contentbank');
|
2020-04-01 16:23:33 +02:00
|
|
|
|
2020-04-28 18:27:16 +02:00
|
|
|
// Get all contents managed by active plugins where the user has permission to render them.
|
|
|
|
$contenttypes = [];
|
|
|
|
$enabledcontenttypes = $cb->get_enabled_content_types();
|
|
|
|
foreach ($enabledcontenttypes as $contenttypename) {
|
|
|
|
$contenttypeclass = "\\contenttype_$contenttypename\\contenttype";
|
|
|
|
$contenttype = new $contenttypeclass($context);
|
|
|
|
if ($contenttype->can_access()) {
|
|
|
|
$contenttypes[] = $contenttypename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$foldercontents = $cb->search_contents($search, $contextid, $contenttypes);
|
2020-04-01 16:23:33 +02:00
|
|
|
|
|
|
|
// Get the toolbar ready.
|
|
|
|
$toolbar = array ();
|
2020-04-29 14:00:43 +01:00
|
|
|
|
|
|
|
// Place the Add button in the toolbar.
|
|
|
|
if (has_capability('moodle/contentbank:useeditor', $context)) {
|
|
|
|
// Get the content types for which the user can use an editor.
|
|
|
|
$editabletypes = $cb->get_contenttypes_with_capability_feature(\core_contentbank\contenttype::CAN_EDIT, $context);
|
|
|
|
if (!empty($editabletypes)) {
|
|
|
|
// Editor base URL.
|
|
|
|
$editbaseurl = new moodle_url('/contentbank/edit.php', ['contextid' => $contextid]);
|
2020-05-28 19:59:06 +02:00
|
|
|
$toolbar[] = [
|
|
|
|
'name' => get_string('add'),
|
|
|
|
'link' => $editbaseurl, 'dropdown' => true,
|
|
|
|
'contenttypes' => $editabletypes,
|
|
|
|
'action' => 'add'
|
|
|
|
];
|
2020-04-29 14:00:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Place the Upload button in the toolbar.
|
2020-04-01 16:23:33 +02:00
|
|
|
if (has_capability('moodle/contentbank:upload', $context)) {
|
|
|
|
// Don' show upload button if there's no plugin to support any file extension.
|
|
|
|
$accepted = $cb->get_supported_extensions_as_string($context);
|
|
|
|
if (!empty($accepted)) {
|
2021-03-18 12:51:03 +01:00
|
|
|
$importurl = new moodle_url('/contentbank/index.php', ['contextid' => $contextid]);
|
2020-05-28 19:59:06 +02:00
|
|
|
$toolbar[] = [
|
|
|
|
'name' => get_string('upload', 'contentbank'),
|
2021-03-18 12:51:03 +01:00
|
|
|
'link' => $importurl->out(false),
|
2020-05-28 19:59:06 +02:00
|
|
|
'icon' => 'i/upload',
|
|
|
|
'action' => 'upload'
|
|
|
|
];
|
2021-03-18 12:51:03 +01:00
|
|
|
$PAGE->requires->js_call_amd(
|
|
|
|
'core_contentbank/upload',
|
|
|
|
'initModal',
|
|
|
|
['[data-action=upload]', \core_contentbank\form\upload_files::class, $contextid]
|
|
|
|
);
|
2020-04-01 16:23:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
2022-02-09 09:31:56 +08:00
|
|
|
echo $OUTPUT->heading($title, 2);
|
2020-04-01 16:23:33 +02:00
|
|
|
echo $OUTPUT->box_start('generalbox');
|
|
|
|
|
2020-04-16 15:04:37 +02:00
|
|
|
// If needed, display notifications.
|
2020-06-16 16:23:39 +02:00
|
|
|
if ($errormsg !== '' && get_string_manager()->string_exists($errormsg, 'core_contentbank')) {
|
|
|
|
$errormsg = get_string($errormsg, 'core_contentbank');
|
2020-04-16 15:04:37 +02:00
|
|
|
echo $OUTPUT->notification($errormsg);
|
2020-06-16 16:23:39 +02:00
|
|
|
} else if ($statusmsg !== '' && get_string_manager()->string_exists($statusmsg, 'core_contentbank')) {
|
|
|
|
$statusmsg = get_string($statusmsg, 'core_contentbank');
|
2020-04-16 15:04:37 +02:00
|
|
|
echo $OUTPUT->notification($statusmsg, 'notifysuccess');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render the contentbank contents.
|
2021-09-27 08:19:38 +02:00
|
|
|
$folder = new \core_contentbank\output\bankcontent($foldercontents, $toolbar, $context, $cb);
|
2020-04-01 16:23:33 +02:00
|
|
|
echo $OUTPUT->render($folder);
|
|
|
|
|
|
|
|
echo $OUTPUT->box_end();
|
|
|
|
echo $OUTPUT->footer();
|