Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * Helper class for adding/editing a question.
19
 *
20
 * This code is based on question/editlib.php by Martin Dougiamas.
21
 *
22
 * @package    qbank_editquestion
23
 * @copyright  2021 Catalyst IT Australia Pty Ltd
24
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
 
28
namespace qbank_editquestion;
29
 
30
use core_question\local\bank\question_version_status;
31
use qbank_editquestion\output\add_new_question;
32
 
33
/**
34
 * Class editquestion_helper for methods related to add/edit/copy
35
 *
36
 * @package    qbank_editquestion
37
 * @copyright  2021 Catalyst IT Australia Pty Ltd
38
 * @author     Safat Shahin <safatshahin@catalyst-au.net>
39
 */
40
class editquestion_helper {
41
 
42
    /**
43
     * Print a form to let the user choose which question type to add.
44
     * When the form is submitted, it goes to the question.php script.
45
     *
46
     * @param array|null $hiddenparams hidden parameters to add to the form, in addition to
47
     *      the qtype radio buttons.
48
     * @param array|null $allowedqtypes optional list of qtypes that are allowed. If given, only
49
     *      those qtypes will be shown. Example value array('description', 'multichoice').
50
     * @param bool $enablejs
51
     * @return bool|string
52
     */
53
    public static function print_choose_qtype_to_add_form(array $hiddenparams, array $allowedqtypes = null, $enablejs = true) {
54
        global $PAGE;
55
 
56
        $chooser = \qbank_editquestion\qbank_chooser::get($PAGE->course, $hiddenparams, $allowedqtypes);
57
        $renderer = $PAGE->get_renderer('qbank_editquestion');
58
 
59
        return $renderer->render($chooser);
60
    }
61
 
62
    /**
63
     * Print a button for creating a new question. This will open question/addquestion.php,
64
     * which in turn goes to question/question.php before getting back to $params['returnurl']
65
     * (by default the question bank screen).
66
     *
67
     * @param int $categoryid The id of the category that the new question should be added to.
68
     * @param array $params Other paramters to add to the URL. You need either $params['cmid'] or
69
     *      $params['courseid'], and you should probably set $params['returnurl']
70
     * @param bool $canadd the text to display on the button.
71
     * @param string $tooltip a tooltip to add to the button (optional).
72
     * @param bool $disabled if true, the button will be disabled.
73
     * @deprecated since Moodle 4.3. Use {@see add_new_question} renderable instead
74
     * @todo Final deprecation in Moodle 4.7
75
     */
76
    public static function create_new_question_button($categoryid, $params, $canadd, $tooltip = '', $disabled = false) {
77
        global $OUTPUT;
78
        debugging('create_new_question_button() is deprecated. Use the add_new_question renderable instead.');
79
        return $OUTPUT->render(new add_new_question($categoryid, $params, $canadd));
80
    }
81
 
82
    /**
83
     * Get the string for the status of the question.
84
     *
85
     * @param string $status
86
     * @return string
87
     */
88
    public static function get_question_status_string($status): string {
89
        return get_string('questionstatus' . $status, 'qbank_editquestion');
90
    }
91
 
92
    /**
93
     * Get the array of status of the questions.
94
     *
95
     * @return array
96
     */
97
    public static function get_question_status_list(): array {
98
        $statuslist = [];
99
        $statuslist[question_version_status::QUESTION_STATUS_READY] = get_string('questionstatusready', 'qbank_editquestion');
100
        $statuslist[question_version_status::QUESTION_STATUS_DRAFT] = get_string('questionstatusdraft', 'qbank_editquestion');
101
        return $statuslist;
102
    }
103
 
104
}