2007-09-26 10:13:23 +00:00
|
|
|
<?php // $Id$
|
2007-06-10 23:20:45 +00:00
|
|
|
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
require_once("$CFG->dirroot/mod/quiz/locallib.php");
|
|
|
|
|
2006-12-28 09:32:45 +00:00
|
|
|
class mod_quiz_mod_form extends moodleform_mod {
|
2006-12-19 07:03:08 +00:00
|
|
|
var $_feedbacks;
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
function definition() {
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-08-06 13:22:59 +00:00
|
|
|
global $COURSE, $CFG;
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform =& $this->_form;
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$mform->addElement('header', 'general', get_string('general', 'form'));
|
|
|
|
|
2007-01-11 19:47:08 +00:00
|
|
|
$mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setType('name', PARAM_TEXT);
|
2007-08-03 10:33:29 +00:00
|
|
|
$mform->addRule('name', null, 'required', null, 'client');
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->addElement('htmleditor', 'intro', get_string("introduction", "quiz"));
|
|
|
|
$mform->setType('intro', PARAM_RAW);
|
2007-01-05 04:51:46 +00:00
|
|
|
$mform->setHelpButton('intro', array('richtext', get_string('helprichtext')));
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$mform->addElement('header', 'timinghdr', get_string('timing', 'form'));
|
2007-10-31 17:08:47 +00:00
|
|
|
$mform->addElement('date_time_selector', 'timeopen', get_string('quizopen', 'quiz'), array('optional'=>true));
|
|
|
|
$mform->setHelpButton('timeopen', array('timeopen', get_string('quizopen', 'quiz'), 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-10-31 17:08:47 +00:00
|
|
|
$mform->addElement('date_time_selector', 'timeclose', get_string('quizclose', 'quiz'), array('optional'=>true));
|
|
|
|
$mform->setHelpButton('timeclose', array('timeopen', get_string('quizclose', 'quiz'), 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
$timelimitgrp=array();
|
|
|
|
$timelimitgrp[] = &$mform->createElement('text', 'timelimit');
|
|
|
|
$timelimitgrp[] = &$mform->createElement('checkbox', 'timelimitenable', '', get_string('enable'));
|
2007-07-02 06:48:50 +00:00
|
|
|
$mform->addGroup($timelimitgrp, 'timelimitgrp', get_string('timelimitmin', 'quiz'), array(' '), false);
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setType('timelimit', PARAM_TEXT);
|
|
|
|
$timelimitgrprules = array();
|
|
|
|
$timelimitgrprules['timelimit'][] = array(null, 'numeric', null, 'client');
|
|
|
|
$mform->addGroupRule('timelimitgrp', $timelimitgrprules);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->disabledIf('timelimitgrp', 'timelimitenable');
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setAdvanced('timelimitgrp', $CFG->quiz_fix_timelimit);
|
|
|
|
$mform->setHelpButton('timelimitgrp', array("timelimit", get_string("quiztimer","quiz"), "quiz"));
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('timelimit', $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);
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setHelpButton('delay1', array("timedelay1", get_string("delay1", "quiz"), "quiz"));
|
|
|
|
$mform->setAdvanced('delay1', $CFG->quiz_fix_delay1);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('delay1', $CFG->quiz_delay1);
|
|
|
|
|
|
|
|
$mform->addElement('select', 'delay2', get_string("delay2", "quiz"), $timedelayoptions);
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setHelpButton('delay2', array("timedelay2", get_string("delay2", "quiz"), "quiz"));
|
|
|
|
$mform->setAdvanced('delay2', $CFG->quiz_fix_delay2);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('delay2', $CFG->quiz_delay2);
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$mform->addElement('header', 'displayhdr', get_string('display', 'form'));
|
2007-05-08 16:11:58 +00:00
|
|
|
$perpage = array();
|
2006-12-19 07:03:08 +00:00
|
|
|
for ($i = 0; $i <= 50; ++$i) {
|
|
|
|
$perpage[$i] = $i;
|
|
|
|
}
|
|
|
|
$perpage[0] = get_string('allinone', 'quiz');
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('questionsperpage', $CFG->quiz_questionsperpage);
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('shufflequestions', $CFG->quiz_shufflequestions);
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('shuffleanswers', $CFG->quiz_shuffleanswers);
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$mform->addElement('header', 'attemptshdr', get_string('attempts', 'quiz'));
|
2007-05-08 16:11:58 +00:00
|
|
|
$attemptoptions = array();
|
2006-12-19 07:03:08 +00:00
|
|
|
$attemptoptions[0] = get_string("attemptsunlimited", "quiz");
|
|
|
|
$attemptoptions[1] = "1 ".moodle_strtolower(get_string("attempt", "quiz"));
|
|
|
|
for ($i=2;$i<=6;$i++) {
|
|
|
|
$attemptoptions[$i] = "$i ".moodle_strtolower(get_string("attempts", "quiz"));
|
|
|
|
}
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('attempts', $CFG->quiz_attempts);
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('attemptonlast', $CFG->quiz_attemptonlast);
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$mform->addElement('header', 'gradeshdr', get_string('grades', 'grades'));
|
2007-08-06 13:22:59 +00:00
|
|
|
$mform->addElement('select', 'grademethod', get_string("grademethod", "quiz"), quiz_get_grading_options());
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setHelpButton('grademethod', array("grademethod", get_string("grademethod","quiz"), "quiz"));
|
|
|
|
$mform->setAdvanced('grademethod', $CFG->quiz_fix_grademethod);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('grademethod', $CFG->quiz_grademethod);
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('penaltyscheme', $CFG->quiz_penaltyscheme);
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$options = array(
|
2006-12-19 07:03:08 +00:00
|
|
|
0 => '0',
|
|
|
|
1 => '1',
|
|
|
|
2 => '2',
|
|
|
|
3 => '3');
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2007-01-26 17:52:23 +00:00
|
|
|
$mform->setDefault('decimalpoints', $CFG->quiz_decimalpoints);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->addElement('hidden', 'grade', $CFG->quiz_maximumgrade);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2007-10-09 15:19:07 +00:00
|
|
|
$mform->addElement('header', 'reviewoptionshdr', get_string('reviewoptionsheading', 'quiz'));
|
|
|
|
$mform->setHelpButton('reviewoptionshdr', array('reviewoptions', get_string('reviewoptionsheading','quiz'), 'quiz'));
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setAdvanced('reviewoptionshdr', $CFG->quiz_fix_review);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$immediatelyoptionsgrp=array();
|
2006-12-19 07:03:08 +00:00
|
|
|
$immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'responsesimmediately', '', get_string('responses', 'quiz'));
|
|
|
|
$immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'answersimmediately', '', get_string('answers', 'quiz'));
|
2007-07-30 10:05:11 +00:00
|
|
|
$immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackimmediately', '', get_string('feedback', 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
$immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackimmediately', '', get_string('generalfeedback', 'quiz'));
|
2007-07-30 10:05:11 +00:00
|
|
|
$immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'scoreimmediately', '', get_string('scores', 'quiz'));
|
|
|
|
$immediatelyoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackimmediately', '', get_string('overallfeedback', 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
$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);
|
2007-07-30 10:05:11 +00:00
|
|
|
$mform->setDefault('feedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('generalfeedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
|
2007-07-30 10:05:11 +00:00
|
|
|
$mform->setDefault('scoreimmediately', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY);
|
|
|
|
$mform->setDefault('overallfeedbackimmediately', $CFG->quiz_review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$openoptionsgrp=array();
|
2006-12-19 07:03:08 +00:00
|
|
|
$openoptionsgrp[] = &$mform->createElement('checkbox', 'responsesopen', '', get_string('responses', 'quiz'));
|
|
|
|
$openoptionsgrp[] = &$mform->createElement('checkbox', 'answersopen', '', get_string('answers', 'quiz'));
|
2007-07-30 10:05:11 +00:00
|
|
|
$openoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackopen', '', get_string('feedback', 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
$openoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackopen', '', get_string('generalfeedback', 'quiz'));
|
2007-07-30 10:05:11 +00:00
|
|
|
$openoptionsgrp[] = &$mform->createElement('checkbox', 'scoreopen', '', get_string('scores', 'quiz'));
|
|
|
|
$openoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackopen', '', get_string('overallfeedback', 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
$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);
|
2007-07-30 10:05:11 +00:00
|
|
|
$mform->setDefault('feedbackopen', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('generalfeedbackopen', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN);
|
2007-07-30 10:05:11 +00:00
|
|
|
$mform->setDefault('scoreopen', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN);
|
|
|
|
$mform->setDefault('overallfeedbackopen', $CFG->quiz_review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$closedoptionsgrp=array();
|
2006-12-19 07:03:08 +00:00
|
|
|
$closedoptionsgrp[] = &$mform->createElement('checkbox', 'responsesclosed', '', get_string('responses', 'quiz'));
|
|
|
|
$closedoptionsgrp[] = &$mform->createElement('checkbox', 'answersclosed', '', get_string('answers', 'quiz'));
|
2007-07-30 10:05:11 +00:00
|
|
|
$closedoptionsgrp[] = &$mform->createElement('checkbox', 'feedbackclosed', '', get_string('feedback', 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
$closedoptionsgrp[] = &$mform->createElement('checkbox', 'generalfeedbackclosed', '', get_string('generalfeedback', 'quiz'));
|
2007-07-30 10:05:11 +00:00
|
|
|
$closedoptionsgrp[] = &$mform->createElement('checkbox', 'scoreclosed', '', get_string('scores', 'quiz'));
|
|
|
|
$closedoptionsgrp[] = &$mform->createElement('checkbox', 'overallfeedbackclosed', '', get_string('overallfeedback', 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
$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);
|
2007-07-30 10:05:11 +00:00
|
|
|
$mform->setDefault('feedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('generalfeedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED);
|
2007-07-30 10:05:11 +00:00
|
|
|
$mform->setDefault('scoreclosed', $CFG->quiz_review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED);
|
|
|
|
$mform->setDefault('overallfeedbackclosed', $CFG->quiz_review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
$mform->addElement('header', 'security', get_string('security', 'form'));
|
|
|
|
|
|
|
|
$mform->addElement('selectyesno', 'popup', get_string("popup", "quiz"));
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setHelpButton('popup', array("popup", get_string("popup", "quiz"), "quiz"));
|
|
|
|
$mform->setAdvanced('popup', $CFG->quiz_fix_popup);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('popup', $CFG->quiz_popup);
|
|
|
|
|
2007-04-30 18:03:19 +00:00
|
|
|
$mform->addElement('passwordunmask', 'quizpassword', get_string("requirepassword", "quiz"));
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setType('quizpassword', PARAM_TEXT);
|
|
|
|
$mform->setHelpButton('quizpassword', array("requirepassword", get_string("requirepassword", "quiz"), "quiz"));
|
|
|
|
$mform->setAdvanced('quizpassword', $CFG->quiz_fix_password);
|
2007-04-27 08:33:11 +00:00
|
|
|
$mform->setDefault('quizpassword', $CFG->quiz_password);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$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);
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->setDefault('subnet', $CFG->quiz_subnet);
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
2007-08-27 03:56:39 +00:00
|
|
|
$features = new stdClass;
|
|
|
|
$features->groups = true;
|
|
|
|
$features->groupings = true;
|
|
|
|
$features->groupmembersonly = true;
|
|
|
|
$this->standard_coursemodule_elements($features);
|
2006-12-19 07:03:08 +00:00
|
|
|
//-------------------------------------------------------------------------------
|
2007-01-08 13:58:42 +00:00
|
|
|
$mform->addElement('header', 'overallfeedbackhdr', get_string('overallfeedback', 'quiz'));
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->setHelpButton('overallfeedbackhdr', array('overallfeedback', get_string('overallfeedback', 'quiz'), 'quiz'));
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
$mform->addElement('static', 'gradeboundarystatic1', get_string('gradeboundary', 'quiz'), '100%');
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
$repeatarray=array();
|
2007-08-15 12:45:23 +00:00
|
|
|
$repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbacktext', get_string('feedback', 'quiz'), array('size' => 50));
|
|
|
|
$repeatarray[] = &MoodleQuickForm::createElement('text', 'feedbackboundaries', get_string('gradeboundary', 'quiz'), array('size' => 10));
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
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);
|
2006-12-28 16:44:47 +00:00
|
|
|
|
2007-07-30 10:33:43 +00:00
|
|
|
$mform->setType('feedbacktext', PARAM_RAW);
|
2007-01-21 10:32:42 +00:00
|
|
|
$mform->setType('feedbackboundaries', PARAM_NOTAGS);
|
2006-12-28 16:44:47 +00:00
|
|
|
|
2006-12-19 07:03:08 +00:00
|
|
|
$nextel=$this->repeat_elements($repeatarray, $numfeedbacks-1,
|
2007-10-09 15:44:06 +00:00
|
|
|
array(), 'boundary_repeats', 'boundary_add_fields', 3,
|
|
|
|
get_string('addmoreoverallfeedbacks', 'quiz'), true);
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
//put some extra elements in before the button
|
2007-08-15 12:45:23 +00:00
|
|
|
$insertEl = &MoodleQuickForm::createElement('text', "feedbacktext[$nextel]", get_string('feedback', 'quiz'), array('size' => 50));
|
2006-12-19 07:03:08 +00:00
|
|
|
$mform->insertElementBefore($insertEl, 'boundary_add_fields');
|
|
|
|
|
|
|
|
$insertEl = &MoodleQuickForm::createElement('static', 'gradeboundarystatic2', get_string('gradeboundary', 'quiz'), '0%');
|
|
|
|
$mform->insertElementBefore($insertEl, 'boundary_add_fields');
|
|
|
|
|
|
|
|
//-------------------------------------------------------------------------------
|
|
|
|
// buttons
|
|
|
|
$this->add_action_buttons();
|
2007-05-08 16:11:58 +00:00
|
|
|
}
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-05-08 16:11:58 +00:00
|
|
|
function data_preprocessing(&$default_values){
|
2006-12-19 07:03:08 +00:00
|
|
|
if (count($this->_feedbacks)) {
|
|
|
|
$key = 0;
|
|
|
|
foreach ($this->_feedbacks as $feedback){
|
|
|
|
$default_values['feedbacktext['.$key.']'] = $feedback->feedbacktext;
|
|
|
|
if ($feedback->mingrade > 0) {
|
|
|
|
$default_values['feedbackboundaries['.$key.']'] = (100.0 * $feedback->mingrade / $default_values['grade']) . '%';
|
|
|
|
}
|
|
|
|
$key++;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (empty($default_values['timelimit'])) {
|
|
|
|
$default_values['timelimitenable'] = 0;
|
|
|
|
} else {
|
|
|
|
$default_values['timelimitenable'] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($default_values['review'])){
|
|
|
|
$review = (int)$default_values['review'];
|
|
|
|
unset($default_values['review']);
|
|
|
|
|
|
|
|
$default_values['responsesimmediately'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_IMMEDIATELY;
|
|
|
|
$default_values['answersimmediately'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_IMMEDIATELY;
|
2007-07-30 10:05:11 +00:00
|
|
|
$default_values['feedbackimmediately'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
|
2006-12-19 07:03:08 +00:00
|
|
|
$default_values['generalfeedbackimmediately'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
|
2007-07-30 10:05:11 +00:00
|
|
|
$default_values['scoreimmediately'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_IMMEDIATELY;
|
|
|
|
$default_values['overallfeedbackimmediately'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_IMMEDIATELY;
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
$default_values['responsesopen'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_OPEN;
|
|
|
|
$default_values['answersopen'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_OPEN;
|
2007-07-30 10:05:11 +00:00
|
|
|
$default_values['feedbackopen'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_OPEN;
|
2006-12-19 07:03:08 +00:00
|
|
|
$default_values['generalfeedbackopen'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_OPEN;
|
2007-07-30 10:05:11 +00:00
|
|
|
$default_values['scoreopen'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_OPEN;
|
|
|
|
$default_values['overallfeedbackopen'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_OPEN;
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
$default_values['responsesclosed'] = $review & QUIZ_REVIEW_RESPONSES & QUIZ_REVIEW_CLOSED;
|
|
|
|
$default_values['answersclosed'] = $review & QUIZ_REVIEW_ANSWERS & QUIZ_REVIEW_CLOSED;
|
2007-07-30 10:05:11 +00:00
|
|
|
$default_values['feedbackclosed'] = $review & QUIZ_REVIEW_FEEDBACK & QUIZ_REVIEW_CLOSED;
|
2006-12-19 07:03:08 +00:00
|
|
|
$default_values['generalfeedbackclosed'] = $review & QUIZ_REVIEW_GENERALFEEDBACK & QUIZ_REVIEW_CLOSED;
|
2007-07-30 10:05:11 +00:00
|
|
|
$default_values['scoreclosed'] = $review & QUIZ_REVIEW_SCORES & QUIZ_REVIEW_CLOSED;
|
|
|
|
$default_values['overallfeedbackclosed'] = $review & QUIZ_REVIEW_OVERALLFEEDBACK & QUIZ_REVIEW_CLOSED;
|
2006-12-19 07:03:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($default_values['optionflags'])){
|
|
|
|
$default_values['adaptive'] = $default_values['optionflags'] & QUESTION_ADAPTIVE;
|
|
|
|
unset($default_values['optionflags']);
|
|
|
|
}
|
2007-04-27 08:33:11 +00:00
|
|
|
|
|
|
|
// Password field - different in form to stop browsers that remember passwords
|
|
|
|
// getting confused.
|
2007-05-08 16:11:58 +00:00
|
|
|
if (isset($default_values['password'])) {
|
2007-04-27 08:33:11 +00:00
|
|
|
$default_values['quizpassword'] = $default_values['password'];
|
|
|
|
unset($default_values['password']);
|
|
|
|
}
|
2007-05-08 16:11:58 +00:00
|
|
|
}
|
2006-12-19 07:03:08 +00:00
|
|
|
|
2007-11-23 22:15:07 +00:00
|
|
|
function validation($data, $files) {
|
|
|
|
$errors = parent::validation($data, $files);
|
2007-08-02 10:38:18 +00:00
|
|
|
|
2006-12-19 07:03:08 +00:00
|
|
|
// Check open and close times are consistent.
|
|
|
|
if ($data['timeopen'] != 0 && $data['timeclose'] != 0 && $data['timeclose'] < $data['timeopen']) {
|
|
|
|
$errors['timeclose'] = get_string('closebeforeopen', 'quiz');
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check the boundary value is a number or a percentage, and in range.
|
|
|
|
$i = 0;
|
|
|
|
while (!empty($data['feedbackboundaries'][$i] )) {
|
|
|
|
$boundary = trim($data['feedbackboundaries'][$i]);
|
|
|
|
if (strlen($boundary) > 0 && $boundary[strlen($boundary) - 1] == '%') {
|
|
|
|
$boundary = trim(substr($boundary, 0, -1));
|
|
|
|
if (is_numeric($boundary)) {
|
|
|
|
$boundary = $boundary * $data['grade'] / 100.0;
|
|
|
|
} else {
|
|
|
|
$errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryformat', 'quiz', $i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (is_numeric($boundary) && $boundary <= 0 || $boundary >= $data['grade'] ) {
|
|
|
|
$errors["feedbackboundaries[$i]"] = get_string('feedbackerrorboundaryoutofrange', 'quiz', $i + 1);
|
|
|
|
}
|
|
|
|
if (is_numeric($boundary) && $i > 0 && $boundary >= $data['feedbackboundaries'][$i - 1]) {
|
|
|
|
$errors["feedbackboundaries[$i]"] = get_string('feedbackerrororder', 'quiz', $i + 1);
|
|
|
|
}
|
|
|
|
$data['feedbackboundaries'][$i] = $boundary;
|
|
|
|
$i += 1;
|
|
|
|
}
|
|
|
|
$numboundaries = $i;
|
|
|
|
|
|
|
|
// Check there is nothing in the remaining unused fields.
|
|
|
|
for ($i = $numboundaries; $i < count($data['feedbackboundaries'] ); $i += 1) {
|
|
|
|
if (!empty($data['feedbackboundaries'][$i] ) && trim($data['feedbackboundaries'][$i] ) != '') {
|
|
|
|
$errors["feedbackboundaries[$i]"] = get_string('feedbackerrorjunkinboundary', 'quiz', $i + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for ($i = $numboundaries + 1; $i < count($data['feedbacktext'] ); $i += 1) {
|
|
|
|
if (!empty($data['feedbacktext'][$i] ) && trim($data['feedbacktext'][$i] ) != '') {
|
|
|
|
$errors["feedbacktext[$i]"] = get_string('feedbackerrorjunkinfeedback', 'quiz', $i + 1);
|
|
|
|
}
|
|
|
|
}
|
2007-08-02 10:38:18 +00:00
|
|
|
|
|
|
|
if (count($errors) == 0) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return $errors;
|
|
|
|
}
|
2007-05-08 16:11:58 +00:00
|
|
|
}
|
2006-12-19 07:03:08 +00:00
|
|
|
|
|
|
|
}
|
2007-05-08 16:11:58 +00:00
|
|
|
?>
|