From 2ea2c1f57aba8b59ba4f3a8cb35e3acb1111f267 Mon Sep 17 00:00:00 2001 From: jamiesensei Date: Tue, 16 Sep 2008 09:50:24 +0000 Subject: [PATCH] MDL-16528 "responses report : improve efficiency of sql" moved the querying for state data all into one big query rather than an individual query for each question in each attempt. --- mod/quiz/report/responses/responses_table.php | 28 +++++++++++++++---- 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/mod/quiz/report/responses/responses_table.php b/mod/quiz/report/responses/responses_table.php index f0b66609f8..ebd75c9a58 100644 --- a/mod/quiz/report/responses/responses_table.php +++ b/mod/quiz/report/responses/responses_table.php @@ -141,15 +141,19 @@ class quiz_report_responses_table extends table_sql { if ($attempt->uniqueid == 0) { return '-'; } - if (!isset($states[$attempt->uniqueid])){ - $states[$attempt->uniqueid] = get_question_states($this->questions, $this->quiz, $attempt); - } - $statesforattempt = $states[$attempt->uniqueid]; $questionid = $matches[1]; + if (isset($this->gradedstatesbyattempt[$attempt->uniqueid][$questionid])){ + $stateforqinattempt = $this->gradedstatesbyattempt[$attempt->uniqueid][$questionid]; + } else { + return '-'; + } + $question = $this->questions[$questionid]; - $responses = get_question_actual_response($question, $statesforattempt[$questionid]); + restore_question_state($question, $stateforqinattempt); + + $responses = get_question_actual_response($question, $stateforqinattempt); $response = (!empty($responses)? implode('; ',$responses) : '-'); - $grade = $statesforattempt[$questionid]->last_graded->grade + $grade = $stateforqinattempt->grade / $this->questions[$questionid]->maxgrade; if (!$this->is_downloading()) { $format_options = new stdClass; @@ -210,6 +214,18 @@ class quiz_report_responses_table extends table_sql { } } parent::query_db($pagesize, $useinitialsbar); + $qsfields = 'qs.id, qs.grade, qs.event, qs.question, qs.answer, qs.attempt'; + if (!$this->is_downloading()) { + $attemptids = array(); + foreach ($this->rawdata as $attempt){ + if ($attempt->uniqueid > 0){ + $attemptids[] = $attempt->uniqueid; + } + } + $this->gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, $qsfields); + } else { + $this->gradedstatesbyattempt = quiz_get_newgraded_states($this->sql, true, $qsfields); + } } } ?> \ No newline at end of file -- 2.39.5