Skip to content

Commit

Permalink
MDL-58860 mod_lesson: Fix get_attempts_overview for no attempts
Browse files Browse the repository at this point in the history
WS get_attempts_overview was failing when there weren’t attempts in the
given assignment.
  • Loading branch information
jleyva committed May 9, 2017
1 parent 932bc91 commit b50ff71
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
15 changes: 8 additions & 7 deletions mod/lesson/classes/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -1681,7 +1681,7 @@ public static function get_attempts_overview($lessonid, $groupid = 0) {

$params = array('lessonid' => $lessonid, 'groupid' => $groupid);
$params = self::validate_parameters(self::get_attempts_overview_parameters(), $params);
$studentsdata = $warnings = array();
$warnings = array();

list($lesson, $course, $cm, $context, $lessonrecord) = self::validate_lesson($params['lessonid']);
require_capability('mod/lesson:viewreports', $context);
Expand All @@ -1705,15 +1705,15 @@ public static function get_attempts_overview($lessonid, $groupid = 0) {
}
}

$result = array(
'warnings' => $warnings
);

list($table, $data) = lesson_get_overview_report_table_and_data($lesson, $groupid);
if ($data !== false) {
$studentsdata = $data;
$result['data'] = $data;
}

$result = array(
'data' => $studentsdata,
'warnings' => $warnings
);
return $result;
}

Expand Down Expand Up @@ -1756,7 +1756,8 @@ public static function get_attempts_overview_returns() {
)
), 'Students data, including attempts.', VALUE_OPTIONAL
),
)
),
'Attempts overview data (empty for no attemps).', VALUE_OPTIONAL
),
'warnings' => new external_warnings(),
)
Expand Down
11 changes: 11 additions & 0 deletions mod/lesson/tests/external_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -1181,6 +1181,17 @@ public function test_get_attempts_overview() {
$this->assertCount(2, $result['data']['students']);
}

/**
* Test get_attempts_overview when there aren't attempts.
*/
public function test_get_attempts_overview_no_attempts() {
$this->setAdminUser();
$result = mod_lesson_external::get_attempts_overview($this->lesson->id);
$result = external_api::clean_returnvalue(mod_lesson_external::get_attempts_overview_returns(), $result);
$this->assertCount(0, $result['warnings']);
$this->assertArrayNotHasKey('data', $result);
}

/**
* Test get_user_attempt
*/
Expand Down

0 comments on commit b50ff71

Please sign in to comment.