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_grading_options(); return true; }
protected function definition() { $mform = $this->_form; $mform->addElement('header', 'preferencespage', get_string('reportsettings', 'quiz_statistics')); $options = array(); foreach (array_keys(quiz_get_grading_options()) as $which) { $options[$which] = \quiz_statistics_calculator::using_attempts_lang_string($which); } $mform->addElement('select', 'whichattempts', get_string('calculatefrom', 'quiz_statistics'), $options); $mform->addElement('submit', 'submitbutton', get_string('preferencessave', 'quiz_overview')); }
protected function definition() { $mform = $this->_form; $mform->addElement('header', 'preferencespage', get_string('reportsettings', 'quiz_statistics')); $options = array(); foreach (array_keys(quiz_get_grading_options()) as $which) { $options[$which] = \quiz_statistics\calculator::using_attempts_lang_string($which); } $mform->addElement('select', 'whichattempts', get_string('calculatefrom', 'quiz_statistics'), $options); if (quiz_allows_multiple_tries($this->_customdata['quiz'])) { $mform->addElement('select', 'whichtries', get_string('whichtries', 'quiz_statistics'), array(question_attempt::FIRST_TRY => get_string('firsttry', 'question'), question_attempt::LAST_TRY => get_string('lasttry', 'question'), question_attempt::ALL_TRIES => get_string('alltries', 'question'))); $mform->setDefault('whichtries', question_attempt::LAST_TRY); } $mform->addElement('submit', 'submitbutton', get_string('preferencessave', 'quiz_overview')); }
/** * @param int $option one of the values QUIZ_GRADEHIGHEST, QUIZ_GRADEAVERAGE, QUIZ_ATTEMPTFIRST or QUIZ_ATTEMPTLAST. * @return the lang string for that option. */ function quiz_get_grading_option_name($option) { $strings = quiz_get_grading_options(); return $strings[$option]; }
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(); }
/** * Calculating count and mean of marks for first and ALL attempts by students. * * See : http://docs.moodle.org/dev/Quiz_item_analysis_calculations_in_practise * #Calculating_MEAN_of_grades_for_all_attempts_by_students * @param int $quizid * @param \core\dml\sql_join $groupstudentsjoins Contains joins, wheres, params for students in this group. * @return \stdClass with properties with count and avg with prefixes firstattempts, highestattempts, etc. */ protected function attempt_counts_and_averages($quizid, \core\dml\sql_join $groupstudentsjoins) { global $DB; $attempttotals = new \stdClass(); foreach (array_keys(quiz_get_grading_options()) as $which) { list($fromqa, $whereqa, $qaparams) = quiz_statistics_attempts_sql($quizid, $groupstudentsjoins, $which); $fromdb = $DB->get_record_sql("SELECT COUNT(*) AS rcount, AVG(sumgrades) AS average FROM {$fromqa} WHERE {$whereqa}", $qaparams); $fieldprefix = static::using_attempts_string_id($which); $attempttotals->{$fieldprefix . 'avg'} = $fromdb->average; $attempttotals->{$fieldprefix . 'count'} = $fromdb->rcount; } return $attempttotals; }
} else { $pagetitle = get_string('generalsettings', 'admin'); } $quizsettings = new admin_settingpage('modsettingquiz', $pagetitle, 'moodle/site:config'); // Introductory explanation that all the settings are defaults for the add quiz form. $quizsettings->add(new admin_setting_heading('quizintro', '', get_string('configintro', 'quiz'))); // Time limit $quizsettings->add(new admin_setting_configtext_with_advanced('quiz/timelimit', get_string('timelimitsec', 'quiz'), get_string('configtimelimitsec', 'quiz'), array('value' => '0', 'fix' => false), PARAM_INT)); // Number of attempts $options = array(get_string('unlimited')); for ($i = 1; $i <= QUIZ_MAX_ATTEMPT_OPTION; $i++) { $options[$i] = $i; } $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/attempts', get_string('attemptsallowed', 'quiz'), get_string('configattemptsallowed', 'quiz'), array('value' => 0, 'fix' => false), $options)); // Grading method. $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/grademethod', get_string('grademethod', 'quiz'), get_string('configgrademethod', 'quiz'), array('value' => QUIZ_GRADEHIGHEST, 'fix' => false), quiz_get_grading_options())); // Maximum grade $quizsettings->add(new admin_setting_configtext('quiz/maximumgrade', get_string('maximumgrade'), get_string('configmaximumgrade', 'quiz'), 10, PARAM_INT)); // Shuffle questions $quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shufflequestions', get_string('shufflequestions', 'quiz'), get_string('configshufflequestions', 'quiz'), array('value' => 0, 'adv' => false))); // Questions per page $perpage = array(); $perpage[0] = get_string('never'); $perpage[1] = get_string('aftereachquestion', 'quiz'); for ($i = 2; $i <= QUIZ_MAX_QPP_OPTION; ++$i) { $perpage[$i] = get_string('afternquestions', 'quiz', $i); } $quizsettings->add(new admin_setting_configselect_with_advanced('quiz/questionsperpage', get_string('newpageevery', 'quiz'), get_string('confignewpageevery', 'quiz'), array('value' => 1, 'fix' => false), $perpage)); // Shuffle within questions $quizsettings->add(new admin_setting_configcheckbox_with_advanced('quiz/shuffleanswers', get_string('shufflewithin', 'quiz'), get_string('configshufflewithin', 'quiz'), array('value' => 1, 'adv' => false))); // Adaptive mode.
function definition() { global $COURSE, $CFG; $mform =& $this->_form; //------------------------------------------------------------------------------- $mform->addElement('header', 'general', get_string('general', 'form')); $mform->addElement('text', 'name', get_string('name'), array('size' => '64')); if (!empty($CFG->formatstringstriptags)) { $mform->setType('name', PARAM_TEXT); } else { $mform->setType('name', PARAM_CLEAN); } $mform->addRule('name', null, 'required', null, 'client'); $mform->addElement('htmleditor', 'intro', get_string("introduction", "quiz")); $mform->setType('intro', PARAM_RAW); $mform->setHelpButton('intro', array('richtext', get_string('helprichtext'))); //------------------------------------------------------------------------------- $mform->addElement('header', 'timinghdr', get_string('timing', 'form')); $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional' => true)); $mform->setHelpButton('timeopen', array('timeopen', get_string('quizopen', 'quiz'), 'quiz')); $mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), array('optional' => true)); $mform->setHelpButton('timeclose', array('timeopen', get_string('quizclose', 'quiz'), 'quiz')); $timelimitgrp = array(); $timelimitgrp[] =& $mform->createElement('text', 'timelimit'); $timelimitgrp[] =& $mform->createElement('checkbox', 'timelimitenable', '', get_string('enable')); $mform->addGroup($timelimitgrp, 'timelimitgrp', get_string('timelimitmin', 'quiz'), array(' '), false); $mform->setType('timelimit', PARAM_TEXT); $timelimitgrprules = array(); $timelimitgrprules['timelimit'][] = array(null, 'numeric', null, 'client'); $mform->addGroupRule('timelimitgrp', $timelimitgrprules); $mform->disabledIf('timelimitgrp', 'timelimitenable'); $mform->setAdvanced('timelimitgrp', $CFG->quiz_fix_timelimit); $mform->setHelpButton('timelimitgrp', array("timelimit", get_string("quiztimer", "quiz"), "quiz")); $mform->setDefault('timelimit', $CFG->quiz_timelimit); $mform->setDefault('timelimitenable', !empty($CFG->quiz_timelimit)); //enforced time delay between quiz attempts add-on $timedelayoptions = array(); $timedelayoptions[0] = get_string('none'); $timedelayoptions[1800] = get_string('numminutes', '', 30); $timedelayoptions[3600] = get_string('numminutes', '', 60); for ($i = 2; $i <= 23; $i++) { $seconds = $i * 3600; $timedelayoptions[$seconds] = get_string('numhours', '', $i); } $timedelayoptions[86400] = get_string('numhours', '', 24); for ($i = 2; $i <= 7; $i++) { $seconds = $i * 86400; $timedelayoptions[$seconds] = get_string('numdays', '', $i); } $mform->addElement('select', 'delay1', get_string("delay1", "quiz"), $timedelayoptions); $mform->setHelpButton('delay1', array("timedelay1", get_string("delay1", "quiz"), "quiz")); $mform->setAdvanced('delay1', $CFG->quiz_fix_delay1); $mform->setDefault('delay1', $CFG->quiz_delay1); $mform->addElement('select', 'delay2', get_string("delay2", "quiz"), $timedelayoptions); $mform->setHelpButton('delay2', array("timedelay2", get_string("delay2", "quiz"), "quiz")); $mform->setAdvanced('delay2', $CFG->quiz_fix_delay2); $mform->setDefault('delay2', $CFG->quiz_delay2); //------------------------------------------------------------------------------- $mform->addElement('header', 'displayhdr', get_string('display', 'form')); $perpage = array(); for ($i = 0; $i <= 50; ++$i) { $perpage[$i] = $i; } $perpage[0] = get_string('allinone', 'quiz'); $mform->addElement('select', 'questionsperpage', get_string('questionsperpage', 'quiz'), $perpage); $mform->setHelpButton('questionsperpage', array('questionsperpage', get_string('questionsperpage', 'quiz'), 'quiz')); $mform->setAdvanced('questionsperpage', $CFG->quiz_fix_questionsperpage); $mform->setDefault('questionsperpage', $CFG->quiz_questionsperpage); $mform->addElement('selectyesno', 'shufflequestions', get_string("shufflequestions", "quiz")); $mform->setHelpButton('shufflequestions', array("shufflequestions", get_string("shufflequestions", "quiz"), "quiz")); $mform->setAdvanced('shufflequestions', $CFG->quiz_fix_shufflequestions); $mform->setDefault('shufflequestions', $CFG->quiz_shufflequestions); $mform->addElement('selectyesno', 'shuffleanswers', get_string("shufflewithin", "quiz")); $mform->setHelpButton('shuffleanswers', array("shufflewithin", get_string("shufflewithin", "quiz"), "quiz")); $mform->setAdvanced('shuffleanswers', $CFG->quiz_fix_shuffleanswers); $mform->setDefault('shuffleanswers', $CFG->quiz_shuffleanswers); //------------------------------------------------------------------------------- $mform->addElement('header', 'attemptshdr', get_string('attempts', 'quiz')); $attemptoptions = array('0' => get_string('unlimited')); for ($i = 1; $i <= 10; $i++) { $attemptoptions[$i] = $i; } $mform->addElement('select', 'attempts', get_string("attemptsallowed", "quiz"), $attemptoptions); $mform->setHelpButton('attempts', array("attempts", get_string("attemptsallowed", "quiz"), "quiz")); $mform->setAdvanced('attempts', $CFG->quiz_fix_attempts); $mform->setDefault('attempts', $CFG->quiz_attempts); $mform->addElement('selectyesno', 'attemptonlast', get_string("eachattemptbuildsonthelast", "quiz")); $mform->setHelpButton('attemptonlast', array("repeatattempts", get_string("eachattemptbuildsonthelast", "quiz"), "quiz")); $mform->setAdvanced('attemptonlast', $CFG->quiz_fix_attemptonlast); $mform->setDefault('attemptonlast', $CFG->quiz_attemptonlast); $mform->addElement('selectyesno', 'adaptive', get_string("adaptive", "quiz")); $mform->setHelpButton('adaptive', array("adaptive", get_string("adaptive", "quiz"), "quiz")); $mform->setAdvanced('adaptive', $CFG->quiz_fix_adaptive); $mform->setDefault('adaptive', $CFG->quiz_optionflags & QUESTION_ADAPTIVE); //------------------------------------------------------------------------------- $mform->addElement('header', 'gradeshdr', get_string('grades', 'grades')); $mform->addElement('select', 'grademethod', get_string("grademethod", "quiz"), quiz_get_grading_options()); $mform->setHelpButton('grademethod', array("grademethod", get_string("grademethod", "quiz"), "quiz")); $mform->setAdvanced('grademethod', $CFG->quiz_fix_grademethod); $mform->setDefault('grademethod', $CFG->quiz_grademethod); $mform->addElement('selectyesno', 'penaltyscheme', get_string("penaltyscheme", "quiz")); $mform->setHelpButton('penaltyscheme', array("penaltyscheme", get_string("penaltyscheme", "quiz"), "quiz")); $mform->setAdvanced('penaltyscheme', $CFG->quiz_fix_penaltyscheme); $mform->setDefault('penaltyscheme', $CFG->quiz_penaltyscheme); $options = array(0 => '0', 1 => '1', 2 => '2', 3 => '3'); $mform->addElement('select', 'decimalpoints', get_string("decimaldigits", "quiz"), $options); $mform->setHelpButton('decimalpoints', array("decimalpoints", get_string("decimaldigits", "quiz"), "quiz")); $mform->setAdvanced('decimalpoints', $CFG->quiz_fix_decimalpoints); $mform->setDefault('decimalpoints', $CFG->quiz_decimalpoints); //------------------------------------------------------------------------------- $mform->addElement('header', 'reviewoptionshdr', get_string('reviewoptionsheading', 'quiz')); $mform->setHelpButton('reviewoptionshdr', array('reviewoptions', get_string('reviewoptionsheading', 'quiz'), 'quiz')); $mform->setAdvanced('reviewoptionshdr', $CFG->quiz_fix_review); $immediatelyoptionsgrp = array(); $immediatelyoptionsgrp[] =& $mform->createElement('checkbox', 'responsesimmediately', '', get_string('responses', 'quiz')); $immediatelyoptionsgrp[] =& $mform->createElement('checkbox', 'answersimmediately', '', get_string('answers', 'quiz')); $immediatelyoptionsgrp[] =& $mform->createElement('checkbox', 'feedbackimmediately', '', get_string('feedback', 'quiz')); $immediatelyoptionsgrp[] =& $mform->createElement('checkbox', 'generalfeedbackimmediately', '', get_string('generalfeedback', 'quiz')); $immediatelyoptionsgrp[] =& $mform->createElement('checkbox', 'scoreimmediately', '', get_string('scores', 'quiz')); $immediatelyoptionsgrp[] =& $mform->createElement('checkbox', 'overallfeedbackimmediately', '', get_string('overallfeedback', 'quiz')); $mform->addGroup($immediatelyoptionsgrp, 'immediatelyoptionsgrp', get_string("reviewimmediately", "quiz"), null, false); $mform->setDefault('responsesimmediately', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('answersimmediately', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('feedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('generalfeedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('scoreimmediately', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('overallfeedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY); $openoptionsgrp = array(); $openoptionsgrp[] =& $mform->createElement('checkbox', 'responsesopen', '', get_string('responses', 'quiz')); $openoptionsgrp[] =& $mform->createElement('checkbox', 'answersopen', '', get_string('answers', 'quiz')); $openoptionsgrp[] =& $mform->createElement('checkbox', 'feedbackopen', '', get_string('feedback', 'quiz')); $openoptionsgrp[] =& $mform->createElement('checkbox', 'generalfeedbackopen', '', get_string('generalfeedback', 'quiz')); $openoptionsgrp[] =& $mform->createElement('checkbox', 'scoreopen', '', get_string('scores', 'quiz')); $openoptionsgrp[] =& $mform->createElement('checkbox', 'overallfeedbackopen', '', get_string('overallfeedback', 'quiz')); $mform->addGroup($openoptionsgrp, 'openoptionsgrp', get_string("reviewopen", "quiz"), array(' '), false); $mform->setDefault('responsesopen', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN); $mform->setDefault('answersopen', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN); $mform->setDefault('feedbackopen', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN); $mform->setDefault('generalfeedbackopen', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN); $mform->setDefault('scoreopen', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN); $mform->setDefault('overallfeedbackopen', $CFG->quiz_review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN); $closedoptionsgrp = array(); $closedoptionsgrp[] =& $mform->createElement('checkbox', 'responsesclosed', '', get_string('responses', 'quiz')); $closedoptionsgrp[] =& $mform->createElement('checkbox', 'answersclosed', '', get_string('answers', 'quiz')); $closedoptionsgrp[] =& $mform->createElement('checkbox', 'feedbackclosed', '', get_string('feedback', 'quiz')); $closedoptionsgrp[] =& $mform->createElement('checkbox', 'generalfeedbackclosed', '', get_string('generalfeedback', 'quiz')); $closedoptionsgrp[] =& $mform->createElement('checkbox', 'scoreclosed', '', get_string('scores', 'quiz')); $closedoptionsgrp[] =& $mform->createElement('checkbox', 'overallfeedbackclosed', '', get_string('overallfeedback', 'quiz')); $mform->addGroup($closedoptionsgrp, 'closedoptionsgrp', get_string("reviewclosed", "quiz"), array(' '), false); $mform->setDefault('responsesclosed', $CFG->quiz_review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED); $mform->setDefault('answersclosed', $CFG->quiz_review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED); $mform->setDefault('feedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED); $mform->setDefault('generalfeedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED); $mform->setDefault('scoreclosed', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED); $mform->setDefault('overallfeedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED); //------------------------------------------------------------------------------- $mform->addElement('header', 'security', get_string('security', 'form')); $options = array(0 => get_string('none', 'quiz'), 1 => get_string('popupwithjavascriptsupport', 'quiz')); if (!empty($CFG->enablesafebrowserintegration)) { $options[2] = get_string('requiresafeexambrowser', 'quiz'); } $mform->addElement('select', 'popup', get_string('browsersecurity', 'quiz'), $options); $mform->setHelpButton('popup', array('browsersecurity', get_string('browsersecurity', 'quiz'), 'quiz')); $mform->setAdvanced('popup', $CFG->quiz_fix_popup); $mform->setDefault('popup', $CFG->quiz_popup); $mform->addElement('passwordunmask', 'quizpassword', get_string("requirepassword", "quiz")); $mform->setType('quizpassword', PARAM_TEXT); $mform->setHelpButton('quizpassword', array("requirepassword", get_string("requirepassword", "quiz"), "quiz")); $mform->setAdvanced('quizpassword', $CFG->quiz_fix_password); $mform->setDefault('quizpassword', $CFG->quiz_password); $mform->addElement('text', 'subnet', get_string("requiresubnet", "quiz")); $mform->setType('subnet', PARAM_TEXT); $mform->setHelpButton('subnet', array("requiresubnet", get_string("requiresubnet", "quiz"), "quiz")); $mform->setAdvanced('subnet', $CFG->quiz_fix_subnet); $mform->setDefault('subnet', $CFG->quiz_subnet); //------------------------------------------------------------------------------- $features = new stdClass(); $features->groups = true; $features->groupings = true; $features->groupmembersonly = true; $this->standard_coursemodule_elements($features); //------------------------------------------------------------------------------- $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz')); $mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz')); $mform->addElement('hidden', 'grade', $CFG->quiz_maximumgrade); $mform->setType('grade', PARAM_RAW); if (empty($this->_cm)) { $needwarning = $CFG->quiz_maximumgrade == 0; } else { $quizgrade = get_field('quiz', 'grade', 'id', $this->_instance); $needwarning = $quizgrade == 0; } if ($needwarning) { $mform->addElement('static', 'nogradewarning', '', get_string('nogradewarning', 'quiz')); } $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%'); $repeatarray = array(); $repeatarray[] =& MoodleQuickForm::createElement('text', 'feedbacktext', get_string('feedback', 'quiz'), array('size' => 50)); $mform->setType('feedbacktext', PARAM_RAW); $repeatarray[] =& MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10)); $mform->setType('feedbackboundaries', PARAM_NOTAGS); if (!empty($this->_instance)) { $this->_feedbacks = get_records('quiz_feedback', 'quizid', $this->_instance, 'mingrade DESC'); } else { $this->_feedbacks = array(); } $numfeedbacks = max(count($this->_feedbacks) * 1.5, 5); $nextel = $this->repeat_elements($repeatarray, $numfeedbacks - 1, array(), 'boundary_repeats', 'boundary_add_fields', 3, get_string('addmoreoverallfeedbacks', 'quiz'), true); // Put some extra elements in before the button $insertEl =& MoodleQuickForm::createElement('text', "feedbacktext[{$nextel}]", get_string('feedback', 'quiz'), array('size' => 50)); $mform->insertElementBefore($insertEl, 'boundary_add_fields'); $insertEl =& MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%'); $mform->insertElementBefore($insertEl, 'boundary_add_fields'); // Add the disabledif rules. We cannot do this using the $repeatoptions parameter to // repeat_elements becuase 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); } //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
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'); // Introduction. $this->add_intro_editor(false, get_string('introduction', 'quiz')); // Open and close dates. $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional' => true, 'step' => 1)); $mform->addHelpButton('timeopen', 'quizopenclose', 'quiz'); $mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), array('optional' => true, 'step' => 1)); // 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); // 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); $mform->disabledIf('grademethod', 'attempts', 'eq', 1); //------------------------------------------------------------------------------- // Grade settings $this->standard_grading_coursemodule_elements(); $mform->removeElement('grade'); $mform->addElement('hidden', 'grade', $quizconfig->maximumgrade); $mform->setType('grade', PARAM_NUMBER); //------------------------------------------------------------------------------- $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->yui2_lib('event'); $PAGE->requires->js('/mod/quiz/edit.js'); $PAGE->requires->js_init_call('quiz_settings_init'); } $mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false); $mform->addHelpButton('questionsperpagegrp', 'newpage', 'quiz'); $mform->setAdvanced('questionsperpagegrp', $quizconfig->questionsperpage_adv); //------------------------------------------------------------------------------- $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); $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); $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('selectyesno', 'showuserpicture', get_string('showuserpicture', 'quiz')); $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')); // Enforced time delay between quiz attempts. $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); $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); $mform->disabledIf('delay2', 'attempts', 'eq', 1); $mform->disabledIf('delay2', 'attempts', 'eq', 2); // 'Secure' window. $options = array( 0 => get_string('none', 'quiz'), 1 => get_string('popupwithjavascriptsupport', 'quiz')); if (!empty($CFG->enablesafebrowserintegration)) { $options[2] = get_string('requiresafeexambrowser', 'quiz'); } $mform->addElement('select', 'popup', get_string('browsersecurity', 'quiz'), $options); $mform->addHelpButton('popup', 'browsersecurity', 'quiz'); $mform->setAdvanced('popup', $quizconfig->popup_adv); $mform->setDefault('popup', $quizconfig->popup); //------------------------------------------------------------------------------- $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[] = MoodleQuickForm::createElement('editor', 'feedbacktext', get_string('feedback', 'quiz'), null, array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $this->context)); $repeatarray[] = MoodleQuickForm::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(MoodleQuickForm::createElement('editor', "feedbacktext[$nextel]", get_string('feedback', 'quiz'), null, array('maxfiles' => EDITOR_UNLIMITED_FILES, 'noclean' => true, 'context' => $this->context)), 'boundary_add_fields'); $mform->insertElementBefore(MoodleQuickForm::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(); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
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'); /// Introduction. $this->add_intro_editor(false, get_string('introduction', 'quiz')); /// Open and close dates. $mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional' => true)); $mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), array('optional' => true)); /// 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); /// 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); $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->yui2_lib('event'); $PAGE->requires->js('/mod/quiz/edit.js'); } $mform->addGroup($pagegroup, 'questionsperpagegrp', get_string('newpage', 'quiz'), null, false); $mform->addHelpButton('questionsperpagegrp', 'newpage', 'quiz'); $mform->setAdvanced('questionsperpagegrp', $quizconfig->questionsperpage_adv); //------------------------------------------------------------------------------- $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); /// Adaptive mode. $mform->addElement('selectyesno', 'adaptive', get_string('adaptive', 'quiz')); $mform->addHelpButton('adaptive', 'adaptive', 'quiz'); $mform->setAdvanced('adaptive', $quizconfig->optionflags_adv); $mform->setDefault('adaptive', $quizconfig->optionflags & QUESTION_ADAPTIVE); /// Apply penalties. $mform->addElement('selectyesno', 'penaltyscheme', get_string('penaltyscheme', 'quiz')); $mform->addHelpButton('penaltyscheme', 'penaltyscheme', 'quiz'); $mform->setAdvanced('penaltyscheme', $quizconfig->penaltyscheme_adv); $mform->setDefault('penaltyscheme', $quizconfig->penaltyscheme); $mform->disabledIf('penaltyscheme', 'adaptive', 'neq', 1); /// 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); $mform->disabledIf('attemptonlast', 'attempts', 'eq', 1); //------------------------------------------------------------------------------- $mform->addElement('header', 'reviewoptionshdr', get_string('reviewoptionsheading', 'quiz')); $mform->addHelpButton('reviewoptionshdr', 'reviewoptionsheading', 'quiz'); $mform->setAdvanced('reviewoptionshdr', $quizconfig->review_adv); /// Review options. $immediatelyoptionsgrp=array(); $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'responsesimmediately', '', get_string('responses', 'quiz')); $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'answersimmediately', '', get_string('answers', 'quiz')); $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackimmediately', '', get_string('feedback', 'quiz')); $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackimmediately', '', get_string('generalfeedback', 'quiz')); $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'scoreimmediately', '', get_string('scores', 'quiz')); $immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackimmediately', '', get_string('overallfeedback', 'quiz')); $mform->addGroup($immediatelyoptionsgrp, 'immediatelyoptionsgrp', get_string('reviewimmediately', 'quiz'), null, false); $mform->setDefault('responsesimmediately', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('answersimmediately', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('feedbackimmediately', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('generalfeedbackimmediately', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('scoreimmediately', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY); $mform->setDefault('overallfeedbackimmediately', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY); $openoptionsgrp=array(); $openoptionsgrp[] = &$mform->createElement('checkbox', 'responsesopen', '', get_string('responses', 'quiz')); $openoptionsgrp[] = &$mform->createElement('checkbox', 'answersopen', '', get_string('answers', 'quiz')); $openoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackopen', '', get_string('feedback', 'quiz')); $openoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackopen', '', get_string('generalfeedback', 'quiz')); $openoptionsgrp[] = &$mform->createElement('checkbox', 'scoreopen', '', get_string('scores', 'quiz')); $openoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackopen', '', get_string('overallfeedback', 'quiz')); $mform->addGroup($openoptionsgrp, 'openoptionsgrp', get_string('reviewopen', 'quiz'), array(' '), false); $mform->setDefault('responsesopen', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN); $mform->setDefault('answersopen', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN); $mform->setDefault('feedbackopen', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN); $mform->setDefault('generalfeedbackopen', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN); $mform->setDefault('scoreopen', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN); $mform->setDefault('overallfeedbackopen', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN); $closedoptionsgrp=array(); $closedoptionsgrp[] = &$mform->createElement('checkbox', 'responsesclosed', '', get_string('responses', 'quiz')); $closedoptionsgrp[] = &$mform->createElement('checkbox', 'answersclosed', '', get_string('answers', 'quiz')); $closedoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackclosed', '', get_string('feedback', 'quiz')); $closedoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackclosed', '', get_string('generalfeedback', 'quiz')); $closedoptionsgrp[] = &$mform->createElement('checkbox', 'scoreclosed', '', get_string('scores', 'quiz')); $closedoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackclosed', '', get_string('overallfeedback', 'quiz')); $mform->addGroup($closedoptionsgrp, 'closedoptionsgrp', get_string('reviewclosed', 'quiz'), array(' '), false); $mform->setDefault('responsesclosed', $quizconfig->review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED); $mform->setDefault('answersclosed', $quizconfig->review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED); $mform->setDefault('feedbackclosed', $quizconfig->review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED); $mform->setDefault('generalfeedbackclosed', $quizconfig->review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED); $mform->setDefault('scoreclosed', $quizconfig->review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED); $mform->setDefault('overallfeedbackclosed', $quizconfig->review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED); $mform->disabledIf('closedoptionsgrp', 'timeclose[enabled]'); //------------------------------------------------------------------------------- $mform->addElement('header', 'display', get_string('display', 'form')); /// Show user picture. $mform->addElement('selectyesno', 'showuserpicture', get_string('showuserpicture', 'quiz')); $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')); /// Enforced time delay between quiz attempts. $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); $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); $mform->disabledIf('delay2', 'attempts', 'eq', 1); $mform->disabledIf('delay2', 'attempts', 'eq', 2); /// 'Secure' window. $options = array( 0 => get_string('none', 'quiz'), 1 => get_string('popupwithjavascriptsupport', 'quiz')); if (!empty($CFG->enablesafebrowserintegration)) { $options[2] = get_string('requiresafeexambrowser', 'quiz'); } $mform->addElement('select', 'popup', get_string('browsersecurity', 'quiz'), $options); $mform->addHelpButton('popup', 'browsersecurity', 'quiz'); $mform->setAdvanced('popup', $quizconfig->popup_adv); $mform->setDefault('popup', $quizconfig->popup); //------------------------------------------------------------------------------- $mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz')); $mform->addHelpButton('overallfeedbackhdr', 'overallfeedback', 'quiz'); $mform->addElement('hidden', 'grade', $quizconfig->maximumgrade); $mform->setType('grade', PARAM_RAW); if (empty($this->_cm)) { $needwarning = $quizconfig->maximumgrade == 0; } else { $quizgrade = $DB->get_field('quiz', 'grade', array('id' => $this->_instance)); $needwarning = $quizgrade == 0; } if ($needwarning) { $mform->addElement('static', 'nogradewarning', '', get_string('nogradewarning', 'quiz')); } $mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%'); $repeatarray = array(); $repeatarray[] = &MoodleQuickForm::createElement('editor', 'feedbacktext', get_string('feedback', 'quiz'), null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->context)); $mform->setType('feedbacktext', PARAM_RAW); $repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10)); $mform->setType('feedbackboundaries', PARAM_NOTAGS); 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, array(), 'boundary_repeats', 'boundary_add_fields', 3, get_string('addmoreoverallfeedbacks', 'quiz'), true); // Put some extra elements in before the button $insertEl = &MoodleQuickForm::createElement('editor', "feedbacktext[$nextel]", get_string('feedback', 'quiz'), null, array('maxfiles'=>EDITOR_UNLIMITED_FILES, 'noclean'=>true, 'context'=>$this->context)); $mform->insertElementBefore($insertEl, 'boundary_add_fields'); $insertEl = &MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%'); $mform->insertElementBefore($insertEl, 'boundary_add_fields'); // Add the disabledif rules. We cannot do this using the $repeatoptions parameter to // repeat_elements becuase 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(); //------------------------------------------------------------------------------- // buttons $this->add_action_buttons(); }
/** * Calculating count and mean of marks for first and ALL attempts by students. * * See : http://docs.moodle.org/dev/Quiz_item_analysis_calculations_in_practise * #Calculating_MEAN_of_grades_for_all_attempts_by_students * @param int $quizid * @param array $groupstudents * @return stdClass with properties with count and avg with prefixes firstattempts, highestattempts, etc. */ protected function attempt_counts_and_averages($quizid, $groupstudents) { global $DB; list($fromqa, $whereqa, $qaparams) = quiz_statistics_attempts_sql($quizid, $groupstudents); $selects = array(); foreach (array_keys(quiz_get_grading_options()) as $which) { $fieldprefix = static::using_attempts_string_id($which); $condition = quiz_report_grade_method_sql($which); if ($condition == '') { $case = '1'; } else { $case = "CASE WHEN ({$condition}) THEN 1 ELSE 0 END"; } $selects[] = "\n SUM({$case}) AS {$fieldprefix}count,\n SUM(sumgrades * {$case}) AS {$fieldprefix}total"; } $select = join(',', $selects); $attempttotals = $DB->get_record_sql("\n SELECT {$select}\n FROM {$fromqa}\n WHERE {$whereqa}", $qaparams); foreach (array_keys(quiz_get_grading_options()) as $which) { $fieldprefix = static::using_attempts_string_id($which); $attempttotals->{$fieldprefix . 'avg'} = $attempttotals->{$fieldprefix . 'total'} / $attempttotals->{$fieldprefix . 'count'}; unset($attempttotals->{$fieldprefix . 'total'}); } return $attempttotals; }