if ($attempt_id) { //print the given attempt, if the user has the appropriate access printable_copy_helper::print_attempt($attempt_id); } elseif ($cm_id) { //create a new printable_copy_helper $printer = printable_copy_helper::create_from_coursemodule($cm_id); //retrieve optional arguments for the printer, which are only appropriate for the report view $batch_mode = optional_param('mode', '', PARAM_ALPHA); //if a QUBA was specified, print it, and only it (the helper methods check permissions) if ($quba_id) { $printer->print_question_usage_by_activity($quba_id, $batch_mode); } else { if ($batch_id) { //disable purification on batch jobs, as it takes up too much RAM //(the print_batch function will handle purification) core_pdf_renderer::$do_not_purify = true; // If "force-rerender" is _not_ set, and a pre-rendered batch exists, // (e.g. this batch has been rendered before), then print the pre-rendered batch. // // TODO: Perhaps don't run this part if we're going to pre-render, but instead print an "already rendered" // message? if (!$force_rerender) { // If a pre-rendered batch exits, print it. Otherwise, this will return false. $printed = $printer->print_prerendered_batch($batch_id); // If we printed a batch, then terminate this script's execution. // If we don't abort here, Moodle will append a blank PDF to the end of our full PDF file. if ($printed) { exit; } } // If the pre-render option is set, then begin executing the "interactive pre-renderer", which
protected function print_quba($quba_id, $batch_mode, $include_barcodes = true, $include_intro = true) { //get the default question display information $options = new question_display_options_pdf(); //get a question usage object from the database $usage = question_engine::load_questions_usage_by_activity($quba_id); //get an associative array, which indicates the questions which should be rendered $slots = $usage->get_slots(); //if we're not _only_ outputting a key, output the core of the quesiton if ($batch_mode !== quiz_papercopy_batch_mode::KEY_ONLY) { //start a new copy with the given margins echo html_writer::start_tag('page', array('backtop' => '9mm', 'backbottom' => '0mm', 'backleft' => '0mm', 'backright' => '8mm')); if ($include_barcodes) { //echo html_writer::start_tag('page_header'); echo self::render_barcode($quba_id); //echo html_writer::end_tag('page_header'); } else { echo html_writer::tag('div', $quba_id, array('class' => 'qubaid')); } //bookmark, for easy access from a PDF viewer echo html_writer::tag('bookmark', '', array('title' => get_string('copynumber', 'quiz_papercopy', $quba_id), 'level' => '0')); //print the quiz's introduction if (!empty($this->quiz->intro) && $include_intro) { $introtext = $this->quiz->intro; $introtext = file_rewrite_pluginfile_urls($this->quiz->intro, 'pluginfile.php', $this->context->id, 'mod_quiz', 'intro', null); echo html_writer::tag('div', self::insert_ids($introtext, $quba_id), array('class' => 'introduction')); } //output each question foreach ($slots as $slot => $question) { $qbuf = $usage->render_question($question, $options, $slot + 1); //if the core PDF renderer has purification turned off, purify the question locally if (core_pdf_renderer::$do_not_purify) { $qbuf = core_pdf_renderer::clean_with_htmlpurify($qbuf); } echo $qbuf; } echo html_writer::end_tag('page'); } //if a key has been requested, output it as well if ($batch_mode == quiz_papercopy_batch_mode::KEY_ONLY || $batch_mode == quiz_papercopy_batch_mode::WITH_KEY) { //start a new copy with the given margins echo html_writer::start_tag('page', array('backtop' => '9mm', 'backbottom' => '0mm', 'backleft' => '0mm', 'backright' => '8mm')); //start of page headers if ($include_barcodes) { echo html_writer::start_tag('page_header'); echo html_writer::start_tag('div', array('align' => 'center')); echo html_writer::tag('barcode', '', array('value' => $id, 'style' => 'width: 40mm; height: 7mm;', 'label' => 'label')); echo html_writer::end_tag('div'); echo html_writer::end_tag('page_header'); } //bookmark, for easy access from a PDF viewer echo html_writer::tag('bookmark', '', array('title' => get_string('answerkeynumber', 'quiz_papercopy', $quba_id), 'level' => $batch_mode !== quiz_papercopy_batch_mode::KEY_ONLY)); //print the quiz's introduction echo html_writer::tag('p', get_string('answerkeyfortestid', 'quiz_papercopy', $quba_id), array('style' => 'font-weight:bold;')); echo html_writer::start_tag('table'); //output each question foreach ($slots as $slot => $question) { echo html_writer::start_tag('tr'); //echo the answer key contents echo html_writer::tag('td', $slot + 1 . '. ', array('style' => 'padding-right: 10px;')); echo html_writer::tag('td', $usage->get_right_answer_summary($question)); echo html_writer::end_tag('tr'); } echo html_writer::start_tag('table'); echo html_writer::end_tag('page'); } }