|
| 1 | +<?php |
| 2 | +// This file is part of Stack - http://stack.maths.ed.ac.uk/ |
| 3 | +// |
| 4 | +// Stack 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 | +// Stack 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 Stack. If not, see <http://www.gnu.org/licenses/>. |
| 16 | +// |
| 17 | + |
| 18 | +/** |
| 19 | + * A block for specifying parsing options in ascii blocks. |
| 20 | + * @package qtype_stack |
| 21 | + * @copyright 2024 University of Edinburgh. |
| 22 | + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. |
| 23 | + */ |
| 24 | + |
| 25 | +defined('MOODLE_INTERNAL') || die(); |
| 26 | + |
| 27 | +require_once(__DIR__ . '/../block.interface.php'); |
| 28 | +require_once(__DIR__ . '/../../../utils.class.php'); |
| 29 | + |
| 30 | +class stack_cas_castext2_filter extends stack_cas_castext2_block { |
| 31 | + // phpcs:ignore moodle.Commenting.MissingDocblock.Function |
| 32 | + public function compile($format, $options): ?MP_Node { |
| 33 | + $r = new MP_List([ |
| 34 | + new MP_String('filter'), |
| 35 | + new MP_String(json_encode($this->params)), |
| 36 | + ]); |
| 37 | + |
| 38 | + return $r; |
| 39 | + } |
| 40 | + |
| 41 | + // phpcs:ignore moodle.Commenting.MissingDocblock.Function |
| 42 | + public function is_flat(): bool { |
| 43 | + // These are never flat. |
| 44 | + return false; |
| 45 | + } |
| 46 | + |
| 47 | + // phpcs:ignore moodle.Commenting.MissingDocblock.Function |
| 48 | + public function validate_extract_attributes(): array { |
| 49 | + // No CAS arguments. |
| 50 | + return []; |
| 51 | + } |
| 52 | + |
| 53 | + // phpcs:ignore moodle.Commenting.MissingDocblock.Function |
| 54 | + public function validate( |
| 55 | + &$errors = [], |
| 56 | + $options = [] |
| 57 | + ): bool { |
| 58 | + $valid = true; |
| 59 | + $err = []; |
| 60 | + |
| 61 | + if (!array_key_exists('type', $this->params)) { |
| 62 | + $valid = false; |
| 63 | + $err[] = stack_string('stackBlock_filter_type_required'); |
| 64 | + } |
| 65 | + |
| 66 | + // Wrap the old string errors with the context details. |
| 67 | + foreach ($err as $er) { |
| 68 | + $errors[] = new $options['errclass']($er, $options['context'] . '/' . $this->position['start'] . '-' . |
| 69 | + $this->position['end']); |
| 70 | + } |
| 71 | + |
| 72 | + return $valid; |
| 73 | + } |
| 74 | + |
| 75 | + // phpcs:ignore moodle.Commenting.MissingDocblock.Function |
| 76 | + public function postprocess( |
| 77 | + array $params, |
| 78 | + castext2_processor $processor, |
| 79 | + castext2_placeholder_holder $holder |
| 80 | + ): string { |
| 81 | + return ''; |
| 82 | + } |
| 83 | + |
| 84 | + /** |
| 85 | + * Is this an interactive block? |
| 86 | + * If true, we can't generate a static version. |
| 87 | + * @return bool |
| 88 | + */ |
| 89 | + public function is_interactive(): bool { |
| 90 | + return true; |
| 91 | + } |
| 92 | +} |
0 commit comments