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 action_link;
|
|
|
20 |
use renderer_base;
|
|
|
21 |
use core_courseformat\output\local\content\cm\controlmenu;
|
|
|
22 |
use core_question\local\bank\question_bank_helper;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Create a list of question bank type links to manage their respective instances.
|
|
|
26 |
*
|
|
|
27 |
* @package core_question
|
|
|
28 |
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
|
|
|
29 |
* @author Simon Adams <simon.adams@catalyst-eu.net>
|
|
|
30 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
31 |
*/
|
|
|
32 |
class question_bank_list implements \renderable, \templatable {
|
|
|
33 |
|
|
|
34 |
/**
|
|
|
35 |
* Instantiate the output class.
|
|
|
36 |
*
|
|
|
37 |
* @param array $bankinstances {@see question_bank_helper::get_activity_instances_with_shareable_questions()}
|
|
|
38 |
*/
|
|
|
39 |
public function __construct(
|
|
|
40 |
/** @var array $bankinstances */
|
|
|
41 |
protected readonly array $bankinstances
|
|
|
42 |
) {
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
/**
|
|
|
46 |
* Create a list of question banks for the template.
|
|
|
47 |
*
|
|
|
48 |
* @param renderer_base $output
|
|
|
49 |
* @return array
|
|
|
50 |
*/
|
|
|
51 |
public function export_for_template(renderer_base $output): array {
|
|
|
52 |
|
|
|
53 |
$banks = [];
|
|
|
54 |
foreach ($this->bankinstances as $instance) {
|
|
|
55 |
if (plugin_supports('mod', $instance->cminfo->modname, FEATURE_PUBLISHES_QUESTIONS)) {
|
|
|
56 |
$returnurl = question_bank_helper::get_url_for_qbank_list($instance->cminfo->course);
|
|
|
57 |
$format = course_get_format($instance->cminfo->course);
|
|
|
58 |
$controlmenu = new controlmenu($format, $instance->cminfo->get_section_info(), $instance->cminfo);
|
|
|
59 |
$controlmenu->set_baseurl($returnurl);
|
|
|
60 |
$actions = $controlmenu->get_cm_control_items();
|
|
|
61 |
$actionmenu = new \action_menu();
|
|
|
62 |
$actionmenu->set_kebab_trigger(get_string('edit'));
|
|
|
63 |
$actionmenu->add_secondary_action($actions['update']);
|
|
|
64 |
$actionmenu->add_secondary_action($actions['assign']);
|
|
|
65 |
$actionmenu->add_secondary_action($actions['delete']);
|
|
|
66 |
$managebankexport = $actionmenu->export_for_template($output);
|
|
|
67 |
} else {
|
|
|
68 |
$managebankexport = null;
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
$managequestions = new action_link(
|
|
|
72 |
new \moodle_url("/mod/{$instance->cminfo->modname}/view.php", [
|
|
|
73 |
'id' => $instance->cminfo->id,
|
|
|
74 |
]),
|
|
|
75 |
$instance->name,
|
|
|
76 |
);
|
|
|
77 |
|
|
|
78 |
$banks[] = [
|
|
|
79 |
'purpose' => plugin_supports('mod', $instance->cminfo->modname, FEATURE_MOD_PURPOSE),
|
|
|
80 |
'iconurl' => $instance->cminfo->get_icon_url(),
|
|
|
81 |
'modname' => $instance->name,
|
|
|
82 |
'description' => $instance->cminfo->get_formatted_content(),
|
|
|
83 |
'managequestions' => $managequestions->export_for_template($output),
|
|
|
84 |
'managebank' => $managebankexport,
|
|
|
85 |
];
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
usort($banks, static fn($a, $b) => $a['modname'] <=> $b['modname']);
|
|
|
89 |
|
|
|
90 |
return $banks;
|
|
|
91 |
}
|
|
|
92 |
}
|