Proyectos de Subversion Moodle

Rev

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

Rev 11 Rev 1441
Línea 27... Línea 27...
27
defined('MOODLE_INTERNAL') || die();
27
defined('MOODLE_INTERNAL') || die();
Línea 28... Línea 28...
28
 
28
 
Línea 29... Línea 29...
29
require_once($CFG->dirroot . '/question/editlib.php');
29
require_once($CFG->dirroot . '/question/editlib.php');
30
 
-
 
31
use coding_exception;
30
 
32
use core\plugininfo\qbank;
-
 
33
use core\output\datafilter;
31
use coding_exception;
34
use core_plugin_manager;
32
use core\output\datafilter;
35
use core_question\local\bank\condition;
33
use core_question\local\bank\condition;
36
use core_question\local\statistics\statistics_bulk_loader;
34
use core_question\local\statistics\statistics_bulk_loader;
37
use core_question\output\question_bank_filter_ui;
-
 
38
use core_question\local\bank\column_manager_base;
-
 
39
use qbank_deletequestion\hidden_condition;
35
use core_question\output\question_bank_filter_ui;
Línea 40... Línea 36...
40
use qbank_editquestion\editquestion_helper;
36
use core_question\local\bank\column_manager_base;
41
use qbank_managecategories\category_condition;
37
use qbank_managecategories\category_condition;
42
 
38
 
Línea 177... Línea 173...
177
     * @var string url of the new question page.
173
     * @var string url of the new question page.
178
     */
174
     */
179
    public $returnurl;
175
    public $returnurl;
Línea 180... Línea 176...
180
 
176
 
181
    /**
177
    /**
182
     * @var array $bulkactions to identify the bulk actions for the api.
178
     * @var bulk_action_base[] $bulkactions bulk actions for the api.
183
     */
179
     */
Línea 184... Línea 180...
184
    public $bulkactions = [];
180
    public $bulkactions = [];
185
 
181
 
Línea 233... Línea 229...
233
        $this->baseurl = $pageurl;
229
        $this->baseurl = $pageurl;
234
        $this->course = $course;
230
        $this->course = $course;
235
        $this->cm = $cm;
231
        $this->cm = $cm;
236
        $this->extraparams = $extraparams;
232
        $this->extraparams = $extraparams;
Línea -... Línea 233...
-
 
233
 
-
 
234
        // Add the default qperpage to extra params array so we can switch back and forth between it and "all".
-
 
235
        $this->extraparams['defaultqperpage'] = $this->pagesize;
-
 
236
        $this->extraparams['maxqperpage'] = MAXIMUM_QUESTIONS_PER_PAGE;
-
 
237
 
-
 
238
        if ($cm === null) {
-
 
239
            debugging('Passing $cm to the view constructor is now required.', DEBUG_DEVELOPER);
-
 
240
        }
237
 
241
 
238
        // Default filter condition.
242
        // Default filter condition.
239
        if (!isset($params['filter']) && isset($params['cat'])) {
-
 
240
            $params['filter']  = [];
243
        if (!isset($params['filter']) && isset($params['cat'])) {
241
            [$categoryid, $contextid] = category_condition::validate_category_param($params['cat']);
-
 
242
            if (!is_null($categoryid)) {
-
 
243
                $category = category_condition::get_category_record($categoryid, $contextid);
-
 
244
                $params['filter']['category'] = [
-
 
245
                    'jointype' => category_condition::JOINTYPE_DEFAULT,
-
 
246
                    'values' => [$category->id],
-
 
247
                    'filteroptions' => ['includesubcategories' => false],
-
 
248
                ];
-
 
249
            }
-
 
250
            $params['filter']['hidden'] = [
-
 
251
                'jointype' => hidden_condition::JOINTYPE_DEFAULT,
-
 
252
                'values' => [0],
-
 
253
            ];
244
            $params['filter']  = filter_condition_manager::get_default_filter($params['cat']);
254
            $params['jointype'] = datafilter::JOINTYPE_ALL;
245
            $params['jointype'] = datafilter::JOINTYPE_ALL;
255
        }
246
        }
256
        if (!empty($params['filter'])) {
247
        if (!empty($params['filter'])) {
257
            $params['filter'] = filter_condition_manager::unpack_filteroptions_param($params['filter']);
248
            $params['filter'] = filter_condition_manager::unpack_filteroptions_param($params['filter']);
Línea 262... Línea 253...
262
        }
253
        }
Línea 263... Línea 254...
263
 
254
 
264
        // Create the url of the new question page to forward to.
255
        // Create the url of the new question page to forward to.
265
        $this->returnurl = $pageurl->out_as_local_url(false);
256
        $this->returnurl = $pageurl->out_as_local_url(false);
266
        $this->editquestionurl = new \moodle_url('/question/bank/editquestion/question.php', ['returnurl' => $this->returnurl]);
-
 
267
        if ($this->cm !== null) {
257
        $this->editquestionurl = new \moodle_url('/question/bank/editquestion/question.php', ['returnurl' => $this->returnurl]);
268
            $this->editquestionurl->param('cmid', $this->cm->id);
-
 
269
        } else {
-
 
270
            $this->editquestionurl->param('courseid', $this->course->id);
-
 
Línea 271... Línea 258...
271
        }
258
        $this->editquestionurl->param('cmid', $this->cm->id);
Línea 272... Línea 259...
272
 
259
 
273
        $this->lastchangedid = clean_param($pageurl->param('lastchanged'), PARAM_INT);
