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
namespace core_question\output;
18
 
19
use action_link;
20
use core_question\local\bank\question_bank_helper;
21
use renderer_base;
22
use stdClass;
23
 
24
/**
25
 * Create a list of 'Add another question bank' links for plugins that support FEATURE_PUBLISHES_QUESTIONS.
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 add_bank_list implements \renderable, \templatable {
33
 
34
    /**
35
     * Instantiate the output class.
36
     *
37
     * @param stdClass $course the course currently being viewed.
38
     * @param array $bankplugins {@see question_bank_helper::get_activity_types_with_shareable_questions()}
39
     */
40
    public function __construct(
41
        /** @var stdClass $course the viewing course */
42
        protected readonly stdClass $course,
43
        /** @var array $bankplugins shareable bank type plugins */
44
        protected readonly array $bankplugins
45
    ) {
46
    }
47
 
48
    /**
49
     * Dynamically create an 'add' link for each module type that supports FEATURE_PUBLISHES_QUESTIONS.
50
     *
51
     * @param renderer_base $output
52
     * @return array
53
     */
54
    public function export_for_template(renderer_base $output): array {
55
 
56
        $addbanks = [];
57
 
58
        foreach ($this->bankplugins as $plugin) {
59
 
60
            if (!plugin_supports('mod', $plugin, FEATURE_PUBLISHES_QUESTIONS)) {
61
                continue;
62
            }
63
 
64
            $link = new action_link(
65
                new \moodle_url('/course/modedit.php', [
66
                    'add' => $plugin,
67
                    'course' => $this->course->id,
68
                    'section' => 0,
69
                    'return' => 0,
70
                    'sr' => 0,
71
                    'beforemod' => 0,
72
                ]),
73
                get_string('addanotherbank', $plugin),
74
                null,
75
                null,
76
                new \pix_icon('t/add', get_string('addanotherbank', $plugin))
77
            );
78
            $addbanks[] = $link->export_for_template($output);
79
        }
80
 
81
        return $addbanks;
82
    }
83
}