Beispiel #1
0
/**
 * Returns subquestions for a given question (ordered).
 *
 * @param  stdClass $question questin object
 * @return array list of subquestions ordered
 * @since Moodle 3.0
 */
function survey_get_subquestions($question) {
    global $DB;

    $questionids = explode(',', $question->multi);
    $questions = $DB->get_records_list("survey_questions", "id", $questionids);

    return survey_order_questions($questions, $questionids);
}
Beispiel #2
0
 /**
  * Test survey_order_questions
  */
 public function test_survey_order_questions()
 {
     global $DB;
     $this->resetAfterTest();
     $course = $this->getDataGenerator()->create_course();
     $survey = $this->getDataGenerator()->create_module('survey', array('course' => $course->id));
     $orderedquestionids = explode(',', $survey->questions);
     $surveyquestions = $DB->get_records_list("survey_questions", "id", $orderedquestionids);
     $questionsordered = survey_order_questions($surveyquestions, $orderedquestionids);
     // Check one by one the correct order.
     for ($i = 0; $i < count($orderedquestionids); $i++) {
         $this->assertEquals($orderedquestionids[$i], $questionsordered[$i]->id);
     }
 }