260
        $this->lastchangedid = clean_param($pageurl->param('lastchanged'), PARAM_INT);
Línea 278... Línea 265...
278
        $this->set_pagevars($params);
265
        $this->set_pagevars($params);
279
        $this->init_columns($this->wanted_columns(), $this->heading_column());
266
        $this->init_columns($this->wanted_columns(), $this->heading_column());
280
        $this->init_question_actions();
267
        $this->init_question_actions();
281
        $this->init_sort();
268
        $this->init_sort();
282
        $this->init_bulk_actions();
269
        $this->init_bulk_actions();
-
 
270
 
-
 
271
        // Record that this question bank has been used.
-
 
272
        question_bank_helper::add_bank_context_to_recently_viewed($contexts->lowest());
283
    }
273
    }
Línea 284... Línea 274...
284
 
274
 
285
    /**
275
    /**
286
     * Get an array of plugin features objects for all enabled qbank plugins.
276
     * Get an array of plugin features objects for all enabled qbank plugins.
Línea 319... Línea 309...
319
    /**
309
    /**
320
     * Initialize bulk actions.
310
     * Initialize bulk actions.
321
     */
311
     */
322
    protected function init_bulk_actions(): void {
312
    protected function init_bulk_actions(): void {
323
        foreach ($this->plugins as $componentname => $plugin) {
313
        foreach ($this->plugins as $componentname => $plugin) {
324
            $bulkactions = $plugin->get_bulk_actions();
314
            $bulkactions = $plugin->get_bulk_actions($this);
325
            if (!is_array($bulkactions)) {
315
            if (!is_array($bulkactions)) {
326
                debugging("The method {$componentname}::get_bulk_actions() must return an " .
316
                debugging("The method {$componentname}::get_bulk_actions() must return an " .
327
                    "array of bulk actions instead of a single bulk action. " .
317
                    "array of bulk actions instead of a single bulk action. " .
328
                    "Please update your implementation of get_bulk_actions() to return an array. " .
318
                    "Please update your implementation of get_bulk_actions() to return an array. " .
329
                    "Check out the qbank_bulkmove plugin for a working example.", DEBUG_DEVELOPER);
319
                    "Check out the qbank_bulkmove plugin for a working example.", DEBUG_DEVELOPER);
330
                $bulkactions = [$bulkactions];
320
                $bulkactions = [$bulkactions];
331
            }
321
            }
Línea 332... Línea 322...
332
 
322
 
333
            foreach ($bulkactions as $bulkactionobject) {
323
            foreach ($bulkactions as $bulkactionobject) {
334
                $this->bulkactions[$bulkactionobject->get_key()] = [
-
 
335
                    'title' => $bulkactionobject->get_bulk_action_title(),
-
 
336
                    'url' => $bulkactionobject->get_bulk_action_url(),
-
 
337
                    'capabilities' => $bulkactionobject->get_bulk_action_capabilities()
-
 
338
                ];
324
                $this->bulkactions[$bulkactionobject->get_key()] = $bulkactionobject;
339
            }
325
            }
340
        }
326
        }
Línea 341... Línea 327...
341
    }
327
    }
342
 
-
 
343
    /**
-
 
344
     * Initialize search conditions from plugins
-
 
345
     * local_*_get_question_bank_search_conditions() must return an array of
-
 
346
     * \core_question\bank\search\condition objects.
328
 
347
     *
-
 
348
     * @deprecated Since Moodle 4.3
329
    /**
-
 
330
     * @deprecated Since Moodle 4.3
-
 
331
     */
-
 
332
    #[\core\attribute\deprecated(
-
 
333
        'create a qbank plugin and implement a filter object',
-
 
334
        since: '4.3',
-
 
335
        mdl: 'MDL-72321',
349
     * @todo Final deprecation on Moodle 4.7 MDL-78090
336
        final: true
350
     */
-
 
351
    protected function init_search_conditions(): void {
-
 
352
        debugging(
-
 
353
            'Function init_search_conditions() has been deprecated, please create a qbank plugin' .
-
 
354
                'and implement a filter object instead.',
-
 
355
            DEBUG_DEVELOPER
-
 
356
        );
-
 
357
        $searchplugins = get_plugin_list_with_function('local', 'get_question_bank_search_conditions');
337
    )]
358
        foreach ($searchplugins as $component => $function) {
-
 
359
            foreach ($function($this) as $searchobject) {
-
 
360
                $this->add_searchcondition($searchobject);
-
 
361
            }
338
    protected function init_search_conditions(): void {
Línea 362... Línea 339...
362
        }
339
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
363
    }
340
    }
364
 
341
 
Línea 574... Línea 551...
574
     * @return array [$colname, $subsort].
551
     * @return array [$colname, $subsort].
575
     */
552
     */
576
    protected function parse_subsort($sort): array {
553
    protected function parse_subsort($sort): array {
577
        // Do the parsing.
554
        // Do the parsing.
578
        if (strpos($sort, '-') !== false) {
555
        if (strpos($sort, '-') !== false) {
579
            list($colname, $subsort) = explode('-', $sort, 2);
556
            [$colname, $subsort] = explode('-', $sort, 2);
580
        } else {
557
        } else {
581
            $colname = $sort;
558
            $colname = $sort;
582
            $subsort = '';
559
            $subsort = '';
583
        }
560
        }
584
        $colname = str_replace('__', '\\', $colname);
561
        $colname = str_replace('__', '\\', $colname);
Línea 612... Línea 589...
612
        }
589
        }
