Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
 * This script shows a list of all the question banks in a course.
19
 * It is normally reached from More -> Question banks in the course navigation.
20
 *
21
 * @package    core_question
22
 * @copyright  2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
23
 * @author     Simon Adams <simon.adams@catalyst-eu.net>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
use core_question\local\bank\question_bank_helper;
28
use core_question\local\bank\question_edit_contexts;
29
use core_question\output\view_banks;
30
 
31
require_once(__DIR__ . '/../config.php');
32
 
33
global $CFG, $PAGE, $OUTPUT;
34
 
35
$courseid = required_param('courseid', PARAM_INT);
36
$createdefault = optional_param('createdefault', false, PARAM_BOOL);
37
$course = get_course($courseid);
38
$coursecontext = context_course::instance($course->id);
39
 
40
require_login($course, false);
41
require_capability('moodle/course:manageactivities', \context_course::instance($course->id));
42
 
43
if (empty(question_bank_helper::get_activity_types_with_shareable_questions())) {
44
    throw new moodle_exception('disabledbanks', 'question');
45
}
46
 
47
$allcaps = array_merge(question_edit_contexts::$caps['editq'], question_edit_contexts::$caps['categories']);
48
$sharedbanks = question_bank_helper::get_activity_instances_with_shareable_questions([$course->id], [], $allcaps);
49
$privatebanks = question_bank_helper::get_activity_instances_with_private_questions([$course->id], [], $allcaps);
50
 
51
$pageurl = question_bank_helper::get_url_for_qbank_list($course->id);
52
$PAGE->set_url($pageurl);
53
$PAGE->add_body_class('limitedwidth');
54
$PAGE->set_heading(format_string($course->fullname, true, ['context' => $coursecontext]));
55
$PAGE->set_title(get_string('questionbank_plural', 'question'));
56
 
57
if ($createdefault) {
58
    require_sesskey();
59
    question_bank_helper::create_default_open_instance(
60
        $course,
61
        question_bank_helper::get_bank_name_string('defaultbank', 'core_question', ['coursename' => $course->fullname]),
62
    );
63
    \core\notification::add(get_string('defaultcreated', 'question'), \core\notification::SUCCESS);
64
    redirect($pageurl);
65
}
66
 
67
$output = $PAGE->get_renderer('core_question', 'bank');
68
 
69
echo $output->header();
70
if (!question_bank_helper::has_bank_migration_task_completed_successfully()) {
71
    $defaultactivityname = question_bank_helper::get_default_question_bank_activity_name();
72
    echo $OUTPUT->notification(get_string('transfernotfinished', 'mod_' . $defaultactivityname),
73
        \core\output\notification::NOTIFY_WARNING
74
    );
75
}
76
echo $output->render(new view_banks($sharedbanks, $privatebanks, $course));
77
echo $output->footer();