protected function dotest_load_questions_usages_where_question_in_state() {
        $this->assertEquals(
                array(array($this->usageids[0], $this->usageids[1]), 2),
                $this->dm->load_questions_usages_where_question_in_state($this->bothusages,
                'all', $this->allslots[1], null, 'questionusageid'));

        $this->assertEquals(
                array(array($this->usageids[0], $this->usageids[1]), 2),
                $this->dm->load_questions_usages_where_question_in_state($this->bothusages,
                'autograded', $this->allslots[0], null, 'questionusageid'));

        $this->assertEquals(
                array(array($this->usageids[0]), 1),
                $this->dm->load_questions_usages_where_question_in_state($this->bothusages,
                'needsgrading', $this->allslots[1], null, 'questionusageid'));
    }
Пример #2
0
 /**
  * Get a list of usage ids where the question with slot $slot, and optionally
  * also with question id $questionid, is in summary state $summarystate. Also
  * return the total count of such states.
  *
  * Only a subset of the ids can be returned by using $orderby, $limitfrom and
  * $limitnum. A special value 'random' can be passed as $orderby, in which case
  * $limitfrom is ignored.
  *
  * @param int $slot The slot for the questions you want to konw about.
  * @param int $questionid (optional) Only return attempts that were of this specific question.
  * @param string $summarystate 'all', 'needsgrading', 'autograded' or 'manuallygraded'.
  * @param string $orderby 'random', 'date', 'student' or 'idnumber'.
  * @param int $page implements paging of the results.
  *      Ignored if $orderby = random or $pagesize is null.
  * @param int $pagesize implements paging of the results. null = all.
  */
 protected function get_usage_ids_where_question_in_state($summarystate, $slot, $questionid = null, $orderby = 'random', $page = 0, $pagesize = null)
 {
     global $CFG, $DB;
     $dm = new question_engine_data_mapper();
     if ($pagesize && $orderby != 'random') {
         $limitfrom = $page * $pagesize;
     } else {
         $limitfrom = 0;
     }
     $qubaids = $this->get_qubaids_condition();
     $params = array();
     if ($orderby == 'date') {
         list($statetest, $params) = $dm->in_summary_state_test('manuallygraded', false, 'mangrstate');
         $orderby = "(\n                    SELECT MAX(sortqas.timecreated)\n                    FROM {question_attempt_steps} sortqas\n                    WHERE sortqas.questionattemptid = qa.id\n                        AND sortqas.state {$statetest}\n                    )";
     } else {
         if ($orderby == 'studentfirstname' || $orderby == 'studentlastname' || $orderby == 'idnumber') {
             $qubaids->from .= " JOIN {user} u ON quiza.userid = u.id ";
             // For name sorting, map orderby form value to
             // actual column names; 'idnumber' maps naturally
             switch ($orderby) {
                 case "studentlastname":
                     $orderby = "u.lastname, u.firstname";
                     break;
                 case "studentfirstname":
                     $orderby = "u.firstname, u.lastname";
                     break;
             }
         }
     }
     return $dm->load_questions_usages_where_question_in_state($qubaids, $summarystate, $slot, $questionid, $orderby, $params, $limitfrom, $pagesize);
 }
Пример #3
0
    /**
     * Get a list of usage ids where the question with slot $slot, and optionally
     * also with question id $questionid, is in summary state $summarystate. Also
     * return the total count of such states.
     *
     * Only a subset of the ids can be returned by using $orderby, $limitfrom and
     * $limitnum. A special value 'random' can be passed as $orderby, in which case
     * $limitfrom is ignored.
     *
     * @param int $slot The slot for the questions you want to konw about.
     * @param int $questionid (optional) Only return attempts that were of this specific question.
     * @param string $summarystate 'all', 'needsgrading', 'autograded' or 'manuallygraded'.
     * @param string $orderby 'random', 'date', 'student' or 'idnumber'.
     * @param int $page implements paging of the results.
     *      Ignored if $orderby = random or $pagesize is null.
     * @param int $pagesize implements paging of the results. null = all.
     */
    protected function get_usage_ids_where_question_in_state($summarystate, $slot,
            $questionid = null, $orderby = 'random', $page = 0, $pagesize = null) {
        global $CFG, $DB;
        $dm = new question_engine_data_mapper();

        if ($pagesize && $orderby != 'random') {
            $limitfrom = $page * $pagesize;
        } else {
            $limitfrom = 0;
        }

        $qubaids = $this->get_qubaids_condition();

        $params = array();
        if ($orderby == 'date') {
            list($statetest, $params) = $dm->in_summary_state_test(
                    'manuallygraded', false, 'mangrstate');
            $orderby = "(
                    SELECT MAX(sortqas.timecreated)
                    FROM {question_attempt_steps} sortqas
                    WHERE sortqas.questionattemptid = qa.id
                        AND sortqas.state $statetest
                    )";
        } else if ($orderby == 'student' || $orderby == 'idnumber') {
            $qubaids->from .= " JOIN {user} u ON quiza.userid = u.id ";
            if ($orderby == 'student') {
                $orderby = $DB->sql_fullname('u.firstname', 'u.lastname');
            }
        }

        return $dm->load_questions_usages_where_question_in_state($qubaids, $summarystate,
                $slot, $questionid, $orderby, $params, $limitfrom, $pagesize);
    }