613
        return $params;
590
        return $params;
614
    }
591
    }
Línea 615... Línea 592...
615
 
592
 
616
    /**
593
    /**
-
 
594
     * Get the default sort columns for this view of the question bank.
-
 
595
     *
-
 
596
     * The array keys in the return value need be the standard keys used
-
 
597
     * to represent sorts. That is [plugin_frankenstyle]__[class_name] and then
-
 
598
     * and optional bit like '-name' if the column supports muliple ways of sorting.
-
 
599
     *
-
 
600
     * The array values should be one of the constants SORT_ASC or SORT_DESC for the default order.
-
 
601
     *
-
 
602
     * Therefore, the default implementation below is a good example.
617
     * Default sort for question data.
603
     *
618
     * @return int[]
604
     * @return int[] sort key => SORT_ASC or SORT_DESC.
619
     */
605
     */
620
    protected function default_sort(): array {
606
    protected function default_sort(): array {
621
        $defaultsort = [];
607
        $defaultsort = [];
622
        if (class_exists('\\qbank_viewquestiontype\\question_type_column')) {
608
        if (class_exists('\\qbank_viewquestiontype\\question_type_column')) {
Línea 743... Línea 729...
743
        $sorts = [];
729
        $sorts = [];
744
        foreach ($this->sort as $sortname => $sortorder) {
730
        foreach ($this->sort as $sortname => $sortorder) {
745
            [$colname, $subsort] = $this->parse_subsort($sortname);
731
            [$colname, $subsort] = $this->parse_subsort($sortname);
746
            $sorts[] = $this->requiredcolumns[$colname]->sort_expression($sortorder == SORT_DESC, $subsort);
732
            $sorts[] = $this->requiredcolumns[$colname]->sort_expression($sortorder == SORT_DESC, $subsort);
747
        }
733
        }
748
 
-
 
749
        // Build the where clause.
-
 
750
        $latestversion = 'qv.version = (SELECT MAX(v.version)
-
 
751
                                          FROM {question_versions} v
-
 
752
                                          JOIN {question_bank_entries} be
-
 
753
                                            ON be.id = v.questionbankentryid
-
 
754
                                         WHERE be.id = qbe.id)';
-
 
755
        $this->sqlparams = [];
734
        $this->sqlparams = [];
756
        $conditions = [];
735
        $conditions = [];
-
 
736
        $showhiddenquestion = true;
-
 
737
        // Build the where clause.
757
        foreach ($this->searchconditions as $searchcondition) {
738
        foreach ($this->searchconditions as $searchcondition) {
-
 
739
            // This is nasty hack to check if the filter is using "Show hidden question" option.
-
 
740
            if (array_key_exists('hidden_condition', $searchcondition->params())) {
-
 
741
                $showhiddenquestion = false;
-
 
742
            }
758
            if ($searchcondition->where()) {
743
            if ($searchcondition->where()) {
759
                $conditions[] = '((' . $searchcondition->where() .'))';
744
                $conditions[] = '((' . $searchcondition->where() .'))';
760
            }
745
            }
761
            if ($searchcondition->params()) {
746
            if ($searchcondition->params()) {
762
                $this->sqlparams = array_merge($this->sqlparams, $searchcondition->params());
747
                $this->sqlparams = array_merge($this->sqlparams, $searchcondition->params());
763
            }
748
            }
764
        }
749
        }
-
 
750
        $extracondition = '';
-
 
751
        if (!$showhiddenquestion) {
-
 
752
            // If Show hidden question option is off, then we need get the latest version that is not hidden.
-
 
753
            $extracondition = ' AND v.status <> :hiddenstatus';
-
 
754
            $this->sqlparams = array_merge($this->sqlparams, ['hiddenstatus' => question_version_status::QUESTION_STATUS_HIDDEN]);
-
 
755
        }
-
 
756
        $latestversion = "qv.version = (SELECT MAX(v.version)
-
 
757
                                          FROM {question_versions} v
-
 
758
                                          JOIN {question_bank_entries} be
-
 
759
                                            ON be.id = v.questionbankentryid
-
 
760
                                         WHERE be.id = qbe.id $extracondition)";
-
 
761
 
765
        // Get higher level filter condition.
762
        // Get higher level filter condition.
766
        $jointype = isset($this->pagevars['jointype']) ? (int)$this->pagevars['jointype'] : condition::JOINTYPE_DEFAULT;
763
        $jointype = isset($this->pagevars['jointype']) ? (int)$this->pagevars['jointype'] : condition::JOINTYPE_DEFAULT;
767
        $nonecondition = ($jointype === datafilter::JOINTYPE_NONE) ? ' NOT ' : '';
764
        $nonecondition = ($jointype === datafilter::JOINTYPE_NONE) ? ' NOT ' : '';
768
        $separator = ($jointype === datafilter::JOINTYPE_ALL) ? ' AND ' : ' OR ';
765
        $separator = ($jointype === datafilter::JOINTYPE_ALL) ? ' AND ' : ' OR ';
769
        // Build the SQL.
766
        // Build the SQL.
Línea 796... Línea 793...
796
     *
793
     *
797
     * @return \moodle_recordset questionid => data about each question.
794
     * @return \moodle_recordset questionid => data about each question.
798
     */
795
     */
799
    protected function load_page_questions(): \moodle_recordset {
796
    protected function load_page_questions(): \moodle_recordset {
800
        global $DB;
797
        global $DB;
-
 
798
 
-
 
799
        // Load the questions based on the page we are on.
801
        $questions = $DB->get_recordset_sql($this->loadsql, $this->sqlparams,
800
        $questions = $DB->get_recordset_sql($this->loadsql, $this->sqlparams,
802
            (int)$this->pagevars['qpage'] * (int)$this->pagevars['qperpage'], $this->pagevars['qperpage']);
801
            (int)$this->pagevars['qpage'] * (int)$this->pagevars['qperpage'], (int)$this->pagevars['qperpage']);
-
 
802
 
803
        if (empty($questions)) {
803
        if (!$questions->valid()) {
804
            $questions->close();
804
            $questions->close();
805
            // No questions on this page. Reset to page 0.
805
            // No questions on this page. Reset to the nearest page that contains questions.
-
 
806
            $this->pagevars['qpage'] = max(0,
-
 
807
                ceil($this->totalcount / (int)$this->pagevars['qperpage']) - 1);
806
            $questions = $DB->get_recordset_sql($this->loadsql, $this->sqlparams, 0, $this->pagevars['qperpage']);
808
            $questions = $DB->get_recordset_sql($this->loadsql, $this->sqlparams,
-
 
809
                (int)$this->pagevars['qpage'] * (int)$this->pagevars['qperpage'], (int)$this->pagevars['qperpage']);
807
        }
810
        }
808
        return $questions;
811
        return $questions;
809
    }
812
    }
Línea 810... Línea 813...
810
 
813
 
Línea 863... Línea 866...
863
    public function get_most_specific_context(): \context {
866
    public function get_most_specific_context(): \context {
864
        return $this->contexts->lowest();
867
        return $this->contexts->lowest();
865
    }
868
    }
Línea 866... Línea 869...
866
 
869
 
867
    /**
-
 
868
     * @deprecated since Moodle 4.0
-
 
869
     */
-
 
870
    public function preview_question_url() {
-
 
871
        throw new coding_exception(__FUNCTION__ . '() has been removed.');
-
 
872
    }
-
 
873
 
-
 
874
    /**
870
    /**
875
     * Get fields from the pagevars array.
871
     * Get fields from the pagevars array.
876
     *
872
     *
877
     * If a field is specified, that particlar pagevars field will be returned. Otherwise the entire array will be returned.
873
     * If a field is specified, that particlar pagevars field will be returned. Otherwise the entire array will be returned.
878
     *
874
     *
Línea 938... Línea 934...
938
                $this->extraparams);
934
                $this->extraparams);
939
        echo $OUTPUT->render($filter);
935
        echo $OUTPUT->render($filter);
940
    }
936
    }
Línea 941... Línea 937...
941
 
937
 
942
    /**
-
 
943
     * Print the text if category id not available.
-
 
944
     *
938
    /**
945
     * @deprecated since Moodle 4.3 MDL-72321
-
 
946
     * @todo Final deprecation on Moodle 4.7 MDL-78090
939
     * @deprecated since Moodle 4.3 MDL-72321
-
 
940
     */
-
 
941
    #[\core\attribute\deprecated(
-
 
942
        'question/bank/managecategories/classes/category_confition.php',
-
 
943
        since: '4.3',
-
 
944
        mdl: 'MDL-72321',
-
 
945
        final: true
947
     */
946
    )]
