Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 30... Línea 30...
30
 */
30
 */
31
class category_condition extends condition {
31
class category_condition extends condition {
32
    /** @var \stdClass The course record. */
32
    /** @var \stdClass The course record. */
33
    protected $course;
33
    protected $course;
Línea -... Línea 34...
-
 
34
 
-
 
35
    /** @var \stdClass The course_modules record. */
-
 
36
    protected \stdClass $cm;
34
 
37
 
35
    /** @var \stdClass The category record. */
38
    /** @var \stdClass The category record. */
Línea 36... Línea 39...
36
    protected $category;
39
    protected $category;
37
 
40
 
Línea 50... Línea 53...
50
    /**
53
    /**
51
     * Constructor to initialize the category filter condition.
54
     * Constructor to initialize the category filter condition.
52
     *
55
     *
53
     * @param view $qbank qbank view
56
     * @param view $qbank qbank view
54
     */
57
     */
55
    public function __construct(view $qbank = null) {
58
    public function __construct(?view $qbank = null) {
56
        if (is_null($qbank)) {
59
        if (is_null($qbank)) {
57
            return;
60
            return;
58
        }
61
        }
59
        $this->cat = $qbank->get_pagevars('cat');
62
        $this->cat = $qbank->get_pagevars('cat');
60
        $this->contexts = $qbank->contexts->having_one_edit_tab_cap($qbank->get_pagevars('tabname'));
63
        $this->contexts = array_filter($qbank->contexts->having_one_edit_tab_cap($qbank->get_pagevars('tabname')),
-
 
64
            static fn($context) => $context->contextlevel === CONTEXT_MODULE
-
 
65
        );
61
        $this->course = $qbank->course;
66
        $this->course = $qbank->course;
-
 
67
        $this->cm = $qbank->cm;
Línea 62... Línea 68...
62
 
68
 
63
        [$categoryid, $contextid] = self::validate_category_param($this->cat);
69
        [$categoryid, $contextid] = self::validate_category_param($this->cat);
64
        if (is_null($categoryid)) {
70
        if (is_null($categoryid)) {
65
            return;
71
            return;
Línea 66... Línea 72...
66
        }
72
        }
Línea 67... Línea 73...
67
 
73
 
-
 
74
        $this->category = self::get_category_record($categoryid, $contextid);
-
 
75
 
-
 
76
        parent::__construct($qbank);
-
 
77
        if (isset($this->filter['filteroptions']['includesubcategories'])) {
68
        $this->category = self::get_category_record($categoryid, $contextid);
78
            set_user_preference('qbank_managecategories_includesubcategories_filter_default',
-
 
79
                $this->filter['filteroptions']['includesubcategories']);
69
 
80
        }
Línea 70... Línea 81...
70
        parent::__construct($qbank);
81
        $this->includesubcategories = $this->filter['filteroptions']['includesubcategories'] ??
71
        $this->includesubcategories = $this->filter['filteroptions']['includesubcategories'] ?? false;
82
            get_user_preferences('qbank_managecategories_includesubcategories_filter_default', false);
72
    }
83
    }
73
 
84
 
74
    /**
85
    /**
75
     * Return default category
86
     * Return default category
76
     *
87
     *
77
     * @return \stdClass default category
88
     * @return \stdClass default category
78
     */
89
     */
Línea 79... Línea 90...
79
    public function get_default_category(): \stdClass {
90
    public function get_default_category(): \stdClass {
80
        if (empty($this->category)) {
91
        if (empty($this->category)) {
Línea 96... Línea 107...
96
    public function get_course_id() {
107
    public function get_course_id() {
97
        return $this->course->id;
108
        return $this->course->id;
98
    }
109
    }
Línea 99... Línea 110...
99
 
110
 
100
    /**
-
 
101
     * Called by question_bank_view to display the GUI for selecting a category
111
    /**
102
     * @deprecated since Moodle 4.3 MDL-72321 - please do not use this function any more.
-
 
103
     * @todo Final deprecation on Moodle 4.7 MDL-78090
112
     * @deprecated since Moodle 4.3 MDL-72321 - please do not use this function any more.
-
 
113
     */
104
     */
114
    #[\core\attribute\deprecated('filtering objects', since: '4.3', mdl: 'MDL-72321', final: true)]
105
    public function display_options() {
-
 
106
        debugging('Function display_options() is deprecated, please use filtering objects', DEBUG_DEVELOPER);
-
 
107
        global $PAGE;
-
 
108
        $displaydata = [];
115
    public function display_options() {
109
        $catmenu = helper::question_category_options($this->contexts, true, 0,
-
 
110
                true, -1, false);
-
 
111
        $displaydata['categoryselect'] = \html_writer::select($catmenu, 'category', $this->cat, [],
-
 
112
                array('class' => 'searchoptions custom-select', 'id' => 'id_selectacategory'));
-
 
113
        $displaydata['categorydesc'] = '';
-
 
114
        if ($this->category) {
-
 
115
            $displaydata['categorydesc'] = $this->print_category_info($this->category);
-
 
116
        }
-
 
117
        return $PAGE->get_renderer('qbank_managecategories')->render_category_condition($displaydata);
116
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 118... Línea 117...
118
    }
117
    }
119
 
-
 
120
    /**
-
 
121
     * Displays the recursion checkbox GUI.
118
 
122
     * question_bank_view places this within the section that is hidden by default
-
 
123
     * @deprecated since Moodle 4.3 MDL-72321 - please do not use this function any more.
119
    /**
-
 
120
     * @deprecated since Moodle 4.3 MDL-72321 - please do not use this function any more.
124
     * @todo Final deprecation on Moodle 4.7 MDL-78090
121
     */
125
     */
122
    #[\core\attribute\deprecated('foobar::blah()', since: '4.3', mdl: 'MDL-72321', final: true)]
126
    public function display_options_adv() {
-
 
127
        debugging('Function display_options_adv() is deprecated, please use filtering objects', DEBUG_DEVELOPER);
-
 
128
        global $PAGE;
-
 
129
        $displaydata = [];
-
 
130
        if ($this->recurse) {
-
 
131
            $displaydata['checked'] = 'checked';
-
 
132
        }
123
    public function display_options_adv() {
Línea 133... Línea 124...
133
        return $PAGE->get_renderer('qbank_managecategories')->render_category_condition_advanced($displaydata);
124
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
134
    }
-
 
135
 
-
 
136
    /**
-
 
137
     * Display the drop down to select the category.
-
 
138
     *
-
 
139
     * @param array $contexts of contexts that can be accessed from here.
125
    }
140
     * @param \moodle_url $pageurl the URL of this page.
-
 
141
     * @param string $current 'categoryID,contextID'.
126
 
-
 
127
    /**
142
     * @deprecated since Moodle 4.3
128
     * @deprecated since Moodle 4.3
143
     * @todo Final deprecation on Moodle 4.7 MDL-78090
-
 
144
     */
-
 
145
    protected function display_category_form($contexts, $pageurl, $current) {
-
 
146
        debugging(
-
 
147
            'Function display_category_form() is deprecated, please use the core_question renderer instead.',
-
 
148
            DEBUG_DEVELOPER
-
 
149
        );
-
 
150
        echo \html_writer::start_div('choosecategory');
129
     */
151
        $catmenu = question_category_options($contexts, true, 0, true, -1, false);
-
 
152
        echo \html_writer::label(get_string('selectacategory', 'question'), 'id_selectacategory', true, ["class" => "mr-1"]);
-
 
153
        echo \html_writer::select($catmenu, 'category', $current, [],
130
    #[\core\attribute\deprecated('core_question renderer', since: '4.3', mdl: 'MDL-72321', final: true)]
Línea 154... Línea 131...
154
                array('class' => 'searchoptions custom-select', 'id' => 'id_selectacategory'));
131
    protected function display_category_form($contexts, $pageurl, $current) {
155
        echo \html_writer::end_div() . "\n";
-
 
156
    }
132
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
157
 
-
 
158
    /**
133
    }
-
 
134
 
159
     * Print the text if category id not available.
135
    /**
160
     * @deprecated since Moodle 4.3
-
 
161
     * @todo Final deprecation in Moodle 4.7 MDL-78090
-
 
162
     */
-
 
163
    public static function print_choose_category_message(): void {
-
 
164
        debugging(
-
 
165
            'Function print_choose_category_message() is deprecated, please use ' .
-
 
166
                'qbank_managecategories/choose_category template instead.',
136
     * @deprecated since Moodle 4.3
167
            DEBUG_DEVELOPER
137
     */
Línea 168... Línea 138...
168
        );
138
    #[\core\attribute\deprecated('qbank_managecategories/choose_category template', since: '4.3', mdl: 'MDL-72321', final: true)]
169
        global $OUTPUT;
-
 
170
        echo $OUTPUT->render_from_template('qbank_managecategories/choose_category', []);
-
 
171
    }
-
 
172
 
139
    public static function print_choose_category_message(): void {
173
    /**
-
 
174
     * Look up the category record based on category ID and context
140
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
-
 
141
    }
175
     * @param string $categoryandcontext categoryID,contextID as used with question_bank_view->display()
142
 
176
     * @return \stdClass The category record
-
 
177
     * @deprecated since Moodle 4.3
-
 
178
     * @todo Final deprecation in Moodle 4.7 MDL-78090
143
    /**
179
     */
-
 
180
    public static function get_current_category($categoryandcontext) {
-
 
181
        debugging('Function get_current_category() is deprecated. Please do not use it anymore.', DEBUG_DEVELOPER);
-
 
182
        global $DB, $OUTPUT;
-
 
183
        [$categoryid, $contextid] = explode(',', $categoryandcontext);
-
 
184
        if (!$categoryid) {
-
 
185
            self::print_choose_category_message();
-
 
186
            return false;
-
 
187
        }
-
 
188
 
-
 
189
        if (!$category = $DB->get_record('question_categories', ['id' => $categoryid, 'contextid' => $contextid])) {
-
 
190
            echo $OUTPUT->box_start('generalbox questionbank');
-
 
191
            echo $OUTPUT->notification('Category not found!');
-
 
192
            echo $OUTPUT->box_end();
144
     * @deprecated since Moodle 4.3
Línea 193... Línea 145...
193
            return false;
145
     */
194
        }
146
    #[\core\attribute\deprecated(null, since: '4.3', mdl: 'MDL-72321', final: true)]
195
 
147
    public static function get_current_category($categoryandcontext) {
Línea 225... Línea 177...
225
                '*',
177
                '*',
226
                MUST_EXIST);
178
                MUST_EXIST);
227
    }
179
    }
Línea 228... Línea 180...
228
 
180
 
229
    /**
-
 
230
     * Print the category description
-
 
231
     * @param \stdClass $category the category information form the database.
181
    /**
232
     * @deprecated since Moodle 4.3 MDL-72321 - please do not use this function any more.
-
 
233
     * @todo Final deprecation on Moodle 4.7 MDL-78090
182
     * @deprecated since Moodle 4.3 MDL-72321 - please do not use this function any more.
-
 
183
     */
234
     */
184
    #[\core\attribute\deprecated(null, since: '4.3', mdl: 'MDL-72321', final: true)]
235
    protected function print_category_info($category): string {
185
    protected function print_category_info($category): string {
236
        debugging('Function print_category_info() is deprecated. Please do not use it anymore', DEBUG_DEVELOPER);
-
 
237
        $formatoptions = new \stdClass();
-
 
238
        $formatoptions->noclean = true;
-
 
239
        $formatoptions->overflowdiv = true;
-
 
240
        if (isset($this->maxinfolength)) {
-
 
241
            return shorten_text(format_text($category->info, $category->infoformat, $formatoptions, $this->course->id),
-
 
242
                    $this->maxinfolength);
-
 
243
        }
-
 
244
 
-
 
245
        return format_text($category->info, $category->infoformat, $formatoptions, $this->course->id);
186
        \core\deprecation::emit_deprecation([self::class, __FUNCTION__]);
Línea 246... Línea 187...
246
    }
187
    }
247
 
188
 
248
    public static function build_query_from_filter(array $filter): array {
189
    public static function build_query_from_filter(array $filter): array {
Línea 329... Línea 270...
329
    }
270
    }
Línea 330... Línea 271...
330
 
271
 
331
    public function is_required(): bool {
272
    public function is_required(): bool {
332
        return true;
273
        return true;
-
 
274
    }
-
 
275
 
-
 
276
    #[\Override]
-
 
277
    public function filter_invalid_values(array $filterconditions): array {
-
 
278
 
-
 
279
        global $DB;
-
 
280
 
-
 
281
        $defaultcatid = explode(',', $filterconditions['cat'])[0];
-
 
282
 
-
 
283
        [$insql, $inparams] = $DB->get_in_or_equal($filterconditions['filter']['category']['values']);
-
 
284
        $categories = $DB->get_records_select('question_categories', "id {$insql}",
-
 
285
            $inparams, null, 'id');
-
 
286
        $categoryids = array_keys($categories);
-
 
287
 
-
 
288
        foreach ($filterconditions['filter']['category']['values'] as $key => $catid) {
-
 
289
 
-
 
290
            // Check that the category still exists, and if not, remove it from the conditions.
-
 
291
            if (!in_array($catid, $categoryids)) {
-
 
292
                unset($filterconditions['filter']['category']['values'][$key]);
-
 
293
            }
-
 
294
 
-
 
295
        }
-
 
296
 
-
 
297
        // If we now don't have any valid categories, use the default loaded from the page.
-
 
298
        if (count($filterconditions['filter']['category']['values']) === 0) {
-
 
299
            $filterconditions['filter']['category']['values'] = [$defaultcatid];
-
 
300
        }
-
 
301
 
-
 
302
        return $filterconditions;
-
 
303
 
-
 
304
    }
333
    }
305