Skip to content

Commit

Permalink
WIP: extract tags from [[todo]] blocks in castext.
Browse files Browse the repository at this point in the history
  • Loading branch information
sangwinc committed Aug 17, 2024
1 parent 95ac1b3 commit b6225f4
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 7 deletions.
6 changes: 4 additions & 2 deletions adminui/dependencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,15 +323,17 @@
'q.id = o.questionid AND ' .
$DB->sql_like('o.compiledcache', ':trg') . ';', ['trg' => '%stack_todo%']);
echo '<h4>Questions containing [[todo]] blocks</h4>';
echo '<table><thead><tr><th>Question</th></thead><tbody>';
echo '<table><thead><tr><th>Question</th><th>Tags</th></thead><tbody>';
// Load the whole question, simpler to get the contexts correct that way.
foreach ($qs as $item) {
$q = question_bank::load_question($item->questionid);
$tags = $q->get_question_todos();
list($context, $seed, $urlparams) = qtype_stack_setup_question_test_page($q);
$qurl = qbank_previewquestion\helper::question_preview_url($item->questionid,
null, null, null, null, $context);
echo "<tr><td>" . $q->name . ' ' .
$OUTPUT->action_icon($qurl, new pix_icon('t/preview', get_string('preview'))) . '</td></tr>';
$OUTPUT->action_icon($qurl, new pix_icon('t/preview', get_string('preview'))) .
'</td><td>' . implode(', ', $tags). '<td></tr>';
}
echo '</tbody></table>';
}
Expand Down
13 changes: 13 additions & 0 deletions question.php
Original file line number Diff line number Diff line change
Expand Up @@ -734,6 +734,19 @@ public function get_question_summary() {
return stack_string('questionnote_missing');
}

public function get_question_todos() {
$tags = [];
$fields = [$this->questiontext, $this->questionnote, $this->generalfeedback,
$this->specificfeedback, $this->questiondescription];
foreach ($fields as $field) {
$tags = array_merge($tags, castext2_parser_utils::get_todoblocks($field));
}
// Unique tags, sorted.
$tags = array_unique($tags);
sort($tags);
return $tags;
}

public function summarise_response(array $response) {
// Provide seed information on student's version via the normal moodle quiz report.
$bits = ['Seed: ' . $this->seed];
Expand Down
8 changes: 4 additions & 4 deletions stack/cas/castext2/README
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ Some key differences to the Abacus era castext:
step can thus be cached and its result is processable even even without
knowing the original code used to generate it.

- '@' and '#' chars are now alloed within {@...@} and {#...#} blocks again due
- '@' and '#' chars are now allowed within {@...@} and {#...#} blocks again due
to the parser grammar being better.

- Mathmode paintting is being done outside the actual parser to simplify
- Mathmode painting is being done outside the actual parser to simplify
the parser grammar and to allow them to be tuned separately. The mathmode
identification logic can now ignore 'comment'-blocks and block parameters
leading to more logical results.

- Overall there are less steps in the process as the parser grammar now
- Overall there are fewer steps in the process as the parser grammar now
actually describes a nested block system and the number of 'special' cases
is lesser.
is reduced.


Like the MaximaParser this parser comes from the UI side of Stateful and is
Expand Down
2 changes: 1 addition & 1 deletion stack/cas/castext2/blocks/body.block.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
require_once(__DIR__ . '/../../../utils.class.php');

/**
* A block for dealig with non script content in IFRAMe blocks.
* A block for dealing with non script content in IFRAME blocks.
*/
class stack_cas_castext2_body extends stack_cas_castext2_block {

Expand Down
11 changes: 11 additions & 0 deletions stack/cas/castext2/blocks/todo.block.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,15 @@ public function is_flat(): bool {
public function validate_extract_attributes(): array {
return [];
}

public function extract_todo(): array {
$tags = [];
foreach (explode(',', $this->params['tags']) as $tag) {
$tag = trim($tag);
if (!array_key_exists($tag, $tags)) {
$tags[$tag] = true;
}
}
return array_keys($tags);
}
}
22 changes: 22 additions & 0 deletions stack/cas/castext2/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,28 @@ public static function get_casstrings(string $castext): array {
return $css;
}

public static function get_todoblocks(string $castext): array {
if ($castext === '' || $castext === null) {
return [];
}

$ast = self::parse($castext);
$root = stack_cas_castext2_special_root::make($ast);
$tags = [];

$collecttags = function ($node) use (&$tags) {
if (!($node instanceof stack_cas_castext2_todo)) {
return true;
}
foreach ($node->extract_todo() as $tag) {
$tags[] = $tag;
}
return true;
};
$root->callbackRecurse($collecttags);
return $tags;
}

// Postprocesses the result from CAS. For those that have not yet fully
// parsed the response. Does not use the full maximaparser infrastructure
// as the result is just an list of strings... well should be for all simple
Expand Down

0 comments on commit b6225f4

Please sign in to comment.