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 |
* core_question output class.
|
|
|
19 |
*
|
|
|
20 |
* @package core_question
|
|
|
21 |
* @copyright 2024 onwards Catalyst IT EU {@link https://catalyst-eu.net}
|
|
|
22 |
* @author Simon Adams <simon.adams@catalyst-eu.net>
|
|
|
23 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
24 |
*/
|
|
|
25 |
|
|
|
26 |
namespace core_question\output;
|
|
|
27 |
|
|
|
28 |
use cm_info;
|
|
|
29 |
use core_question\local\bank\question_bank_helper;
|
|
|
30 |
use renderer_base;
|
|
|
31 |
|
|
|
32 |
/**
|
|
|
33 |
* Get the switch question bank rendered content. Displays lists of shared banks the viewing user has access to.
|
|
|
34 |
*/
|
|
|
35 |
class switch_question_bank implements \renderable, \templatable {
|
|
|
36 |
|
|
|
37 |
/**
|
|
|
38 |
* Instantiate the output class.
|
|
|
39 |
*
|
|
|
40 |
* @param int $quizcmid quiz course module id.
|
|
|
41 |
* @param int $courseid of the current course.
|
|
|
42 |
* @param int $userid of the user viewing the page.
|
|
|
43 |
*/
|
|
|
44 |
public function __construct(
|
|
|
45 |
/** @var int quiz course module id */
|
|
|
46 |
private readonly int $quizcmid,
|
|
|
47 |
/** @var int id of the current course */
|
|
|
48 |
private readonly int $courseid,
|
|
|
49 |
/** @var int id of the user viewing the page */
|
|
|
50 |
private readonly int $userid
|
|
|
51 |
) {
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/**
|
|
|
55 |
* Create a list of question banks the user has access to for the template.
|
|
|
56 |
*
|
|
|
57 |
* @param renderer_base $output
|
|
|
58 |
* @return array
|
|
|
59 |
*/
|
|
|
60 |
public function export_for_template(renderer_base $output) {
|
|
|
61 |
|
|
|
62 |
[, $cm] = get_module_from_cmid($this->quizcmid);
|
|
|
63 |
$cminfo = cm_info::create($cm);
|
|
|
64 |
|
|
|
65 |
$capabilities = ['moodle/question:useall', 'moodle/question:usemine'];
|
|
|
66 |
$coursesharedbanks = question_bank_helper::get_activity_instances_with_shareable_questions(
|
|
|
67 |
incourseids: [$this->courseid],
|
|
|
68 |
havingcap: $capabilities,
|
|
|
69 |
filtercontext: $cminfo->context,
|
|
|
70 |
);
|
|
|
71 |
$recentlyviewedbanks = question_bank_helper::get_recently_used_open_banks($this->userid, havingcap: $capabilities);
|
|
|
72 |
|
|
|
73 |
return [
|
|
|
74 |
'quizname' => $cminfo->get_formatted_name(),
|
|
|
75 |
'quizcmid' => $this->quizcmid,
|
|
|
76 |
'quizcontextid' => $cminfo->context->id,
|
|
|
77 |
'hascoursesharedbanks' => !empty($coursesharedbanks),
|
|
|
78 |
'coursesharedbanks' => $coursesharedbanks,
|
|
|
79 |
'hasrecentlyviewedbanks' => !empty($recentlyviewedbanks),
|
|
|
80 |
'recentlyviewedbanks' => $recentlyviewedbanks,
|
|
|
81 |
];
|
|
|
82 |
}
|
|
|
83 |
}
|