-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parsons filter to extract final submission only
- Loading branch information
Showing
8 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
stack/cas/parsingrules/909_parsons_get_final_submission.filter.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
// This file is part of Stack - https://stack.maths.ed.ac.uk | ||
// | ||
// Stack is free software: you can redistribute it and/or modify | ||
// it under the terms of the GNU General Public License as published by | ||
// the Free Software Foundation, either version 3 of the License, or | ||
// (at your option) any later version. | ||
// | ||
// Stack is distributed in the hope that it will be useful, | ||
// but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
// GNU General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU General Public License | ||
// along with Stack. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
/** | ||
* Add description here! | ||
* @package qtype_stack | ||
* @copyright 2024 University of Edinburgh. | ||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later. | ||
*/ | ||
|
||
defined('MOODLE_INTERNAL') || die(); | ||
require_once(__DIR__ . '/filter.interface.php'); | ||
require_once(__DIR__ . '/../../utils.class.php'); | ||
|
||
// phpcs:ignore moodle.Commenting.MissingDocblock.Class | ||
class stack_ast_filter_909_parsons_get_final_submission implements stack_cas_astfilter { | ||
// phpcs:ignore moodle.Commenting.MissingDocblock.Function | ||
public function filter(MP_Node $ast, array &$errors, array &$answernotes, stack_cas_security $identifierrules): MP_Node { | ||
$strings = function($node) use (&$answernotes, &$errors) { | ||
// We validate the node to check that it is a string that represents a Parson's state. | ||
// This is not strictly required as it is prevented by `$node instanceof MP_String`, but it is an additional safety | ||
// measure to ensure we do not dehash other strings. | ||
if ($node instanceof MP_String && stack_parsons_input::validate_parsons_string($node->value)) { | ||
$decoded = json_decode($node->value); | ||
$node->value = json_encode(reset($decoded)); | ||
} | ||
|
||
return true; | ||
}; | ||
|
||
$ast->callbackRecurse($strings); | ||
return $ast; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters