/** * Verify that the given layout matches that expected. * @param array $expectedlayout as for $layout in {@link create_test_quiz()}. * @param \mod_quiz\structure $structure the structure to test. */ protected function assert_quiz_layout($expectedlayout, \mod_quiz\structure $structure) { $sections = $structure->get_sections(); $slot = 1; foreach ($expectedlayout as $item) { if (is_string($item)) { list($heading, $shuffle) = $this->parse_section_name($item); $section = array_shift($sections); if ($slot > 1 && $section->heading == '' && $section->firstslot == 1) { // The array $expectedlayout did not contain default first quiz section, so skip over it. $section = array_shift($sections); } $this->assertEquals($slot, $section->firstslot); $this->assertEquals($heading, $section->heading); $this->assertEquals($shuffle, $section->shufflequestions); } else { list($name, $page, $qtype) = $item; $question = $structure->get_question_in_slot($slot); $this->assertEquals($name, $question->name); $this->assertEquals($slot, $question->slot, 'Slot number wrong for question ' . $name); $this->assertEquals($qtype, $question->qtype, 'Question type wrong for question ' . $name); $this->assertEquals($page, $question->page, 'Page number wrong for question ' . $name); $slot += 1; } } if ($slot - 1 != count($structure->get_slots())) { $this->fail('The quiz contains more slots than expected.'); } if (!empty($sections)) { $section = array_shift($sections); if ($section->heading != '' || $section->firstslot != 1) { $this->fail('Unexpected section (' . $section->heading . ') found in the quiz.'); } } }
/** * Renders html to display a random question the link to edit the configuration * and also to see that category in the question bank. * * @param structure $structure object containing the structure of the quiz. * @param int $slot which slot we are outputting. * @param \moodle_url $pageurl the canonical URL of this page. * @return string HTML to output. */ public function random_question(structure $structure, $slot, $pageurl) { $question = $structure->get_question_in_slot($slot); $editurl = new \moodle_url('/question/question.php', array('returnurl' => $pageurl->out_as_local_url(), 'cmid' => $structure->get_cmid(), 'id' => $question->id)); $temp = clone $question; $temp->questiontext = ''; $instancename = quiz_question_tostring($temp); $configuretitle = get_string('configurerandomquestion', 'quiz'); $qtype = \question_bank::get_qtype($question->qtype, false); $namestr = $qtype->local_name(); $icon = $this->pix_icon('icon', $namestr, $qtype->plugin_name(), array('title' => $namestr, 'class' => 'icon activityicon', 'alt' => ' ', 'role' => 'presentation')); $editicon = $this->pix_icon('t/edit', $configuretitle, 'moodle', array('title' => '')); // If this is a random question, display a link to show the questions // selected from in the question bank. $qbankurl = new \moodle_url('/question/edit.php', array('cmid' => $structure->get_cmid(), 'cat' => $question->category . ',' . $question->contextid, 'recurse' => !empty($question->questiontext))); $qbanklink = ' ' . \html_writer::link($qbankurl, get_string('seequestions', 'quiz'), array('class' => 'mod_quiz_random_qbank_link')); return html_writer::link($editurl, $icon . $editicon, array('title' => $configuretitle)) . ' ' . $instancename . ' ' . $qbanklink; }
/** * HTML for a page, with ids stripped, so it can be used as a javascript template. * * @param structure $structure object containing the structure of the quiz. * @param \stdClass $quiz the quiz settings. * @return string HTML for a new icon */ protected function add_page_icon_template(structure $structure, $quiz) { if (!$structure->has_questions()) { return ''; } $question = $structure->get_question_in_slot(1); $html = $this->page_split_join_button($quiz, $question, true); return str_replace('&slot=1&', '&slot=%%SLOT%%&', $html); }
/** * Verify that the given layout matches that expected. * @param array $expectedlayout * @param \mod_quiz\structure $structure */ protected function assert_quiz_layout($expectedlayout, \mod_quiz\structure $structure) { $slotnumber = 0; foreach ($expectedlayout as $slotid => $page) { $slotnumber += 1; $this->assertEquals($slotid, $structure->get_question_in_slot($slotnumber)->slotid, 'Wrong question in slot ' . $slotnumber); $this->assertEquals($page, $structure->get_question_in_slot($slotnumber)->page, 'Wrong page number for slot ' . $slotnumber); } }