+ ' the question name, the page number, and optionally the maxiumum mark. ' .
+ count($firstrow) . ' values passed.', $this->getSession());
+ }
+ $rows = $data->getRows();
+ array_unshift($rows, $headings);
+ $data->setRows($rows);
+ }
+
+ // Add the questions.
+ $lastpage = 0;
+ foreach ($data->getHash() as $questiondata) {
+ if (!array_key_exists('question', $questiondata)) {
+ throw new ExpectationException('When adding questions to a quiz, ' .
+ 'the question name column is required.', $this->getSession());
+ }
+ if (!array_key_exists('page', $questiondata)) {
+ throw new ExpectationException('When adding questions to a quiz, ' .
+ 'the page number column is required.', $this->getSession());
+ }
+
+ // Question id.
+ $questionid = $DB->get_field('question', 'id',
+ array('name' => $questiondata['question']), MUST_EXIST);
+
+ // Page number.
+ $page = clean_param($questiondata['page'], PARAM_INT);
+ if ($page <= 0 || (string) $page !== $questiondata['page']) {
+ throw new ExpectationException('The page number for question "' .
+ $questiondata['question'] . '" must be a positive integer.',
+ $this->getSession());
+ }
+ if ($page < $lastpage || $page > $lastpage + 1) {
+ throw new ExpectationException('When adding questions to a quiz, ' .
+ 'the page number for each question must either be the same, ' .
+ 'or one more, then the page number for the previous question.',
+ $this->getSession());