public function load_choices() { global $CFG; if (is_array($this->choices)) { return true; } require_once $CFG->dirroot . '/mod/quiz/locallib.php'; $this->choices = quiz_get_user_image_options(); return true; }
protected function definition() { global $COURSE, $CFG, $DB, $PAGE; $quizconfig = get_config('quiz'); $mform = $this->_form; // ------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); // Name. $mform->addElement('text', 'name', get_string('name'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEANHTML); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client'); // Introduction. $this->add_intro_editor(false, get_string('introduction', 'quiz')); // ------------------------------------------------------------------------------- $mform->addElement('header', 'timing', get_string('timing', 'quiz')); // Open and close dates. $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), self::$datefieldoptions); $mform->addHelpButton('timeopen', 'quizopenclose', 'quiz'); $mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), self::$datefieldoptions); // Time limit. $mform->addElement('duration', 'timelimit', get_string('timelimit', 'quiz'), array('optional' => true)); $mform->addHelpButton('timelimit', 'timelimit', 'quiz'); $mform->setAdvanced('timelimit', $quizconfig->timelimit_adv); $mform->setDefault('timelimit', $quizconfig->timelimit); // What to do with overdue attempts. $mform->addElement('select', 'overduehandling', get_string('overduehandling', 'quiz'), quiz_get_overdue_handling_options()); $mform->addHelpButton('overduehandling', 'overduehandling', 'quiz'); $mform->setAdvanced('overduehandling', $quizconfig->overduehandling_adv); $mform->setDefault('overduehandling', $quizconfig->overduehandling); // TODO Formslib does OR logic on disableif, and we need AND logic here. // $mform->disabledIf('overduehandling', 'timelimit', 'eq', 0); // $mform->disabledIf('overduehandling', 'timeclose', 'eq', 0); // Grace period time. $mform->addElement('duration', 'graceperiod', get_string('graceperiod', 'quiz'), array('optional' => true)); $mform->addHelpButton('graceperiod', 'graceperiod', 'quiz'); $mform->setAdvanced('graceperiod', $quizconfig->graceperiod_adv); $mform->setDefault('graceperiod', $quizconfig->graceperiod); $mform->disabledIf('graceperiod', 'overduehandling', 'neq', 'graceperiod'); // ------------------------------------------------------------------------------- // Grade settings. $this->standard_grading_coursemodule_elements(); $mform->removeElement('grade'); $mform->addElement('hidden', 'grade', $quizconfig->maximumgrade); $mform->setType('grade', PARAM_FLOAT); // Number of attempts. $attemptoptions = array('0' => get_string('unlimited')); for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) { $attemptoptions[$i] = $i; } $mform->addElement('select', 'attempts', get_string('attemptsallowed', 'quiz'), $attemptoptions); $mform->setAdvanced('attempts', $quizconfig->attempts_adv); $mform->setDefault('attempts', $quizconfig->attempts); // Grading method. $mform->addElement('select', 'grademethod', get_string('grademethod', 'quiz'), quiz_get_grading_options()); $mform->addHelpButton('grademethod', 'grademethod', 'quiz'); $mform->setAdvanced('grademethod', $quizconfig->grademethod_adv); $mform->setDefault('grademethod', $quizconfig->grademethod); if ($this->get_max_attempts_for_any_override() < 2) { $mform->disabledIf('grademethod', 'attempts', 'eq', 1); } // ------------------------------------------------------------------------------- $mform->addElement('header', 'layouthdr', get_string('layout', 'quiz')); // Shuffle questions. $shuffleoptions = array(0 => get_string('asshownoneditscreen', 'quiz'), 1 => get_string('shuffledrandomly', 'quiz')); $mform->addElement('select', 'shufflequestions', get_string('questionorder', 'quiz'), $shuffleoptions, array('id' => 'id_shufflequestions')); $mform->setAdvanced('shufflequestions', $quizconfig->shufflequestions_adv); $mform->setDefault('shufflequestions', $quizconfig->shufflequestions); // Questions per page. $pageoptions = array(); $pageoptions[0] = get_string('neverallononepage', 'quiz'); $pageoptions[1] = get_string('everyquestion', 'quiz'); for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) { $pageoptions[$i] = get_string('everynquestions', 'quiz', $i); } $pagegroup = array(); $pagegroup[] = $mform->createElement('select', 'questionsperpage', get_string('newpage', 'quiz'), $pageoptions, array('id' => 'id_questionsperpage')); $mform->setDefault('questionsperpage', $quizconfig->questionsperpage); if (!empty($this->_cm)) { $pagegroup[] = $mform->createElement('checkbox', 'repaginatenow', '', get_string('repaginatenow', 'quiz'), array('id' => 'id_repaginatenow')); $mform->disabledIf('repaginatenow', 'shufflequestions', 'eq', 1); $PAGE->requires->js('/question/qengine.js'); $module = array('name' => 'mod_quiz_edit', 'fullpath' => '/mod/quiz/edit.js', 'requires' => array('yui2-dom', 'yui2-event', 'yui2-container'), 'strings' => array(), 'async' => false); $PAGE->requires->js_init_call('quiz_settings_init', null, false, $module); } $mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false); $mform->addHelpButton('questionsperpagegrp', 'newpage', 'quiz'); $mform->setAdvanced('questionsperpagegrp', $quizconfig->questionsperpage_adv); // Navigation method. $mform->addElement('select', 'navmethod', get_string('navmethod', 'quiz'), quiz_get_navigation_options()); $mform->addHelpButton('navmethod', 'navmethod', 'quiz'); $mform->setAdvanced('navmethod', $quizconfig->navmethod_adv); $mform->setDefault('navmethod', $quizconfig->navmethod); // ------------------------------------------------------------------------------- $mform->addElement('header', 'interactionhdr', get_string('questionbehaviour', 'quiz')); // Shuffle within questions. $mform->addElement('selectyesno', 'shuffleanswers', get_string('shufflewithin', 'quiz')); $mform->addHelpButton('shuffleanswers', 'shufflewithin', 'quiz'); $mform->setAdvanced('shuffleanswers', $quizconfig->shuffleanswers_adv); $mform->setDefault('shuffleanswers', $quizconfig->shuffleanswers); // How questions behave (question behaviour). if (!empty($this->current->preferredbehaviour)) { $currentbehaviour = $this->current->preferredbehaviour; } else { $currentbehaviour = ''; } $behaviours = question_engine::get_behaviour_options($currentbehaviour); $mform->addElement('select', 'preferredbehaviour', get_string('howquestionsbehave', 'question'), $behaviours); $mform->addHelpButton('preferredbehaviour', 'howquestionsbehave', 'question'); $mform->setDefault('preferredbehaviour', $quizconfig->preferredbehaviour); // Each attempt builds on last. $mform->addElement('selectyesno', 'attemptonlast', get_string('eachattemptbuildsonthelast', 'quiz')); $mform->addHelpButton('attemptonlast', 'eachattemptbuildsonthelast', 'quiz'); $mform->setAdvanced('attemptonlast', $quizconfig->attemptonlast_adv); $mform->setDefault('attemptonlast', $quizconfig->attemptonlast); if ($this->get_max_attempts_for_any_override() < 2) { $mform->disabledIf('attemptonlast', 'attempts', 'eq', 1); } // ------------------------------------------------------------------------------- $mform->addElement('header', 'reviewoptionshdr', get_string('reviewoptionsheading', 'quiz')); $mform->addHelpButton('reviewoptionshdr', 'reviewoptionsheading', 'quiz'); // Review options. $this->add_review_options_group($mform, $quizconfig, 'during', mod_quiz_display_options::DURING, true); $this->add_review_options_group($mform, $quizconfig, 'immediately', mod_quiz_display_options::IMMEDIATELY_AFTER); $this->add_review_options_group($mform, $quizconfig, 'open', mod_quiz_display_options::LATER_WHILE_OPEN); $this->add_review_options_group($mform, $quizconfig, 'closed', mod_quiz_display_options::AFTER_CLOSE); foreach ($behaviours as $behaviour => $notused) { $unusedoptions = question_engine::get_behaviour_unused_display_options($behaviour); foreach ($unusedoptions as $unusedoption) { $mform->disabledIf($unusedoption . 'during', 'preferredbehaviour', 'eq', $behaviour); } } $mform->disabledIf('attemptduring', 'preferredbehaviour', 'neq', 'wontmatch'); $mform->disabledIf('overallfeedbackduring', 'preferredbehaviour', 'neq', 'wontmatch'); // ------------------------------------------------------------------------------- $mform->addElement('header', 'display', get_string('display', 'form')); // Show user picture. $mform->addElement('select', 'showuserpicture', get_string('showuserpicture', 'quiz'), quiz_get_user_image_options()); $mform->addHelpButton('showuserpicture', 'showuserpicture', 'quiz'); $mform->setAdvanced('showuserpicture', $quizconfig->showuserpicture_adv); $mform->setDefault('showuserpicture', $quizconfig->showuserpicture); // Overall decimal points. $options = array(); for ($i = 0; $i <= QUIZ_MAX_DECIMAL_OPTION; $i++) { $options[$i] = $i; } $mform->addElement('select', 'decimalpoints', get_string('decimalplaces', 'quiz'), $options); $mform->addHelpButton('decimalpoints', 'decimalplaces', 'quiz'); $mform->setAdvanced('decimalpoints', $quizconfig->decimalpoints_adv); $mform->setDefault('decimalpoints', $quizconfig->decimalpoints); // Question decimal points. $options = array(-1 => get_string('sameasoverall', 'quiz')); for ($i = 0; $i <= QUIZ_MAX_Q_DECIMAL_OPTION; $i++) { $options[$i] = $i; } $mform->addElement('select', 'questiondecimalpoints', get_string('decimalplacesquestion', 'quiz'), $options); $mform->addHelpButton('questiondecimalpoints', 'decimalplacesquestion', 'quiz'); $mform->setAdvanced('questiondecimalpoints', $quizconfig->questiondecimalpoints_adv); $mform->setDefault('questiondecimalpoints', $quizconfig->questiondecimalpoints); // Show blocks during quiz attempt. $mform->addElement('selectyesno', 'showblocks', get_string('showblocks', 'quiz')); $mform->addHelpButton('showblocks', 'showblocks', 'quiz'); $mform->setAdvanced('showblocks', $quizconfig->showblocks_adv); $mform->setDefault('showblocks', $quizconfig->showblocks); // ------------------------------------------------------------------------------- $mform->addElement('header', 'security', get_string('extraattemptrestrictions', 'quiz')); // Require password to begin quiz attempt. $mform->addElement('passwordunmask', 'quizpassword', get_string('requirepassword', 'quiz')); $mform->setType('quizpassword', PARAM_TEXT); $mform->addHelpButton('quizpassword', 'requirepassword', 'quiz'); $mform->setAdvanced('quizpassword', $quizconfig->password_adv); $mform->setDefault('quizpassword', $quizconfig->password); // IP address. $mform->addElement('text', 'subnet', get_string('requiresubnet', 'quiz')); $mform->setType('subnet', PARAM_TEXT); $mform->addHelpButton('subnet', 'requiresubnet', 'quiz'); $mform->setAdvanced('subnet', $quizconfig->subnet_adv); $mform->setDefault('subnet', $quizconfig->subnet); // Enforced time delay between quiz attempts. $mform->addElement('duration', 'delay1', get_string('delay1st2nd', 'quiz'), array('optional' => true)); $mform->addHelpButton('delay1', 'delay1st2nd', 'quiz'); $mform->setAdvanced('delay1', $quizconfig->delay1_adv); $mform->setDefault('delay1', $quizconfig->delay1); if ($this->get_max_attempts_for_any_override() < 2) { $mform->disabledIf('delay1', 'attempts', 'eq', 1); } $mform->addElement('duration', 'delay2', get_string('delaylater', 'quiz'), array('optional' => true)); $mform->addHelpButton('delay2', 'delaylater', 'quiz'); $mform->setAdvanced('delay2', $quizconfig->delay2_adv); $mform->setDefault('delay2', $quizconfig->delay2); if ($this->get_max_attempts_for_any_override() < 3) { $mform->disabledIf('delay2', 'attempts', 'eq', 1); $mform->disabledIf('delay2', 'attempts', 'eq', 2); } // Browser security choices. $mform->addElement('select', 'browsersecurity', get_string('browsersecurity', 'quiz'), quiz_access_manager::get_browser_security_choices()); $mform->addHelpButton('browsersecurity', 'browsersecurity', 'quiz'); $mform->setAdvanced('browsersecurity', $quizconfig->browsersecurity_adv); $mform->setDefault('browsersecurity', $quizconfig->browsersecurity); // Any other rule plugins. quiz_access_manager::add_settings_form_fields($this, $mform); // ------------------------------------------------------------------------------- $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz')); $mform->addHelpButton('overallfeedbackhdr', 'overallfeedback', 'quiz'); if (isset($this->current->grade)) { $needwarning = $this->current->grade === 0; } else { $needwarning = $quizconfig->maximumgrade == 0; } if ($needwarning) { $mform->addElement('static', 'nogradewarning', '', get_string('nogradewarning', 'quiz')); } $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%'); $repeatarray = array(); $repeatedoptions = array(); $repeatarray[] = $mform->createElement('editor', 'feedbacktext', get_string('feedback', 'quiz'), array('rows' => 3), array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $this->context)); $repeatarray[] = $mform->createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10)); $repeatedoptions['feedbacktext']['type'] = PARAM_RAW; $repeatedoptions['feedbackboundaries']['type'] = PARAM_RAW; if (!empty($this->_instance)) { $this->_feedbacks = $DB->get_records('quiz_feedback', array('quizid' => $this->_instance), 'mingrade DESC'); } else { $this->_feedbacks = array(); } $numfeedbacks = max(count($this->_feedbacks) * 1.5, 5); $nextel = $this->repeat_elements($repeatarray, $numfeedbacks - 1, $repeatedoptions, 'boundary_repeats', 'boundary_add_fields', 3, get_string('addmoreoverallfeedbacks', 'quiz'), true); // Put some extra elements in before the button. $mform->insertElementBefore($mform->createElement('editor', "feedbacktext[{$nextel}]", get_string('feedback', 'quiz'), array('rows' => 3), array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $this->context)), 'boundary_add_fields'); $mform->insertElementBefore($mform->createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%'), 'boundary_add_fields'); // Add the disabledif rules. We cannot do this using the $repeatoptions parameter to // repeat_elements because we don't want to dissable the first feedbacktext. for ($i = 0; $i < $nextel; $i++) { $mform->disabledIf('feedbackboundaries[' . $i . ']', 'grade', 'eq', 0); $mform->disabledIf('feedbacktext[' . ($i + 1) . ']', 'grade', 'eq', 0); } // ------------------------------------------------------------------------------- $this->standard_coursemodule_elements(); // Check and act on whether setting outcomes is considered an advanced setting. $mform->setAdvanced('modoutcomes', !empty($quizconfig->outcomes_adv)); // The standard_coursemodule_elements method sets this to 100, but the // quiz has its own setting, so use that. $mform->setDefault('grade', $quizconfig->maximumgrade); // ------------------------------------------------------------------------------- $this->add_action_buttons(); }