Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 26... Línea 26...
26
namespace mod_quiz\question\bank;
26
namespace mod_quiz\question\bank;
Línea 27... Línea 27...
27
 
27
 
Línea 28... Línea 28...
28
defined('MOODLE_INTERNAL') || die();
28
defined('MOODLE_INTERNAL') || die();
-
 
29
 
29
 
30
use core\output\datafilter;
30
use core\output\datafilter;
31
use core\output\html_writer;
31
use core_question\local\bank\column_base;
32
use core_question\local\bank\column_base;
-
 
33
use core_question\local\bank\condition;
32
use core_question\local\bank\condition;
34
use core_question\local\bank\column_manager_base;
33
use core_question\local\bank\column_manager_base;
-
 
34
use core_question\local\bank\question_version_status;
-
 
Línea 35... Línea 35...
35
use mod_quiz\question\bank\filter\custom_category_condition;
35
use core_question\local\bank\filter_condition_manager;
36
use qbank_managecategories\category_condition;
36
use core_question\local\bank\question_version_status;
37
 
37
 
38
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
38
require_once($CFG->dirroot . '/mod/quiz/locallib.php');
Línea 57... Línea 57...
57
     * @var string $component the component the api is used from.
57
     * @var string $component the component the api is used from.
58
     */
58
     */
59
    public $component = 'mod_quiz';
59
    public $component = 'mod_quiz';
Línea 60... Línea 60...
60
 
60
 
-
 
61
    /**
-
 
62
     * Determine if the 'switch question bank' button must be displayed.
-
 
63
     *
-
 
64
     * @var bool
-
 
65
     */
-
 
66
    protected bool $requirebankswitch;
-
 
67
 
61
    /**
68
    /**
62
     * Constructor.
69
     * Constructor.
63
     * @param \core_question\local\bank\question_edit_contexts $contexts
70
     * @param \core_question\local\bank\question_edit_contexts $contexts
64
     * @param \moodle_url $pageurl
71
     * @param \moodle_url $pageurl
65
     * @param \stdClass $course course settings
72
     * @param \stdClass $course course settings
66
     * @param \stdClass $cm activity settings.
73
     * @param \stdClass $cm activity settings.
67
     * @param \stdClass $quiz quiz settings.
74
     * @param \stdClass $quiz quiz settings.
68
     */
75
     */
69
    public function __construct($contexts, $pageurl, $course, $cm, $params, $extraparams) {
76
    public function __construct($contexts, $pageurl, $course, $cm, $params, $extraparams) {
70
        // Default filter condition.
77
        // Default filter condition.
71
        if (!isset($params['filter'])) {
-
 
72
            $params['filter']  = [];
78
        if (!isset($params['filter'])) {
73
            [$categoryid, $contextid] = custom_category_condition::validate_category_param($params['cat']);
79
            $params['filter']  = filter_condition_manager::get_default_filter($params['cat']);
74
            if (!is_null($categoryid)) {
80
            // The quiz question bank modal doesn't include a hidden filter option.
75
                $category = custom_category_condition::get_category_record($categoryid, $contextid);
81
            // Therefore, the default filter hidden condition is unnecessary.
76
                $params['filter']['category'] = [
-
 
77
                    'jointype' => custom_category_condition::JOINTYPE_DEFAULT,
-
 
78
                    'values' => [$category->id],
-
 
79
                    'filteroptions' => ['includesubcategories' => false],
-
 
80
                ];
-
 
81
            }
82
            unset($params['filter']['hidden']);
Línea 82... Línea 83...
82
        }
83
        }
-
 
84
 
83
 
85
        $this->init_columns($this->wanted_columns(), $this->heading_column());
84
        $this->init_columns($this->wanted_columns(), $this->heading_column());
86
        $this->pagesize = self::DEFAULT_PAGE_SIZE;
85
        parent::__construct($contexts, $pageurl, $course, $cm, $params, $extraparams);
87
        parent::__construct($contexts, $pageurl, $course, $cm, $params, $extraparams);
86
        [$this->quiz, ] = get_module_from_cmid($cm->id);
88
        [$this->quiz, ] = get_module_from_cmid($extraparams['quizcmid']);
87
        $this->set_quiz_has_attempts(quiz_has_attempts($this->quiz->id));
89
        $this->set_quiz_has_attempts(quiz_has_attempts($this->quiz->id));
Línea 88... Línea 90...
88
        $this->pagesize = self::DEFAULT_PAGE_SIZE;
90
        $this->requirebankswitch = $extraparams['requirebankswitch'] ?? true;
89
    }
91
    }
