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
 * Output class file.
19
 *
20
 * @package    qbank_bulkmove
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 qbank_bulkmove\output;
27
 
28
use cm_info;
29
use core_question\local\bank\question_bank_helper;
30
use core_question\output\question_category_selector;
31
use moodle_url;
32
use renderer_base;
33
use single_button;
34
 
35
/**
36
 * Output class to create a modal template with selects for question banks, question categories, and a move button.
37
 */
38
class bulk_move implements \renderable, \templatable {
39
 
40
    /** @var int The question bank id you are currently moving the question(s) from */
41
    protected int $currentbankid;
42
 
43
    /** @var int The question category id you are moving the question(s) from */
44
    protected int $currentcategoryid;
45
 
46
    /**
47
     * Instantiate the output class.
48
     *
49
     * @param int $currentbankid
50
     * @param int $currentcategoryid
51
     */
52
    public function __construct(int $currentbankid, int $currentcategoryid) {
53
        $this->currentbankid = $currentbankid;
54
        $this->currentcategoryid = $currentcategoryid;
55
    }
56
 
57
    /**
58
     * Export data for use by the template.
59
     *
60
     * @param renderer_base $output
61
     * @return array
62
     */
63
    public function export_for_template(renderer_base $output) {
64
 
65
        [, $cmrec] = get_module_from_cmid($this->currentbankid);
66
        $currentbankcm = cm_info::create($cmrec);
67
 
68
        // Get the current bank and its categories. All other banks and categories will be loaded dynamically.
69
        if (plugin_supports('mod', $currentbankcm->modname, FEATURE_PUBLISHES_QUESTIONS, false)) {
70
            $banktorender = question_bank_helper::get_activity_instances_with_shareable_questions(
71
                havingcap: ['moodle/question:add'],
72
                currentbankid: $this->currentbankid,
73
                filtercontext: $currentbankcm->context,
74
                limit: 1,
75
            )[0];
76
        } else {
77
            $banktorender = question_bank_helper::get_activity_instances_with_private_questions(
78
                incourseids: [$currentbankcm->course],
79
                havingcap: ['moodle/question:add'],
80
                currentbankid: $this->currentbankid,
81
                filtercontext: $currentbankcm->context,
82
            )[0];
83
        }
84
 
85
        $categoryselector = new question_category_selector([$currentbankcm->context], autocomplete: true);
86
 
87
        $savebutton = new single_button(
88
            new moodle_url('#'),
89
            get_string('movequestions', 'qbank_bulkmove'),
90
            'post',
91
            single_button::BUTTON_PRIMARY,
92
            [
93
                'data-action' => 'bulkmovesave',
94
                'disabled' => 'disabled',
95
            ]
96
        );
97
 
98
        return [
99
            'bank' => $banktorender,
100
            'categories' => $categoryselector->export_for_template($output),
101
            'save' => $savebutton->export_for_template($output),
102
            'contextid' => $currentbankcm->context->id,
103
        ];
104
    }
105
}