return new self();
}
- /**
- * Create an instance of this class representing the structure of a given quiz.
- * @param \stdClass $quiz the quiz settings.
- * @return structure
- */
- public static function create_for($quiz) {
- $structure = self::create();
- $structure->populate_structure($quiz);
- return $structure;
- }
-
/**
* Create an instance of this class representing the structure of a given quiz.
* @param \quiz $quizobj the quiz.
* @return structure
*/
public static function create_for_quiz($quizobj) {
- $structure = self::create_for($quizobj->get_quiz());
+ $structure = self::create();
$structure->quizobj = $quizobj;
+ $structure->populate_structure($quizobj->get_quiz());
return $structure;
}
$quiz = $quizgenerator->create_instance(array(
'course' => $SITE->id, 'questionsperpage' => 0, 'grade' => 100.0, 'sumgrades' => 2));
+ $cm = get_coursemodule_from_instance('quiz', $quiz->id, $SITE->id);
// Create five questions.
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
quiz_add_quiz_question($match->id, $quiz);
// Return the quiz object.
- return \mod_quiz\structure::create_for($quiz);
+ $quizobj = new quiz($quiz, $cm, $SITE);
+ return \mod_quiz\structure::create_for_quiz($quizobj);
}
/**
// Setup a quiz with 1 standard and 1 random question.
$quizgenerator = $this->getDataGenerator()->get_plugin_generator('mod_quiz');
$quiz = $quizgenerator->create_instance(array('course' => $SITE->id, 'questionsperpage' => 3, 'grade' => 100.0));
+ $cm = get_coursemodule_from_instance('quiz', $quiz->id, $SITE->id);
$questiongenerator = $this->getDataGenerator()->get_plugin_generator('core_question');
$cat = $questiongenerator->create_question_category();
// Get the random question.
$randomq = $DB->get_record('question', array('qtype' => 'random'));
- $structure = \mod_quiz\structure::create_for($quiz);
+ $quizobj = new quiz($quiz, $cm, $SITE);
+ $structure = \mod_quiz\structure::create_for_quiz($quizobj);
// Check that the setup looks right.
$this->assertEquals(2, $structure->get_question_count());
// Remove the standard question.
$structure->remove_slot($quiz, 1);
- $alteredstructure = \mod_quiz\structure::create_for($quiz);
+ $alteredstructure = \mod_quiz\structure::create_for_quiz($quizobj);
// Check the new ordering, and that the slot number was updated.
$this->assertEquals(1, $alteredstructure->get_question_count());
// Remove the random question.
$structure->remove_slot($quiz, 1);
- $alteredstructure = \mod_quiz\structure::create_for($quiz);
+ $alteredstructure = \mod_quiz\structure::create_for_quiz($quizobj);
// Check that new ordering.
$this->assertEquals(0, $alteredstructure->get_question_count());