90
 
92
 
Línea 243... Línea 245...
243
        // Build the where clause.
245
        // Build the where clause.
244
        $latestversion = 'qv.version = (SELECT MAX(v.version)
246
        $latestversion = 'qv.version = (SELECT MAX(v.version)
245
                                          FROM {question_versions} v
247
                                          FROM {question_versions} v
246
                                          JOIN {question_bank_entries} be
248
                                          JOIN {question_bank_entries} be
247
                                            ON be.id = v.questionbankentryid
249
                                            ON be.id = v.questionbankentryid
248
                                         WHERE be.id = qbe.id)';
250
                                         WHERE be.id = qbe.id AND v.status <> :substatus)';
-
 
251
 
-
 
252
        // An additional condition is required in the subquery to account for scenarios
-
 
253
        // where the latest version is hidden. This ensures we retrieve the previous
-
 
254
        // "Ready" version instead of the hidden latest version.
249
        $onlyready = '((' . "qv.status = '" . question_version_status::QUESTION_STATUS_READY . "'" .'))';
255
        $onlyready = '((qv.status = :status))';
250
        $this->sqlparams = [];
256
        $this->sqlparams = [
-
 
257
            'status' => question_version_status::QUESTION_STATUS_READY,
-
 
258
            'substatus' => question_version_status::QUESTION_STATUS_HIDDEN,
-
 
259
        ];
251
        $conditions = [];
260
        $conditions = [];
252
        foreach ($this->searchconditions as $searchcondition) {
261
        foreach ($this->searchconditions as $searchcondition) {
253
            if ($searchcondition->where()) {
262
            if ($searchcondition->where()) {
254
                $conditions[] = '((' . $searchcondition->where() .'))';
263
                $conditions[] = '((' . $searchcondition->where() .'))';
255
            }
264
            }
Línea 298... Línea 307...
298
     * @return bool|\stdClass
307
     * @return bool|\stdClass
299
     */
308
     */
300
    public function get_quiz() {
309
    public function get_quiz() {
301
        return $this->quiz;
310
        return $this->quiz;
302
    }
311
    }
-
 
312
 
-
 
313
    /**
-
 
314
     * Shows the question bank interface.
-
 
315
     *
-
 
316
     * @return void
-
 
317
     */
-
 
318
    public function display(): void {
-
 
319
 
-
 
320
        echo \html_writer::start_div('questionbankwindow boxwidthwide boxaligncenter', [
-
 
321
            'data-component' => 'core_question',
-
 
322
            'data-callback' => 'display_question_bank',
-
 
323
            'data-contextid' => $this->contexts->lowest()->id,
-
 
324
        ]);
-
 
325
 
-
 
326
        // Show the 'switch question bank' button.
-
 
327
        echo $this->display_bank_switch();
-
 
328
 
-
 
329
        // Show the filters and search options.
-
 
330
        $this->wanted_filters();
-
 
331
        // Continues with list of questions.
-
 
332
        $this->display_question_list();
-
 
333
        echo \html_writer::end_div();
-
 
334
    }
-
 
335
 
-
 
336
    /**
-
 
337
     * Get the current bank header and bank switch button.
-
 
338
     *
-
 
339
     * @return string
-
 
340
     */
-
 
341
    protected function display_bank_switch(): string {
-
 
342
        global $OUTPUT;
-
 
343
 
-
 
344
        if (!$this->requirebankswitch) {
-
 
345
            return '';
-
 
346
        }
-
 
347
 
-
 
348
        $cminfo = \cm_info::create($this->cm);
-
 
349
 
-
 
350
        return $OUTPUT->render_from_template('mod_quiz/switch_bank_header', ['currentbank' => $cminfo->get_formatted_name()]);
-
 
351
    }
303
}
352
}