Moodle

'Analysis of responses' shows an error when viewing individual question data.

Details

  • Type: Sub-task Sub-task
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 2.0
  • Fix Version/s: 2.0
  • Component/s: Quiz
  • Labels:
    None
  • Affected Branches:
    MOODLE_20_STABLE
  • Fixed Branches:
    MOODLE_20_STABLE

Description

OU Moodle with September 2008 Quiz Reports

1 From the statistics page, click on any individual question link ('more detailed analysis of the responses to this question')

2 The final section on the new page, 'Analysis of responses' , gives the following error message:

Notice: Trying to get property of non-object in /var/www/html/icmatest/ou-moodle-dev/mod/quiz/report/statistics/report.php on line 183

Notice: Trying to get property of non-object in /var/www/html/icmatest/ou-moodle-dev/mod/quiz/report/statistics/report.php on line 183

Notice: Trying to get property of non-object in /var/www/html/icmatest/ou-moodle-dev/mod/quiz/report/statistics/report.php on line 184

Notice: Trying to get property of non-object in /var/www/html/icmatest/ou-moodle-dev/mod/quiz/report/statistics/report.php on line 184

......above repeated numerous times

Fatal error: Cannot use object of type stdClass as array in /var/www/html/icmatest/ou-moodle-dev/mod/quiz/report/statistics/report.php on line 290

Activity

Hide
Jamie Pratt added a comment -

Hi,

Could you see what the output is if you insert a print_object as follows :

if ($responses = get_records_select('quiz_question_response_stats', "quizstatisticsid = {$quizstats->id} AND questionid = {$question->id}",
'credit DESC, subqid ASC, aid ASC, rcount DESC')){
$responses = quiz_report_index_by_keys($responses, array('subqid', 'aid'), false);
+ print_object(compact('teacherresponses', 'responses'));
foreach ($responses as $subqid => $response){

And could you copy and paste the code that is around line 183 and 184 and 290 in your copy of mod/quiz/report/statistics/report.php please?

Jamie

Show
Jamie Pratt added a comment - Hi, Could you see what the output is if you insert a print_object as follows : if ($responses = get_records_select('quiz_question_response_stats', "quizstatisticsid = {$quizstats->id} AND questionid = {$question->id}", 'credit DESC, subqid ASC, aid ASC, rcount DESC')){ $responses = quiz_report_index_by_keys($responses, array('subqid', 'aid'), false); + print_object(compact('teacherresponses', 'responses')); foreach ($responses as $subqid => $response){ And could you copy and paste the code that is around line 183 and 184 and 290 in your copy of mod/quiz/report/statistics/report.php please? Jamie
Hide
Jamie Pratt added a comment -

I can see the cause of this problem from the output of print_object you sent me :

[responses] => Array
(
[715] => Array
(
[1769] => stdClass Object
(
[quizstatisticsid] => 123
[questionid] => 715
[subqid] => 715
[aid] => 1769
[response] => blue
[rcount] => 3
[credit] => 1.00000
[id] => 587
)

[1770] => stdClass Object
(
[quizstatisticsid] => 123
[questionid] => 715
[subqid] => 715
[aid] => 1770
[response] => yellow
[rcount] => 1
[credit] => 0.00000
[id] => 588
)

)

)

The quiz_report_index_by_keys function is not returning arrays indexed as expected. This is what a print_object in the same place outputs for me :

[responses] => Array
(
[33] => Array
(
[51] => Array
(
[0] => stdClass Object
(
[quizstatisticsid] => 54
[questionid] => 33
[subqid] => 33
[aid] => 51
[response] => 4.5 billion years old
[rcount] => 15
[credit] => 1.00000
[id] => 7988
)

)

[50] => Array
(
[0] => stdClass Object
(
[quizstatisticsid] => 54
[questionid] => 33
[subqid] => 33
[aid] => 50
[response] => 5 billion years old
[rcount] => 16
[credit] => 0.90000
[id] => 7986
)

)

[49] => Array
(
[0] => stdClass Object
(
[quizstatisticsid] => 54
[questionid] => 33
[subqid] => 33
[aid] => 49
[response] => Ancient
[rcount] => 18
[credit] => 0.30000
[id] => 7987
)

)

)

)

Notice I have 3 dimensions in my array of objects whereas you have two. I would expect that the problem must be in quiz_report_index_by_keys.

The third parameter of the function '$keysunique' controls whether to add this extra dimension to the array. Here is a copy of my function in my copy of the code base :

function quiz_report_index_by_keys($datum, $keys, $keysunique=true){
if (!$datum){ return $datum; }
$key = array_shift($keys);
$datumkeyed = array();
foreach ($datum as $data){
if ($keys || !$keysunique){
$datumkeyed[$data->{$key}][]= $data;
} else {
$datumkeyed[$data->{$key}]= $data;
}
}
if ($keys){
foreach ($datumkeyed as $datakey => $datakeyed){ $datumkeyed[$datakey] = quiz_report_index_by_keys($datakeyed, $keys, $keysunique); }
}
return $datumkeyed;
}

Please check particularly that $keysunique is passed through to the reciprocal call to quiz_report_index_by_keys.

Show
Jamie Pratt added a comment - I can see the cause of this problem from the output of print_object you sent me : [responses] => Array ( [715] => Array ( [1769] => stdClass Object ( [quizstatisticsid] => 123 [questionid] => 715 [subqid] => 715 [aid] => 1769 [response] => blue [rcount] => 3 [credit] => 1.00000 [id] => 587 ) [1770] => stdClass Object ( [quizstatisticsid] => 123 [questionid] => 715 [subqid] => 715 [aid] => 1770 [response] => yellow [rcount] => 1 [credit] => 0.00000 [id] => 588 ) ) ) The quiz_report_index_by_keys function is not returning arrays indexed as expected. This is what a print_object in the same place outputs for me : [responses] => Array ( [33] => Array ( [51] => Array ( [0] => stdClass Object ( [quizstatisticsid] => 54 [questionid] => 33 [subqid] => 33 [aid] => 51 [response] => 4.5 billion years old [rcount] => 15 [credit] => 1.00000 [id] => 7988 ) ) [50] => Array ( [0] => stdClass Object ( [quizstatisticsid] => 54 [questionid] => 33 [subqid] => 33 [aid] => 50 [response] => 5 billion years old [rcount] => 16 [credit] => 0.90000 [id] => 7986 ) ) [49] => Array ( [0] => stdClass Object ( [quizstatisticsid] => 54 [questionid] => 33 [subqid] => 33 [aid] => 49 [response] => Ancient [rcount] => 18 [credit] => 0.30000 [id] => 7987 ) ) ) ) Notice I have 3 dimensions in my array of objects whereas you have two. I would expect that the problem must be in quiz_report_index_by_keys. The third parameter of the function '$keysunique' controls whether to add this extra dimension to the array. Here is a copy of my function in my copy of the code base : function quiz_report_index_by_keys($datum, $keys, $keysunique=true){ if (!$datum){ return $datum; } $key = array_shift($keys); $datumkeyed = array(); foreach ($datum as $data){ if ($keys || !$keysunique){ $datumkeyed[$data->{$key}][]= $data; } else { $datumkeyed[$data->{$key}]= $data; } } if ($keys){ foreach ($datumkeyed as $datakey => $datakeyed){ $datumkeyed[$datakey] = quiz_report_index_by_keys($datakeyed, $keys, $keysunique); } } return $datumkeyed; } Please check particularly that $keysunique is passed through to the reciprocal call to quiz_report_index_by_keys.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: