public function query_db($pagesize, $useinitialsbar = true) { $doneslots = array(); foreach ($this->get_sort_columns() as $column => $notused) { $slot = $this->is_latest_step_column($column); if ($slot && !in_array($slot, $doneslots)) { $this->add_latest_state_join($slot); $doneslots[] = $slot; } } parent::query_db($pagesize, $useinitialsbar); if ($this->requires_latest_steps_loaded()) { $qubaids = $this->get_qubaids_condition(); $this->lateststeps = $this->load_question_latest_steps($qubaids); } }
function query_db($pagesize, $useinitialsbar = true) { // Add table joins so we can sort by question answer // unfortunately can't join all tables necessary to fetch all answers // to get the state for one question per attempt row we must join two tables // and there is a limit to how many joins you can have in one query. In MySQL it // is 61. This means that when having more than 29 questions the query will fail. // So we join just the tables needed to sort the attempts. if ($sort = $this->get_sql_sort()) { $this->sql->from .= ' '; $sortparts = explode(',', $sort); $matches = array(); foreach ($sortparts as $sortpart) { $sortpart = trim($sortpart); if (preg_match('/^qsanswer([0-9]+)/', $sortpart, $matches)) { $qid = intval($matches[1]); $this->sql->fields .= ", qs{$qid}.grade AS qsgrade{$qid}, qs{$qid}.answer AS qsanswer{$qid}, qs{$qid}.event AS qsevent{$qid}, qs{$qid}.id AS qsid{$qid}"; $this->sql->from .= "LEFT JOIN {question_sessions} qns{$qid} ON qns{$qid}.attemptid = qa.uniqueid AND qns{$qid}.questionid = :qid{$qid} "; $this->sql->from .= "LEFT JOIN {question_states} qs{$qid} ON qs{$qid}.id = qns{$qid}.newgraded "; $this->sql->params['qid' . $qid] = $qid; } } } 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); } }
function query_db($pagesize, $useinitialsbar = true) { // Add table joins so we can sort by question grade // unfortunately can't join all tables necessary to fetch all grades // to get the state for one question per attempt row we must join two tables // and there is a limit to how many joins you can have in one query. In MySQL it // is 61. This means that when having more than 29 questions the query will fail. // So we join just the tables needed to sort the attempts. if ($sort = $this->get_sql_sort()) { if ($this->detailedmarks) { $this->sql->from .= ' '; $sortparts = explode(',', $sort); $matches = array(); foreach ($sortparts as $sortpart) { $sortpart = trim($sortpart); if (preg_match('/^qsgrade([0-9]+)/', $sortpart, $matches)) { $qid = intval($matches[1]); $this->sql->fields .= ", qs{$qid}.grade AS qsgrade{$qid}, qs{$qid}.event AS qsevent{$qid}, qs{$qid}.id AS qsid{$qid}"; $this->sql->from .= "LEFT JOIN {question_sessions} qns{$qid} ON qns{$qid}.attemptid = qa.uniqueid AND qns{$qid}.questionid = :qid{$qid} "; $this->sql->from .= "LEFT JOIN {question_states} qs{$qid} ON qs{$qid}.id = qns{$qid}.newgraded "; $this->sql->params['qid' . $qid] = $qid; } } } else { //unset any sort columns that sort on question grade as the //grades are not being fetched as fields $sess =& $this->sess; foreach ($sess->sortby as $column => $order) { if (preg_match('/^qsgrade([0-9]+)/', trim($column))) { unset($sess->sortby[$column]); } } } } parent::query_db($pagesize, $useinitialsbar); //get all the attempt ids we want to display on this page //or to export for download. if (!$this->is_downloading()) { $attemptids = array(); foreach ($this->rawdata as $attempt) { if ($attempt->attemptuniqueid > 0) { $attemptids[] = $attempt->attemptuniqueid; } } $this->gradedstatesbyattempt = quiz_get_newgraded_states($attemptids, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt'); if (has_capability('mod/quiz:regrade', $this->context)) { $this->regradedqs = quiz_get_regraded_qs($attemptids); } } else { $this->gradedstatesbyattempt = quiz_get_newgraded_states($this->sql, true, 'qs.id, qs.grade, qs.event, qs.question, qs.attempt'); if (has_capability('mod/quiz:regrade', $this->context)) { $this->regradedqs = quiz_get_regraded_qs($this->sql); } } }