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.
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