948
    protected function print_choose_category_message(): void {
-
 
949
        debugging(
-
 
950
            'Function print_choose_category_message() is deprecated, all the features for this method is currently ' .
-
 
951
                'handled by the qbank filter api, please have a look at ' .
-
 
952
                'question/bank/managecategories/classes/category_confition.php for more information.',
-
 
953
            DEBUG_DEVELOPER
-
 
954
        );
-
 
955
        echo \html_writer::start_tag('p', ['style' => "\"text-align:center;\""]);
947
    protected function print_choose_category_message(): void {
956
        echo \html_writer::tag('b', get_string('selectcategoryabove', 'question'));
-
 
957
        echo \html_writer::end_tag('p');
948
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 958... Línea 949...
958
    }
949
    }
959
 
-
 
960
    /**
-
 
961
     * Gets current selected category.
-
 
962
     * @param string $categoryandcontext
-
 
963
     * @return false|mixed|\stdClass
950
 
964
     *
-
 
965
     * @deprecated since Moodle 4.3 MDL-72321
951
    /**
-
 
952
     * @deprecated since Moodle 4.3 MDL-72321
-
 
953
     */
-
 
954
    #[\core\attribute\deprecated(
-
 
955
        'question/bank/managecategories/classes/category_confition.php',
-
 
956
        since: '4.3',
-
 
957
        mdl: 'MDL-72321',
966
     * @todo Final deprecation on Moodle 4.7 MDL-78090
958
        final: true
967
     */
-
 
968
    protected function get_current_category($categoryandcontext) {
-
 
969
        debugging(
-
 
970
            'Function get_current_category() is deprecated, all the features for this method is currently handled by ' .
-
 
971
            'the qbank filter api, please have a look at question/bank/managecategories/classes/category_confition.php ' .
-
 
972
            'for more information.',
-
 
973
            DEBUG_DEVELOPER
-
 
974
        );
-
 
975
        global $DB, $OUTPUT;
-
 
976
        list($categoryid, $contextid) = explode(',', $categoryandcontext);
-
 
977
        if (!$categoryid) {
-
 
978
            $this->print_choose_category_message();
-
 
979
            return false;
-
 
980
        }
-
 
981
 
-
 
982
        if (!$category = $DB->get_record('question_categories',
-
 
983
            ['id' => $categoryid, 'contextid' => $contextid])) {
959
    )]
984
            echo $OUTPUT->box_start('generalbox questionbank');
-
 
985
            echo $OUTPUT->notification('Category not found!');
-
 
986
            echo $OUTPUT->box_end();
-
 
987
            return false;
-
 
988
        }
-
 
989
 
960
    protected function get_current_category($categoryandcontext) {
Línea 990... Línea 961...
990
        return $category;
961
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
991
    }
-
 
992
 
-
 
993
    /**
-
 
994
     * Display the form with options for which questions are displayed and how they are displayed.
962
    }
995
     *
-
 
996
     * @param bool $showquestiontext Display the text of the question within the list.
963
 
-
 
964
    /**
997
     * @deprecated since Moodle 4.3 MDL-72321
965
     * @deprecated since Moodle 4.3 MDL-72321
998
     * @todo Final deprecation on Moodle 4.7 MDL-78090
-
 
999
     */
-
 
1000
    protected function display_options_form($showquestiontext): void {
-
 
1001
        debugging(
-
 
1002
            'Function display_options_form() is deprecated, this method has been replaced with mustaches in filters, ' .
-
 
1003
                'please use filtering objects',
-
 
1004
            DEBUG_DEVELOPER
-
 
1005
        );
-
 
1006
        global $PAGE;
-
 
1007
 
-
 
1008
        // The html will be refactored in the filter feature implementation.
-
 
1009
        echo \html_writer::start_tag('form', ['method' => 'get',
-
 
1010
            'action' => new \moodle_url($this->baseurl), 'id' => 'displayoptions']);
-
 
1011
        echo \html_writer::start_div();
-
 
1012
 
-
 
1013
        $excludes = ['recurse', 'showhidden', 'qbshowtext'];
-
 
1014
        // If the URL contains any tags then we need to prevent them
-
 
1015
        // being added to the form as hidden elements because the tags
-
 
1016
        // are managed separately.
-
 
1017
        if ($this->baseurl->param('qtagids[0]')) {
-
 
1018
            $index = 0;
-
 
1019
            while ($this->baseurl->param("qtagids[{$index}]")) {
-
 
1020
                $excludes[] = "qtagids[{$index}]";
-
 
1021
                $index++;
966
     */
1022
            }
-
 
1023
        }
-
 
1024
        echo \html_writer::input_hidden_params($this->baseurl, $excludes);
-
 
1025
 
-
 
1026
        $advancedsearch = [];
-
 
1027
 
-
 
1028
        foreach ($this->searchconditions as $searchcondition) {
-
 
1029
            if ($searchcondition->display_options_adv()) {
-
 
1030
                $advancedsearch[] = $searchcondition;
-
 
1031
            }
-
 
1032
        }
-
 
1033
        if (!empty($advancedsearch)) {
-
 
1034
            $this->display_advanced_search_form($advancedsearch);
-
 
1035
        }
-
 
1036
 
-
 
1037
        $go = \html_writer::empty_tag('input', ['type' => 'submit', 'value' => get_string('go')]);
-
 
1038
        echo \html_writer::tag('noscript', \html_writer::div($go), ['class' => 'inline']);
-
 
1039
        echo \html_writer::end_div();
967
    #[\core\attribute\deprecated('filtering objects', since: '4.3', mdl: 'MDL-72321', final: true)]
Línea 1040... Línea 968...
1040
        echo \html_writer::end_tag('form');
968
    protected function display_options_form($showquestiontext): void {
1041
        $PAGE->requires->yui_module('moodle-question-searchform', 'M.question.searchform.init');
-
 
1042
    }
-
 
1043
 
-
 
1044
    /**
969
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
1045
     * Print the "advanced" UI elements for the form to select which questions. Hidden by default.
-
 
1046
     *
970
    }
-
 
971
 
1047
     * @param array $advancedsearch
972
    /**
1048
     * @deprecated since Moodle 4.3 MDL-72321
-
 
1049
     * @todo Final deprecation on Moodle 4.7 MDL-78090
-
 
1050
     */
-
 
1051
    protected function display_advanced_search_form($advancedsearch): void {
-
 
1052
        debugging(
-
 
1053
            'Function display_advanced_search_form() is deprecated, this method has been replaced with mustaches in ' .
-
 
1054
            'filters, please use filtering objects',
-
 
1055
            DEBUG_DEVELOPER
-
 
1056
        );
-
 
1057
        print_collapsible_region_start('', 'advancedsearch',
973
     * @deprecated since Moodle 4.3 MDL-72321
1058
            get_string('advancedsearchoptions', 'question'),
-
 
1059
            'question_bank_advanced_search');
-
 
1060
        foreach ($advancedsearch as $searchcondition) {
974
     */
Línea 1061... Línea 975...
1061
            echo $searchcondition->display_options_adv();
975
    #[\core\attribute\deprecated('filtering objects', since: '4.3', mdl: 'MDL-72321', final: true)]
1062
        }
-
 
1063
        print_collapsible_region_end();
-
 
1064
    }
976
    protected function display_advanced_search_form($advancedsearch): void {
1065
 
-
 
1066
    /**
977
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
-
 
978
    }
1067
     * Display the checkbox UI for toggling the display of the question text in the list.
979
 
1068
     * @param bool $showquestiontext the current or default value for whether to display the text.
-
 
1069
     * @deprecated since Moodle 4.3 MDL-72321
-
 
1070
     * @todo Final deprecation on Moodle 4.7 MDL-78090
-
 
1071
     */
-
 
1072
    protected function display_showtext_checkbox($showquestiontext): void {
-
 
1073
        debugging('Function display_showtext_checkbox() is deprecated, please use filtering objects', DEBUG_DEVELOPER);
980
    /**
1074
        global $PAGE;
-
 
1075
        $displaydata = [
-
 
1076
            'checked' => $showquestiontext
-
 
1077
        ];
-
 
1078
        if (class_exists('qbank_viewquestiontext\\question_text_row')) {
981
     * @deprecated since Moodle 4.3 MDL-72321
Línea 1079... Línea 982...
1079
            if (\core\plugininfo\qbank::is_plugin_enabled('qbank_viewquestiontext')) {
982
     */
1080
                echo $PAGE->get_renderer('core_question', 'bank')->render_showtext_checkbox($displaydata);
983
    #[\core\attribute\deprecated('filtering objects', since: '4.3', mdl: 'MDL-72321', final: true)]
1081
            }
984
    protected function display_showtext_checkbox($showquestiontext): void {
Línea 1137... Línea 1040...
1137
    public function display_question_list(): void {
1040
    public function display_question_list(): void {
1138
        // This function can be moderately slow with large question counts and may time out.
1041
        // This function can be moderately slow with large question counts and may time out.
1139
        // We probably do not want to raise it to unlimited, so randomly picking 5 minutes.
1042
        // We probably do not want to raise it to unlimited, so randomly picking 5 minutes.
1140
        // Note: We do not call this in the loop because quiz ob_ captures this function (see raise() PHP doc).
1043
        // Note: We do not call this in the loop because quiz ob_ captures this function (see raise() PHP doc).
1141
        \core_php_time_limit::raise(300);
1044
        \core_php_time_limit::raise(300);
-
 
1045
        raise_memory_limit(MEMORY_EXTRA);
Línea 1142... Línea 1046...
1142
 
1046
 
1143
        [$categoryid, $contextid] = category_condition::validate_category_param($this->pagevars['cat']);
1047
        [$categoryid, $contextid] = category_condition::validate_category_param($this->pagevars['cat']);
-
 
1048
        $catcontext = \context::instance_by_id($contextid);
-
 
1049
        // Update the question in the list with correct category context when we have selected category filter.
-
 
1050
        if (isset($this->pagevars['filter']['category']['values'])) {
-
 
1051
            $categoryid = $this->pagevars['filter']['category']['values'][0];
-
 
1052
            foreach ($this->contexts->all() as $context) {
-
 
1053
                if ((int) $context->instanceid === (int) $categoryid) {
-
 
1054
                    $catcontext = $context;
-
 
1055
                    break;
-
 
1056
                }
-
 
1057
            }
Línea 1144... Línea 1058...
1144
        $catcontext = \context::instance_by_id($contextid);
1058
        }
1145
 
1059
 
1146
        echo \html_writer::start_tag(
1060
        echo \html_writer::start_tag(
1147
            'div',
1061
            'div',
Línea 1152... Línea 1066...
1152
                'data-contextid' => $this->get_most_specific_context()->id,
1066
                'data-contextid' => $this->get_most_specific_context()->id,
1153
            ]
1067
            ]
1154
        );
1068
        );
1155
        echo $this->get_plugin_controls($catcontext, $categoryid);
1069
        echo $this->get_plugin_controls($catcontext, $categoryid);
Línea 1156... Línea -...
1156
 
-
 
1157
        $this->build_query();
1070
 
1158
        $questionsrs = $this->load_page_questions();
-
 
1159
        $totalquestions = $this->get_question_count();
-
 
1160
        $questions = [];
-
 
1161
        foreach ($questionsrs as $question) {
-
 
1162
            if (!empty($question->id)) {
-
 
1163
                $questions[$question->id] = $question;
-
 
1164
            }
-
 
1165
        }
-
 
Línea 1166... Línea 1071...
1166
        $questionsrs->close();
1071
        $questions = $this->load_questions();
1167
 
1072
 
1168
        // This html will be refactored in the bulk actions implementation.
1073
        // This html will be refactored in the bulk actions implementation.
1169
        echo \html_writer::start_tag('form', ['action' => $this->baseurl, 'method' => 'post', 'id' => 'questionsubmit']);
1074
        echo \html_writer::start_tag('form', ['action' => $this->baseurl, 'method' => 'post', 'id' => 'questionsubmit']);
-
 
1075
        echo \html_writer::start_tag('fieldset', ['class' => 'invisiblefieldset', 'style' => "display: block;"]);
1170
        echo \html_writer::start_tag('fieldset', ['class' => 'invisiblefieldset', 'style' => "display: block;"]);
1076
        echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]);
Línea 1171... Línea 1077...
1171
        echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'sesskey', 'value' => sesskey()]);
