MDL-77418 mod_feedback: defensive use of analysis item data.

This commit is contained in:
Paul Holden 2023-02-27 18:49:11 +00:00
parent a31f5830bd
commit 72f7128665
2 changed files with 10 additions and 4 deletions

View File

@ -104,7 +104,7 @@ class feedback_item_multichoice extends feedback_item_base {
* @param stdClass $item the db-object from feedback_item
* @param int $groupid
* @param int $courseid
* @return array
* @return array|null
*/
protected function get_analysed($item, $groupid = false, $courseid = false) {
$info = $this->get_info($item);
@ -251,6 +251,9 @@ class feedback_item_multichoice extends feedback_item_base {
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
if (!$analysed_item) {
return $row_offset;
}
$data = $analysed_item[2];
@ -503,7 +506,7 @@ class feedback_item_multichoice extends feedback_item_base {
$externaldata = array();
$data = $this->get_analysed($item, $groupid, $courseid);
if (!empty($data[2]) && is_array($data[2])) {
if ($data && !empty($data[2]) && is_array($data[2])) {
foreach ($data[2] as $d) {
$externaldata[] = json_encode($d);
}

View File

@ -106,7 +106,7 @@ class feedback_item_multichoicerated extends feedback_item_base {
* @param stdClass $item the db-object from feedback_item
* @param int $groupid
* @param int $courseid
* @return array
* @return array|null
*/
protected function get_analysed($item, $groupid = false, $courseid = false) {
$analysed_item = array();
@ -228,6 +228,9 @@ class feedback_item_multichoicerated extends feedback_item_base {
$groupid, $courseid = false) {
$analysed_item = $this->get_analysed($item, $groupid, $courseid);
if (!$analysed_item) {
return $row_offset;
}
$data = $analysed_item[2];
@ -491,7 +494,7 @@ class feedback_item_multichoicerated extends feedback_item_base {
$externaldata = array();
$data = $this->get_analysed($item, $groupid, $courseid);
if (!empty($data[2]) && is_array($data[2])) {
if ($data && !empty($data[2]) && is_array($data[2])) {
foreach ($data[2] as $d) {
$externaldata[] = json_encode($d);
}