Skip to content

Commit

Permalink
MDL-83645 grade: fix text formatting in external grading form method.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulholden committed Dec 20, 2024
1 parent 04cb431 commit 4d31a0e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 8 additions & 7 deletions lib/classes/grading_external.php
Original file line number Diff line number Diff line change
Expand Up @@ -364,24 +364,25 @@ public static function get_gradingform_instances($definitionid, $since = 0) {
'warningcode' => '1'
);
}

foreach ($activeinstances as $activeinstance) {
$instance = array();
$instance['id'] = $activeinstance->get_id();
$instance['raterid'] = $activeinstance->get_data('raterid');
$instance['itemid'] = $activeinstance->get_data('itemid');
$instance['rawgrade'] = $activeinstance->get_data('rawgrade');
$instance['status'] = $activeinstance->get_data('status');
$instance['feedback'] = $activeinstance->get_data('feedback');
$instance['feedbackformat'] = $activeinstance->get_data('feedbackformat');

// Format the feedback text field.
$formattedtext = \core_external\util::format_text($activeinstance->get_data('feedback'),
[$instance['feedback'], $instance['feedbackformat']] = \core_external\util::format_text(
$activeinstance->get_data('feedback'),
$activeinstance->get_data('feedbackformat'),
$context->id,
$context,
$area->component,
'feedback',
$params['definitionid']);
$instance['feedback'] = $formattedtext[0];
$instance['feedbackformat'] = $formattedtext[1];
$params['definitionid'],
);

$instance['timemodified'] = $activeinstance->get_data('timemodified');

if ($details != null && $getfilling != null) {
Expand Down
10 changes: 7 additions & 3 deletions lib/tests/grading_external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,8 @@ public function test_get_gradingform_instances(): void {
'raterid' => $USER->id,
'itemid' => $gid,
'status' => 1,
'feedbackformat' => 0,
'feedback' => 'Fabulous',
'feedbackformat' => FORMAT_HTML,
'timemodified' => 1
);
$instanceid = $DB->insert_record('grading_instances', $instance);
Expand All @@ -297,9 +298,12 @@ public function test_get_gradingform_instances(): void {
$this->assertEquals($USER->id, $result['instances'][0]['raterid']);
$this->assertEquals($gid, $result['instances'][0]['itemid']);
$this->assertEquals(1, $result['instances'][0]['status']);
$this->assertEquals('Fabulous', $result['instances'][0]['feedback']);
$this->assertEquals(FORMAT_HTML, $result['instances'][0]['feedbackformat']);
$this->assertEquals(1, $result['instances'][0]['timemodified']);
$this->assertEquals(1, count($result['instances'][0]['rubric']));
$this->assertEquals(1, count($result['instances'][0]['rubric']['criteria']));
$this->assertCount(1, $result['instances'][0]['rubric']);
$this->assertCount(1, $result['instances'][0]['rubric']['criteria']);

$criteria = $result['instances'][0]['rubric']['criteria'];
$this->assertEquals($criterionid, $criteria[0]['criterionid']);
$this->assertEquals($levelid, $criteria[0]['levelid']);
Expand Down

0 comments on commit 4d31a0e

Please sign in to comment.