1077
        echo \html_writer::empty_tag('input', ['type' => 'hidden', 'name' => 'addonpage']);
1172
        echo \html_writer::input_hidden_params($this->baseurl);
1078
        echo \html_writer::input_hidden_params($this->baseurl);
1173
 
1079
 
1174
        $filtercondition = json_encode($this->get_pagevars());
1080
        $filtercondition = json_encode($this->get_pagevars());
1175
        // Embeded filterconditon into the div.
1081
        // Embeded filterconditon into the div.
1176
        echo \html_writer::start_tag('div',
1082
        echo \html_writer::start_tag('div',
1177
            ['class' => 'categoryquestionscontainer', 'data-filtercondition' => $filtercondition]);
1083
            ['class' => 'categoryquestionscontainer', 'data-filtercondition' => $filtercondition]);
Línea 1178... Línea 1084...
1178
        if ($totalquestions > 0) {
1084
        if ($this->totalcount > 0) {
1179
            // Bulk load any required statistics.
1085
            // Bulk load any required statistics.
Línea 1325... Línea 1231...
1325
            $returnurl = new \moodle_url($this->base_url(), ['filter' => json_encode($this->pagevars['filter'])]);
1231
            $returnurl = new \moodle_url($this->base_url(), ['filter' => json_encode($this->pagevars['filter'])]);
1326
            $params['returnurl'] = $returnurl;
1232
            $params['returnurl'] = $returnurl;
1327
            foreach ($this->bulkactions as $key => $action) {
1233
            foreach ($this->bulkactions as $key => $action) {
1328
                // Check capabilities.
1234
                // Check capabilities.
1329
                $capcount = 0;
1235
                $capcount = 0;
1330
                foreach ($action['capabilities'] as $capability) {
1236
                foreach ($action->get_bulk_action_capabilities() as $capability) {
1331
                    if (has_capability($capability, $catcontext)) {
1237
                    if (has_capability($capability, $catcontext)) {
1332
                        $capcount ++;
1238
                        $capcount ++;
1333
                    }
1239
                    }
1334
                }
1240
                }
1335
                // At least one cap need to be there.
1241
                // At least one cap need to be there.
1336
                if ($capcount === 0) {
1242
                if ($capcount === 0) {
1337
                    unset($this->bulkactions[$key]);
1243
                    unset($this->bulkactions[$key]);
1338
                    continue;
1244
                    continue;
1339
                }
1245
                }
1340
                $actiondata = new \stdClass();
1246
                $actiondata = new \stdClass();
1341
                $actiondata->actionname = $action['title'];
1247
                $actiondata->actionname = $action->get_bulk_action_title();
1342
                $actiondata->actionkey = $key;
1248
                $actiondata->actionkey = $key;
1343
                $actiondata->actionurl = new \moodle_url($action['url'], $params);
1249
                $actiondata->actionurl = new \moodle_url($action->get_bulk_action_url(), $params);
1344
                $bulkactiondata[] = $actiondata;
1250
                $bulkactiondata[] = $actiondata;
Línea 1345... Línea 1251...
1345
 
1251
 
1346
                $bulkactiondatas ['bulkactionitems'] = $bulkactiondata;
1252
                $bulkactiondatas ['bulkactionitems'] = $bulkactiondata;
1347
            }
1253
            }
Línea 1351... Línea 1257...
1351
            }
1257
            }
1352
        }
1258
        }
1353
    }
1259
    }
Línea 1354... Línea 1260...
1354
 
1260
 
-
 
1261
    /**
-
 
1262
     * Give each bulk action a chance to load its own javascript module.
-
 
1263
     * @return void
-
 
1264
     */
-
 
1265
    public function init_bulk_actions_js(): void {
-
 
1266
        foreach ($this->bulkactions as $action) {
-
 
1267
            $action->initialise_javascript();
-
 
1268
        }
-
 
1269
    }
-
 
1270
 
1355
    /**
1271
    /**
1356
     * Display the questions.
1272
     * Display the questions.
1357
     *
1273
     *
1358
     * @param array $questions
1274
     * @param array $questions
1359
     */
1275
     */
Línea 1386... Línea 1302...
1386
     *
1302
     *
1387
     * @return array
1303
     * @return array
1388
     */
1304
     */
1389
    public function load_questions() {
1305
    public function load_questions() {
1390
        $this->build_query();
1306
        $this->build_query();
-
 
1307
        $this->get_question_count();
1391
        $questionsrs = $this->load_page_questions();
1308
        $questionsrs = $this->load_page_questions();
1392
        $questions = [];
1309
        $questions = [];
1393
        foreach ($questionsrs as $question) {
1310
        foreach ($questionsrs as $question) {
1394
            if (!empty($question->id)) {
1311
            if (!empty($question->id)) {
1395
                $questions[$question->id] = $question;
1312
                $questions[$question->id] = $question;
Línea 1409... Línea 1326...
1409
     */
1326
     */
1410
    protected function print_table($questions): void {
1327
    protected function print_table($questions): void {
1411
        // Start of the table.
1328
        // Start of the table.
1412
        echo \html_writer::start_tag('table', [
1329
        echo \html_writer::start_tag('table', [
1413
            'id' => 'categoryquestions',
1330
            'id' => 'categoryquestions',
1414
            'class' => 'question-bank-table generaltable',
1331
            'class' => 'question-bank-table table generaltable',
1415
            'data-defaultsort' => json_encode($this->sort),
1332
            'data-defaultsort' => json_encode($this->sort),
1416
        ]);
1333
        ]);
Línea 1417... Línea 1334...
1417
 
1334
 
1418
        // Prints the table header.
1335
        // Prints the table header.
Línea 1434... Línea 1351...
1434
        // End of the table.
1351
        // End of the table.
1435
        echo \html_writer::end_tag('table');
1352
        echo \html_writer::end_tag('table');
1436
    }
1353
    }
Línea 1437... Línea 1354...
1437
 
1354
 
1438
    /**
-
 
1439
     * Start of the table html.
-
 
1440
     *
-
 
1441
     * @see print_table()
1355
    /**
1442
     * @deprecated since Moodle 4.3 MDL-72321
-
 
1443
     * @todo Final deprecation on Moodle 4.7 MDL-78090
1356
     * @deprecated since Moodle 4.3 MDL-72321
-
 
1357
     */
1444
     */
1358
    #[\core\attribute\deprecated('print_table()', since: '4.3', mdl: 'MDL-72321', final: true)]
1445
    protected function start_table() {
-
 
1446
        debugging('Function start_table() is deprecated, please use print_table() instead.', DEBUG_DEVELOPER);
1359
    protected function start_table() {
1447
        echo '<table id="categoryquestions" class="table table-responsive">' . "\n";
-
 
1448
        echo "<thead>\n";
-
 
1449
        $this->print_table_headers();
-
 
1450
        echo "</thead>\n";
-
 
1451
        echo "<tbody>\n";
1360
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 1452... Línea 1361...
1452
    }
1361
    }
1453
 
-
 
1454
    /**
-
 
1455
     * End of the table html.
-
 
1456
     *
1362
 
1457
     * @see print_table()
-
 
1458
     * @deprecated since Moodle 4.3 MDL-72321
1363
    /**
-
 
1364
     * @deprecated since Moodle 4.3 MDL-72321
1459
     * @todo Final deprecation on Moodle 4.7 MDL-78090
1365
     */
1460
     */
1366
    #[\core\attribute\deprecated('print_table()', since: '4.3', mdl: 'MDL-72321', final: true)]
1461
    protected function end_table() {
-
 
1462
        debugging('Function end_table() is deprecated, please use print_table() instead.', DEBUG_DEVELOPER);
-
 
1463
        echo "</tbody>\n";
1367
    protected function end_table() {
Línea 1464... Línea 1368...
1464
        echo "</table>\n";
1368
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
1465
    }
1369
    }
1466
 
1370
 
Línea 1501... Línea 1405...
1501
     * @param int $rowcount
1405
     * @param int $rowcount
1502
     */
1406
     */
1503
    public function print_table_row($question, $rowcount): void {
1407
    public function print_table_row($question, $rowcount): void {
1504
        $rowclasses = implode(' ', $this->get_row_classes($question, $rowcount));
1408
        $rowclasses = implode(' ', $this->get_row_classes($question, $rowcount));
1505
        $attributes = [];
1409
        $attributes = [];
-
 
1410
 
-
 
1411
        // If the question type is invalid we highlight it red.
-
 
1412
        if (!\question_bank::is_qtype_usable($question->qtype)) {
-
 
1413
            $rowclasses .= ' table-danger';
-
 
1414
        }
1506
        if ($rowclasses) {
1415
        if ($rowclasses) {
1507
            $attributes['class'] = $rowclasses;
1416
            $attributes['class'] = $rowclasses;
1508
        }
1417
        }
1509
        echo \html_writer::start_tag('tr', $attributes);
1418
        echo \html_writer::start_tag('tr', $attributes);
1510
        foreach ($this->visiblecolumns as $column) {
1419
        foreach ($this->visiblecolumns as $column) {
Línea 1515... Línea 1424...
1515
            $row->display($question, $rowclasses);
1424
            $row->display($question, $rowclasses);
1516
        }
1425
        }
1517
    }
1426
    }
Línea 1518... Línea 1427...
1518
 
1427
 
1519
    /**
-
 
1520
     * @deprecated since Moodle 4.0
-
 
1521
     */
-
 
1522
    public function process_actions(): void {
-
 
1523
        throw new coding_exception(__FUNCTION__ . '() has been removed.');
-
 
1524
    }
-
 
1525
 
-
 
1526
    /**
-
 
1527
     * @deprecated since Moodle 4.0
-
 
1528
     */
-
 
1529
    public function process_actions_needing_ui() {
-
 
1530
        throw new coding_exception(__FUNCTION__ . '() has been removed.');
-
 
1531
    }
-
 
1532
 
-
 
1533
    /**
1428
    /**
1534
     * Add another search control to this view.
1429
     * Add another search control to this view.
1535
     * @param condition $searchcondition the condition to add.
1430
     * @param condition $searchcondition the condition to add.
1536
     * @param string|null $fieldname
1431
     * @param string|null $fieldname
1537
     */
1432
     */
Línea 1591... Línea 1486...
1591
     * @return string HTML for the question table
1486
     * @return string HTML for the question table
1592
     */
1487
     */
1593
    public function display_questions_table(): string {
1488
    public function display_questions_table(): string {
1594
        $this->add_standard_search_conditions();
1489
        $this->add_standard_search_conditions();
1595
        $questions = $this->load_questions();
1490
        $questions = $this->load_questions();
1596
        $totalquestions = $this->get_question_count();
-
 
1597
        $questionhtml = '';
1491
        $questionhtml = '';
1598
        if ($totalquestions > 0) {
1492
        if ($this->get_question_count() > 0) {
1599
            $this->load_required_statistics($questions);
1493
            $this->load_required_statistics($questions);
1600
            ob_start();
1494
            ob_start();
1601
            $this->display_questions($questions, $this->pagevars['qpage'], $this->pagevars['qperpage']);
1495
            $this->display_questions($questions, $this->pagevars['qpage'], $this->pagevars['qperpage']);
1602
            $questionhtml = ob_get_clean();
1496
            $questionhtml = ob_get_clean();
1603
        }
1497
        }