public function load_average_marks(qubaid_condition $qubaids, $slots = null) {
        if (!empty($slots)) {
            list($slottest, $slotsparams) = $this->db->get_in_or_equal(
                    $slots, SQL_PARAMS_NAMED, 'slot');
            $slotwhere = " AND qa.slot {$slottest}";
        } else {
            $slotwhere = '';
            $slotsparams = array();
        }

        list($statetest, $stateparams) = $this->db->get_in_or_equal(array(
                (string) question_state::$gaveup,
                (string) question_state::$gradedwrong,
                (string) question_state::$gradedpartial,
                (string) question_state::$gradedright,
                (string) question_state::$mangaveup,
                (string) question_state::$mangrwrong,
                (string) question_state::$mangrpartial,
                (string) question_state::$mangrright), SQL_PARAMS_NAMED, 'st');

        return $this->db->get_records_sql("
SELECT
    qa.slot,
    AVG(COALESCE(qas.fraction, 0)) AS averagefraction,
    COUNT(1) AS numaveraged

FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
        AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}

WHERE
    {$qubaids->where()}
    $slotwhere
    AND qas.state $statetest

GROUP BY qa.slot

ORDER BY qa.slot
        ", $slotsparams + $stateparams + $qubaids->from_where_params());
    }
public function load_average_marks(qubaid_condition $qubaids, $slots = null) {
        if (!empty($slots)) {
            list($slottest, $slotsparams) = $this->db->get_in_or_equal(
                    $slots, SQL_PARAMS_NAMED, 'slot');
            $slotwhere = " AND qa.slot {$slottest}";
        } else {
            $slotwhere = '';
            $slotsparams = array();
        }

        list($statetest, $stateparams) = $this->db->get_in_or_equal(array(
                (string) question_state::$gaveup,
                (string) question_state::$gradedwrong,
                (string) question_state::$gradedpartial,
                (string) question_state::$gradedright,
                (string) question_state::$mangaveup,
                (string) question_state::$mangrwrong,
                (string) question_state::$mangrpartial,
                (string) question_state::$mangrright), SQL_PARAMS_NAMED, 'st');

        return $this->db->get_records_sql("
SELECT
    qa.slot,
    AVG(COALESCE(qas.fraction, 0)) AS averagefraction,
    COUNT(1) AS numaveraged

FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
        AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}

WHERE
    {$qubaids->where()}
    $slotwhere
    AND qas.state $statetest

GROUP BY qa.slot

ORDER BY qa.slot
        ", $slotsparams + $stateparams + $qubaids->from_where_params());
    }
public function load_average_marks ( qubaid_condition $ qubaids , $ slots = null ) { if ( ! empty ( $ slots ) ) { list ( $ slottest , $ slotsparams ) = $ this -> db -> get_in_or_equal ( $ slots , SQL_PARAMS_NAMED , 'slot' ) ; $ slotwhere = " AND qa.slot {$slottest}" ; } else { $ slotwhere = '' ; $ slotsparams = array ( ) ; } list ( $ statetest , $ stateparams ) = $ this -> db -> get_in_or_equal ( array ( ( string ) question_state :: $ gaveup , ( string ) question_state :: $ gradedwrong , ( string ) question_state :: $ gradedpartial , ( string ) question_state :: $ gradedright , ( string ) question_state :: $ mangaveup , ( string ) question_state :: $ mangrwrong , ( string ) question_state :: $ mangrpartial , ( string ) question_state :: $ mangrright ) , SQL_PARAMS_NAMED , 'st' ) ; return $ this -> db -> get_records_sql ( "
SELECT
    qa.slot,
    AVG(COALESCE(qas.fraction, 0)) AS averagefraction,
    COUNT(1) AS numaveraged

FROM {$qubaids->from_question_attempts('qa')}
JOIN {question_attempt_steps} qas ON qas.questionattemptid = qa.id
        AND qas.sequencenumber = {$this->latest_step_for_qa_subquery()}

WHERE
    {$qubaids->where()}
    $slotwhere
    AND qas.state $statetest

GROUP BY qa.slot

ORDER BY qa.slot
        " , $ slotsparams + $ stateparams + $ qubaids -> from_where_params ( ) ) ; }
Load the average mark, and number of attempts, for each slot in a set of
question usages..

This method may be called publicly.

@param qubaid_condition $qubaids used to restrict which usages are included
in the query. See {@link qubaid_condition}.
@param array $slots if null, load info for all quesitions, otherwise only
load the averages for the specified questions.
@return array of objects with fields ->slot, ->averagefraction and ->numaveraged.
Load the average mark and number of attempts for each slot in a set of question usages ..