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 |
namespace core_question\output;
|
|
|
18 |
|
|
|
19 |
use context_course;
|
|
|
20 |
use core_question\local\bank\question_bank_helper;
|
|
|
21 |
use renderer_base;
|
|
|
22 |
use single_button;
|
|
|
23 |
use stdClass;
|
|
|
24 |
|
|
|
25 |
/**
|
|
|
26 |
* Create the management view of shared and non-shared banks.
|
|
|
27 |
*
|
|
|
28 |
* @package core_question
|
|
|
29 |
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
|
|
|
30 |
* @author Simon Adams <simon.adams@catalyst-eu.net>
|
|
|
31 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
32 |
*/
|
|
|
33 |
class view_banks implements \templatable, \renderable {
|
|
|
34 |
|
|
|
35 |
/**
|
|
|
36 |
* Create a new view_banks instance.
|
|
|
37 |
*
|
|
|
38 |
* @param array $sharedbanks {@see question_bank_helper::get_activity_instances_with_shareable_questions()}
|
|
|
39 |
* @param array $privatebanks {@see question_bank_helper::get_activity_instances_with_private_questions()}
|
|
|
40 |
* @param stdClass $course the viewing course.
|
|
|
41 |
*/
|
|
|
42 |
public function __construct(
|
|
|
43 |
/** @var array Banks that can be shared */
|
|
|
44 |
protected readonly array $sharedbanks,
|
|
|
45 |
/** @var array Banks that cannot be shared */
|
|
|
46 |
protected readonly array $privatebanks,
|
|
|
47 |
/** @var stdClass current course object */
|
|
|
48 |
protected readonly stdClass $course,
|
|
|
49 |
) {
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
/**
|
|
|
53 |
* Create a list of shared and non-shared banks for the template.
|
|
|
54 |
*
|
|
|
55 |
* @param renderer_base $output
|
|
|
56 |
* @return array
|
|
|
57 |
*/
|
|
|
58 |
public function export_for_template(renderer_base $output) {
|
|
|
59 |
$sharedbanksrenderable = new question_bank_list($this->sharedbanks);
|
|
|
60 |
$sharedbankscontext = $sharedbanksrenderable->export_for_template($output);
|
|
|
61 |
$privatebanksrenderable = new question_bank_list($this->privatebanks);
|
|
|
62 |
$privatebankscontext = $privatebanksrenderable->export_for_template($output);
|
|
|
63 |
$defaultbankname = question_bank_helper::get_default_question_bank_activity_name();
|
|
|
64 |
$customqbankmods = array_filter(question_bank_helper::get_activity_types_with_shareable_questions(),
|
|
|
65 |
static fn($plugin) => $plugin !== $defaultbankname
|
|
|
66 |
);
|
|
|
67 |
$addqbanklink = new single_button(
|
|
|
68 |
new \moodle_url('/course/modedit.php', [
|
|
|
69 |
'add' => $defaultbankname,
|
|
|
70 |
'course' => $this->course->id,
|
|
|
71 |
'section' => 0,
|
|
|
72 |
'return' => 0,
|
|
|
73 |
'sr' => 0,
|
|
|
74 |
'beforemod' => 0,
|
|
|
75 |
]),
|
|
|
76 |
get_string('add', 'core'),
|
|
|
77 |
'post',
|
|
|
78 |
single_button::BUTTON_PRIMARY
|
|
|
79 |
);
|
|
|
80 |
|
|
|
81 |
$addcustombanksrenderable = new add_bank_list($this->course, $customqbankmods);
|
|
|
82 |
$createdefaultrenderable = new single_button(
|
|
|
83 |
question_bank_helper::get_url_for_qbank_list($this->course->id, true),
|
|
|
84 |
get_string('createdefault', 'question')
|
|
|
85 |
);
|
|
|
86 |
|
|
|
87 |
$cancreatedefault = has_capability('moodle/course:manageactivities', context_course::instance($this->course->id));
|
|
|
88 |
|
|
|
89 |
return [
|
|
|
90 |
'addqbank' => $addqbanklink->export_for_template($output),
|
|
|
91 |
'hassharedbanks' => !empty($sharedbankscontext),
|
|
|
92 |
'sharedbanks' => $sharedbankscontext,
|
|
|
93 |
'hasprivatebanks' => !empty($privatebankscontext),
|
|
|
94 |
'privatebanks' => $privatebankscontext,
|
|
|
95 |
'addcustombanks' => $addcustombanksrenderable->export_for_template($output),
|
|
|
96 |
'createdefault' => $cancreatedefault ? $createdefaultrenderable->export_for_template($output) : false,
|
|
|
97 |
];
|
|
|
98 |
}
|
|
|
99 |
}
|