Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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
 * Question related functions.
19
 *
20
 * This file was created just because Fragment API expects callbacks to be defined on lib.php
21
 *
22
 * Please, do not add new functions to this file.
23
 *
24
 * @package   core_question
25
 * @copyright 2018 Simey Lameze <simey@moodle.com>
26
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
27
 */
28
 
29
defined('MOODLE_INTERNAL') || die();
30
 
31
require_once($CFG->dirroot . '/question/editlib.php');
32
 
33
/**
34
 * Question data fragment to get the question html via ajax call.
35
 *
36
 * @param array $args Arguments for rendering the fragment. Expected keys:
37
 *  * view - the view class
38
 *  * cmid - if in an activity, the course module ID.
39
 *  * filterquery - the current filters encoded as a URL parameter.
40
 *  * lastchanged - the ID of the last edited question.
41
 *  * sortdata - Array of sorted columns.
42
 *  * filtercondition - the current filters encoded as an object.
43
 *  * extraparams - additional parameters required for a particular view class.
44
 *
45
 * @return array|string
46
 */
47
function core_question_output_fragment_question_data(array $args): string {
48
    if (empty($args)) {
49
        return '';
50
    }
51
    [$params, $extraparams] = \core_question\local\bank\filter_condition_manager::extract_parameters_from_fragment_args($args);
52
    [
53
        $thispageurl,
54
        $contexts,
55
        ,
56
        $cm,
57
        ,
58
        $pagevars
59
    ] = question_build_edit_resources('questions', '/question/edit.php', $params);
60
 
61
    if (is_null($cm)) {
62
        $course = get_course(clean_param($args['courseid'], PARAM_INT));
63
    } else {
64
        $course = get_course($cm->course);
65
    }
66
 
67
    $viewclass = empty($args['view']) ? \core_question\local\bank\view::class : clean_param($args['view'], PARAM_NOTAGS);
68
 
1441 ariadna 69
    // Make sure the class passed through is valid (exists and is view or subclass of view).
70
    if (!class_exists($viewclass) || !is_a($viewclass, \core_question\local\bank\view::class, true)) {
71
        throw new invalid_parameter_exception('view parameter must be a valid view class');
72
    }
73
 
1 efrain 74
    if (!empty($args['lastchanged'])) {
75
        $thispageurl->param('lastchanged', clean_param($args['lastchanged'], PARAM_INT));
76
    }
1441 ariadna 77
    if (!empty($args['view'])) {
78
        $thispageurl->param('view', clean_param($args['view'], PARAM_NOTAGS));
79
    }
80
    if (!empty($args['extraparams'])) {
81
        $thispageurl->param('extraparams', clean_param($args['extraparams'], PARAM_RAW));
82
    }
1 efrain 83
    $questionbank = new $viewclass($contexts, $thispageurl, $course, $cm, $pagevars, $extraparams);
84
    $questionbank->add_standard_search_conditions();
85
    ob_start();
86
    $questionbank->display_question_list();
87
    return ob_get_clean();
88
}
1441 ariadna 89
 
90
/**
91
 * Render and return a category selector for the categories in a given question bank.
92
 *
93
 * @param array $args ['bankcmid' => Course module ID of the question bank]
94
 * @return string The rendered selector.
95
 */
96
function core_question_output_fragment_category_selector(array $args): string {
97
    global $OUTPUT;
98
    $context = \core\context\module::instance($args['bankcmid']);
99
    $selector = new \core_question\output\question_category_selector([$context], autocomplete: true);
100
    return $OUTPUT->render($selector);
101
}