require_once $CFG->dirroot . '/mod/offlinequiz/locallib.php'; require_once $CFG->dirroot . '/question/editlib.php'; list($thispageurl, $contexts, $cmid, $cm, $offlinequiz, $pagevars) = question_edit_setup('editq', '/mod/offlinequiz/edit.php', true); // Get the course object and related bits. $course = $DB->get_record('course', array('id' => $offlinequiz->course), '*', MUST_EXIST); require_capability('mod/offlinequiz:manage', $contexts->lowest()); // Determine groupid. $groupnumber = optional_param('groupnumber', 1, PARAM_INT); if ($groupnumber === -1 and !empty($SESSION->question_pagevars['groupnumber'])) { $groupnumber = $SESSION->question_pagevars['groupnumber']; } if ($groupnumber === -1) { $groupnumber = 1; } $offlinequiz->groupnumber = $groupnumber; $thispageurl->param('groupnumber', $offlinequiz->groupnumber); // Load the offlinequiz group and set the groupid in the offlinequiz object. if ($offlinequizgroup = offlinequiz_get_group($offlinequiz, $groupnumber)) { $offlinequiz->groupid = $offlinequizgroup->id; $groupquestions = offlinequiz_get_group_question_ids($offlinequiz); $offlinequiz->questions = $groupquestions; } else { print_error('invalidgroupnumber', 'offlinequiz'); } // Create offlinequiz question bank view. $questionbank = new mod_offlinequiz\question\bank\custom_view($contexts, $thispageurl, $course, $cm, $offlinequiz); $questionbank->set_offlinequiz_has_scanned_pages(offlinequiz_has_scanned_pages($offlinequiz->id)); // Output. $output = $PAGE->get_renderer('mod_offlinequiz', 'edit'); $contents = $output->question_bank_contents($questionbank, $pagevars); echo json_encode(array('status' => 'OK', 'contents' => $contents));
/** * Get any warnings to show at the top of the edit page. * @return string[] array of strings. */ public function get_edit_page_warnings() { global $CFG; $warnings = array(); if (!$this->can_be_edited()) { $reviewlink = new \moodle_url($CFG->wwwroot . '/mod/offlinequiz/createquiz.php', array('q' => $this->offlinequizobj->get_offlinequiz()->id, 'mode' => 'createpdfs')); $warnings[] = get_string('formsexistx', 'offlinequiz', $reviewlink->out(false)); } if (offlinequiz_has_scanned_pages($this->offlinequizobj->get_offlinequizid())) { $reviewlink = offlinequiz_attempt_summary_link_to_reports($this->offlinequizobj->get_offlinequiz(), $this->offlinequizobj->get_cm(), $this->offlinequizobj->get_context()); $warnings[] = get_string('cannoteditafterattempts', 'offlinequiz', $reviewlink); } if ($this->is_shuffled()) { $updateurl = new \moodle_url('/course/mod.php', array('return' => 'true', 'update' => $this->offlinequizobj->get_cmid(), 'sesskey' => sesskey())); $updatelink = '<a href="' . $updateurl->out() . '">' . get_string('updatethis', '', get_string('modulename', 'offlinequiz')) . '</a>'; $warnings[] = get_string('shufflequestionsselected', 'offlinequiz', $updatelink); } if ($this->offlinequizobj->get_offlinequiz()->grade == 0) { $warnings[] = '<b>' . get_string('gradeiszero', 'offlinequiz') . '</b>'; } foreach ($this->warnings as $warning) { $warnings[] = '<b>' . $warning . '</b>'; } return $warnings; }
/** * Given an object containing all the necessary data, * (defined by the form in mod_form.php) this function * will update an existing instance with new data. * * @param object $offlinequiz An object from the form in mod_form.php * @return boolean Success/Fail */ function offlinequiz_update_instance($offlinequiz) { global $DB, $CFG; require_once $CFG->dirroot . '/mod/offlinequiz/locallib.php'; $offlinequiz->timemodified = time(); $offlinequiz->id = $offlinequiz->instance; // Remember the old values of the shuffle settings. $shufflequestions = $DB->get_field('offlinequiz', 'shufflequestions', array('id' => $offlinequiz->id)); $shuffleanswers = $DB->get_field('offlinequiz', 'shuffleanswers', array('id' => $offlinequiz->id)); // Process the options from the form. $result = offlinequiz_process_options($offlinequiz); if ($result && is_string($result)) { return $result; } $context = context_module::instance($offlinequiz->coursemodule); // Process the HTML editor data in pdfintro. if (property_exists($offlinequiz, 'pdfintro') && is_array($offlinequiz->pdfintro) && array_key_exists('text', $offlinequiz->pdfintro)) { if ($draftitemid = $offlinequiz->pdfintro['itemid']) { $editoroptions = offlinequiz_get_editor_options(); $offlinequiz->pdfintro = file_save_draft_area_files($draftitemid, $context->id, 'mod_offlinequiz', 'pdfintro', 0, $editoroptions, $offlinequiz->pdfintro['text']); } // $offlinequiz->pdfintro = $feedback->pdfintro['format']; } // Update the database. if (!$DB->update_record('offlinequiz', $offlinequiz)) { return false; // Some error occurred. } // Do the processing required after an add or an update. offlinequiz_after_add_or_update($offlinequiz); // We also need the docscreated and the numgroups field. $offlinequiz = $DB->get_record('offlinequiz', array('id' => $offlinequiz->id)); // Delete the question usage templates if no documents have been created and no answer forms have been scanned. if (!$offlinequiz->docscreated && !offlinequiz_has_scanned_pages($offlinequiz->id)) { offlinequiz_delete_template_usages($offlinequiz); } return true; }
} $path = clean_filename($path); $filelist[$path . '/' . $filename] = $file; } } $zipper = new zip_packer(); if ($zipper->archive_to_pathname($filelist, $tempzip)) { send_temp_file($tempzip, $zipfilename); } } // Print the page header. echo $OUTPUT->header(); // Print the offlinequiz name heading and tabs for teacher. $currenttab = 'createofflinequiz'; require 'tabs.php'; $hasscannedpages = offlinequiz_has_scanned_pages($offlinequiz->id); if ($offlinequiz->grade == 0) { echo '<div class="linkbox"><strong>'; echo $OUTPUT->notification(get_string('gradeiszero', 'offlinequiz'), 'notifyproblem'); echo '</strong></div>'; } // Preview. if ($mode == 'preview') { // Print shuffle again buttons. if (!$offlinequiz->docscreated && !$hasscannedpages) { echo $OUTPUT->heading(get_string('formspreview', 'offlinequiz')); echo $OUTPUT->box_start('generalbox controlbuttonbox'); unset($buttonoptions); $buttonoptions = array(); $buttonoptions['q'] = $offlinequiz->id; $buttonoptions['forcenew'] = true;
/** * Add a question to a offlinequiz group * * Adds a question to a offlinequiz by updating $offlinequiz as well as the * offlinequiz and offlinequiz_question_instances tables. It also adds a page break * if required. * @param int $id The id of the question to be added * @param object $offlinequiz The extended offlinequiz object as used by edit.php * This is updated by this function * @param int $page Which page in offlinequiz to add the question on. If 0 (default), * add at the end * @return bool false if the question was already in the offlinequiz */ function offlinequiz_add_questionlist_to_group($questionids, $offlinequiz, $offlinegroup, $fromofflinegroup = null, $maxmarks = null) { global $DB; if (offlinequiz_has_scanned_pages($offlinequiz->id)) { return false; } // Don't add the same question twice. foreach ($questionids as $questionid) { $slots = $DB->get_records('offlinequiz_group_questions', array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $offlinegroup->id), 'slot', 'questionid, slot, page, id'); if (array_key_exists($questionid, $slots)) { continue; } $trans = $DB->start_delegated_transaction(); // If the question is already in another group, take the maxmark of that. $maxmark = null; if ($fromofflinegroup && ($oldmaxmark = $DB->get_field('offlinequiz_group_questions', 'maxmark', array('offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $fromofflinegroup, 'questionid' => $questionid)))) { $maxmark = $oldmaxmark; } else { if ($maxmarks && array_key_exists($questionid, $maxmarks)) { $maxmark = $maxmarks[$questionid]; } } $maxpage = 1; $numonlastpage = 0; foreach ($slots as $slot) { if ($slot->page > $maxpage) { $maxpage = $slot->page; $numonlastpage = 1; } else { $numonlastpage += 1; } } // Add the new question instance. $slot = new stdClass(); $slot->offlinequizid = $offlinequiz->id; $slot->offlinegroupid = $offlinegroup->id; $slot->questionid = $questionid; if ($maxmark !== null) { $slot->maxmark = $maxmark; } else { $slot->maxmark = $DB->get_field('question', 'defaultmark', array('id' => $questionid)); } $lastslot = end($slots); if ($lastslot) { $slot->slot = $lastslot->slot + 1; } else { $slot->slot = 1; } $slot->page = 0; if (!$slot->page) { if ($offlinequiz->questionsperpage && $numonlastpage >= $offlinequiz->questionsperpage) { $slot->page = $maxpage + 1; } else { $slot->page = $maxpage; } } $DB->insert_record('offlinequiz_group_questions', $slot); $trans->allow_commit(); } }
} if ($groupnumber === -1) { $groupnumber = 1; } $offlinequiz->groupnumber = $groupnumber; $thispageurl->param('groupnumber', $offlinequiz->groupnumber); // Load the offlinequiz group and set the groupid in the offlinequiz object. if ($offlinequizgroup = offlinequiz_get_group($offlinequiz, $groupnumber)) { $offlinequiz->groupid = $offlinequizgroup->id; $groupquestions = offlinequiz_get_group_question_ids($offlinequiz); $offlinequiz->questions = $groupquestions; } else { print_error('invalidgroupnumber', 'offlinequiz'); } $offlinequiz->sumgrades = $offlinequizgroup->sumgrades; $offlinequizhasattempts = offlinequiz_has_scanned_pages($offlinequiz->id); $docscreated = $offlinequiz->docscreated; $PAGE->set_url($thispageurl); // Get the course object and related bits. $course = $DB->get_record('course', array('id' => $offlinequiz->course), '*', MUST_EXIST); $offlinequizobj = new offlinequiz($offlinequiz, $cm, $course); $structure = $offlinequizobj->get_structure(); if ($warning = optional_param('warning', '', PARAM_TEXT)) { $structure->add_warning(urldecode($warning)); } // You need mod/offlinequiz:manage in addition to question capabilities to access this page. require_capability('mod/offlinequiz:manage', $contexts->lowest()); // Log this visit. $params = array('courseid' => $course->id, 'context' => $contexts->lowest(), 'other' => array('offlinequizid' => $offlinequiz->id)); $event = \mod_offlinequiz\event\edit_page_viewed::create($params); $event->trigger();
/** * Display an icon to split or join two pages of the offlinequiz. * * @param \stdClass $offlinequiz the offlinequiz settings from the database. * @param \stdClass $question data from the question and offlinequiz_slots tables. * @param bool $insertpagebreak if true, show an insert page break icon. * else show a join pages icon. * @return string HTML to output. */ public function page_split_join_button($offlinequiz, $question, $insertpagebreak) { $url = new \moodle_url('repaginate.php', array('cmid' => $offlinequiz->cmid, 'offlinequizid' => $offlinequiz->id, 'offlinegroupid' => $offlinequiz->groupid, 'slot' => $question->slot, 'repag' => $insertpagebreak ? 2 : 1, 'sesskey' => sesskey())); if ($insertpagebreak) { $title = get_string('addpagebreak', 'offlinequiz'); $image = $this->pix_icon('e/insert_page_break', $title); $action = 'addpagebreak'; } else { $title = get_string('removepagebreak', 'offlinequiz'); $image = $this->pix_icon('e/remove_page_break', $title); $action = 'removepagebreak'; } // Disable the link if offlinequiz has attempts. $disabled = null; if (offlinequiz_has_scanned_pages($offlinequiz->id)) { $disabled = "disabled"; } return html_writer::span($this->action_link($url, $image, null, array('title' => $title, 'class' => 'page_split_join cm-edit-action', 'disabled' => $disabled, 'data-action' => $action)), 'page_split_join_wrapper'); }
* @package mod * @subpackage offlinequiz * @author Juergen Zimmer <*****@*****.**> * @copyright 2015 Academic Moodle Cooperation {@link http://www.academic-moodle-cooperation.org} * @since Moodle 2.8 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ require_once __DIR__ . '/../../config.php'; require_once $CFG->dirroot . '/mod/offlinequiz/locallib.php'; require_once $CFG->dirroot . '/mod/offlinequiz/offlinequiz.class.php'; $cmid = required_param('cmid', PARAM_INT); $offlinequizid = required_param('offlinequizid', PARAM_INT); $offlinegroupid = required_param('offlinegroupid', PARAM_INT); $slotnumber = required_param('slot', PARAM_INT); $repagtype = required_param('repag', PARAM_INT); require_sesskey(); $offlinequizobj = offlinequiz::create($offlinequizid, $offlinegroupid); $group = $DB->get_record('offlinequiz_groups', array('id' => $offlinegroupid)); require_login($offlinequizobj->get_course(), false, $offlinequizobj->get_cm()); require_capability('mod/offlinequiz:manage', $offlinequizobj->get_context()); if (offlinequiz_has_scanned_pages($offlinequizid)) { $reportlink = offlinequiz_attempt_summary_link_to_reports($offlinequizobj->get_offlinequiz(), $offlinequizobj->get_cm(), $offlinequizobj->get_context()); throw new \moodle_exception('cannoteditafterattempts', 'offlinequiz', new moodle_url('/mod/offlinequiz/edit.php', array('cmid' => $cmid)), $reportlink); } $slotnumber++; $repage = new \mod_offlinequiz\repaginate($offlinequizid, $offlinegroupid); $repage->repaginate_slots($slotnumber, $repagtype); offlinequiz_delete_template_usages($offlinequizobj->get_offlinequiz()); $structure = $offlinequizobj->get_structure(); $slots = $structure->refresh_page_numbers_and_update_db($structure->get_offlinequiz()); redirect(new moodle_url('edit.php', array('cmid' => $offlinequizobj->get_cmid(), 'groupnumber' => $group->number)));