Exemplo n.º 1
0
 /**
  * Defines the hotpot instance configuration form
  *
  * @return void
  */
 function definition()
 {
     global $CFG;
     $hotpotconfig = get_config('hotpot');
     $mform = $this->_form;
     // General --------------------------------------------------------------------
     $mform->addElement('header', 'general', get_string('general', 'form'));
     //-----------------------------------------------------------------------------
     // Hotpot name
     if ($this->is_add()) {
         $elements = array($mform->createElement('select', 'namesource', '', hotpot::available_namesources_list()), $mform->createElement('text', 'name', '', array('size' => '40')));
         $mform->addGroup($elements, 'name_elements', get_string('name'), array(' '), false);
         $mform->disabledIf('name_elements', 'namesource', 'ne', hotpot::TEXTSOURCE_SPECIFIC);
         $mform->setDefault('namesource', get_user_preferences('hotpot_namesource', hotpot::TEXTSOURCE_FILE));
         $mform->addHelpButton('name_elements', 'nameadd', 'hotpot');
     } else {
         $mform->addElement('text', 'name', get_string('name'), array('size' => '40'));
         $mform->addElement('hidden', 'namesource', hotpot::TEXTSOURCE_SPECIFIC);
         $mform->addHelpButton('name', 'nameedit', 'hotpot');
         $mform->addRule('name', null, 'required', null, 'client');
         $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
     }
     $mform->setType('namesource', PARAM_INT);
     if (empty($CFG->formatstringstriptags)) {
         $mform->setType('name', PARAM_CLEAN);
     } else {
         $mform->setType('name', PARAM_TEXT);
     }
     // Reference
     // $mform->addElement('filepicker', 'sourceitemid', get_string('sourcefile', 'hotpot'));
     // $mform->addRule('sourceitemid', null, 'required', null, 'client');
     // $mform->addHelpButton('sourceitemid', 'sourcefile', 'hotpot');
     $options = array('subdirs' => 1, 'maxbytes' => 0, 'maxfiles' => -1, 'mainfile' => true, 'accepted_types' => '*');
     $mform->addElement('filemanager', 'sourceitemid', get_string('sourcefile', 'hotpot'), null, $options);
     $mform->addRule('sourceitemid', null, 'required', null, 'client');
     $mform->addHelpButton('sourceitemid', 'sourcefile', 'hotpot');
     // legacy field from Moodle 1.9 - it will probably be removed someday
     $mform->addElement('hidden', 'sourcelocation', isset($this->current->sourcelocation) ? $this->current->sourcelocation : 0);
     $mform->setType('sourcelocation', PARAM_INT);
     // Add quiz chain (this setting is not implemented in Moodle 2.0)
     $mform->addElement('hidden', 'quizchain', 0);
     $mform->setType('quizchain', PARAM_INT);
     //if ($this->is_add()) {
     //    $mform->addElement('selectyesno', 'quizchain', get_string('addquizchain', 'hotpot'));
     //    $mform->setDefault('quizchain', get_user_preferences('hotpot_add_quizchain', 0));
     //    $mform->addHelpButton('quizchain', 'addquizchain', 'hotpot');
     //    $mform->setAdvanced('quizchain');
     //} else {
     //    $mform->addElement('hidden', 'quizchain', 0);
     //}
     // Entry page -----------------------------------------------------------------
     $mform->addElement('header', 'entrypagehdr', get_string('entrypagehdr', 'hotpot'));
     //-----------------------------------------------------------------------------
     // Entry page text editor
     $this->add_hotpot_text_editor('entry');
     // Entry page options
     $elements = array($mform->createElement('checkbox', 'entry_title', '', get_string('title', 'hotpot')), $mform->createElement('checkbox', 'entry_grading', '', get_string('entry_grading', 'hotpot')), $mform->createElement('checkbox', 'entry_dates', '', get_string('entry_dates', 'hotpot')), $mform->createElement('checkbox', 'entry_attempts', '', get_string('entry_attempts', 'hotpot')));
     $mform->addGroup($elements, 'entryoptions_elements', get_string('entryoptions', 'hotpot'), html_writer::empty_tag('br'), false);
     $mform->setAdvanced('entryoptions_elements');
     $mform->addHelpButton('entryoptions_elements', 'entryoptions', 'hotpot');
     $mform->disabledIf('entryoptions_elements', 'entrypage', 'ne', 1);
     // Exit page ------------------------------------------------------------------
     $mform->addElement('header', 'exitpagehdr', get_string('exitpagehdr', 'hotpot'));
     //-----------------------------------------------------------------------------
     // Exit page text editor
     $this->add_hotpot_text_editor('exit');
     // Exit page options (feedback)
     $elements = array($mform->createElement('checkbox', 'exit_title', '', get_string('title', 'hotpot')), $mform->createElement('checkbox', 'exit_encouragement', '', get_string('exit_encouragement', 'hotpot')), $mform->createElement('checkbox', 'exit_attemptscore', '', get_string('exit_attemptscore', 'hotpot', '...')), $mform->createElement('checkbox', 'exit_hotpotgrade', '', get_string('exit_hotpotgrade', 'hotpot', '...')));
     $mform->addGroup($elements, 'exit_feedback', get_string('exit_feedback', 'hotpot'), html_writer::empty_tag('br'), false);
     $mform->setAdvanced('exit_feedback');
     $mform->disabledIf('exit_feedback', 'exitpage', 'ne', 1);
     $mform->addHelpButton('exit_feedback', 'exit_feedback', 'hotpot');
     // Exit page options (links)
     $elements = array($mform->createElement('checkbox', 'exit_retry', '', get_string('exit_retry', 'hotpot') . ': ' . get_string('exit_retry_text', 'hotpot')), $mform->createElement('checkbox', 'exit_index', '', get_string('exit_index', 'hotpot') . ': ' . get_string('exit_index_text', 'hotpot')), $mform->createElement('checkbox', 'exit_course', '', get_string('exit_course', 'hotpot') . ': ' . get_string('exit_course_text', 'hotpot')), $mform->createElement('checkbox', 'exit_grades', '', get_string('exit_grades', 'hotpot') . ': ' . get_string('exit_grades_text', 'hotpot')));
     $mform->addGroup($elements, 'exit_links', get_string('exit_links', 'hotpot'), html_writer::empty_tag('br'), false);
     $mform->setAdvanced('exit_links');
     $mform->disabledIf('exit_links', 'exitpage', 'ne', 1);
     $mform->addHelpButton('exit_links', 'exit_links', 'hotpot');
     // Next activity
     $this->add_activity_list('exit');
     // Display --------------------------------------------------------------------
     $mform->addElement('header', 'displayhdr', get_string('display', 'form'));
     //-----------------------------------------------------------------------------
     // Output format
     if (empty($this->current->sourcetype)) {
         $sourcetype = '';
         // add
     } else {
         $sourcetype = $this->current->sourcetype;
     }
     $mform->addElement('select', 'outputformat', get_string('outputformat', 'hotpot'), hotpot::available_outputformats_list($sourcetype));
     $mform->setDefault('outputformat', get_user_preferences('hotpot_outputformat', ''));
     $mform->addHelpButton('outputformat', 'outputformat', 'hotpot');
     // Navigation
     $mform->addElement('select', 'navigation', get_string('navigation', 'hotpot'), hotpot::available_navigations_list());
     $mform->setDefault('navigation', get_user_preferences('hotpot_navigation', hotpot::NAVIGATION_MOODLE));
     $mform->addHelpButton('navigation', 'navigation', 'hotpot');
     // Title
     $mform->addElement('select', 'title', get_string('title', 'hotpot'), hotpot::available_titles_list());
     $mform->setDefault('title', get_user_preferences('hotpot_title', hotpot::TEXTSOURCE_SPECIFIC));
     $mform->addHelpButton('title', 'title', 'hotpot');
     $mform->setAdvanced('title');
     // Show stop button
     $options = array('hotpot_giveup' => get_string('giveup', 'hotpot'), 'specific' => get_string('stopbutton_specific', 'hotpot'));
     $elements = array($mform->createElement('selectyesno', 'stopbutton_yesno', ''), $mform->createElement('select', 'stopbutton_type', '', $options), $mform->createElement('text', 'stopbutton_text', '', array('size' => '20')));
     $mform->addGroup($elements, 'stopbutton_elements', get_string('stopbutton', 'hotpot'), ' ', false);
     $mform->addHelpButton('stopbutton_elements', 'stopbutton', 'hotpot');
     $mform->setAdvanced('stopbutton_elements');
     $mform->setType('stopbutton_yesno', PARAM_INT);
     $mform->setType('stopbutton_type', PARAM_ALPHAEXT);
     $mform->setType('stopbutton_text', PARAM_TEXT);
     $mform->disabledIf('stopbutton_elements', 'stopbutton_yesno', 'ne', '1');
     $mform->disabledIf('stopbutton_text', 'stopbutton_type', 'ne', 'specific');
     // Allow paste
     $mform->addElement('selectyesno', 'allowpaste', get_string('allowpaste', 'hotpot'));
     $mform->setType('allowpaste', PARAM_INT);
     $mform->setDefault('allowpaste', get_user_preferences('hotpot_quiz_allowpaste', 1));
     $mform->addHelpButton('allowpaste', 'allowpaste', 'hotpot');
     $mform->setAdvanced('allowpaste');
     // Use filters
     $mform->addElement('selectyesno', 'usefilters', get_string('usefilters', 'hotpot'));
     $mform->setType('usefilters', PARAM_INT);
     $mform->setDefault('usefilters', get_user_preferences('hotpot_quiz_usefilters', 1));
     $mform->addHelpButton('usefilters', 'usefilters', 'hotpot');
     $mform->setAdvanced('usefilters');
     // Use glossary
     $mform->addElement('selectyesno', 'useglossary', get_string('useglossary', 'hotpot'));
     $mform->setType('useglossary', PARAM_INT);
     $mform->setDefault('useglossary', get_user_preferences('hotpot_quiz_useglossary', 1));
     $mform->addHelpButton('useglossary', 'useglossary', 'hotpot');
     $mform->setAdvanced('useglossary');
     // Use media filters
     $mform->addElement('select', 'usemediafilter', get_string('usemediafilter', 'hotpot'), hotpot::available_mediafilters_list());
     $mform->setType('usemediafilter', PARAM_SAFEDIR);
     // [a-zA-Z0-9_-]
     $mform->setDefault('usemediafilter', get_user_preferences('hotpot_quiz_usemediafilter', 'moodle'));
     $mform->addHelpButton('usemediafilter', 'usemediafilter', 'hotpot');
     $mform->setAdvanced('usemediafilter');
     // Student feedback
     $elements = array($mform->createElement('select', 'studentfeedback', '', hotpot::available_feedbacks_list()), $mform->createElement('text', 'studentfeedbackurl', '', array('size' => '40')));
     $mform->addGroup($elements, 'studentfeedback_elements', get_string('studentfeedback', 'hotpot'), array(' '), false);
     $mform->disabledIf('studentfeedback_elements', 'studentfeedback', 'eq', hotpot::FEEDBACK_NONE);
     $mform->disabledIf('studentfeedback_elements', 'studentfeedback', 'eq', hotpot::FEEDBACK_MOODLEFORUM);
     $mform->disabledIf('studentfeedback_elements', 'studentfeedback', 'eq', hotpot::FEEDBACK_MOODLEMESSAGING);
     $mform->addHelpButton('studentfeedback_elements', 'studentfeedback', 'hotpot');
     $mform->setAdvanced('studentfeedback_elements');
     $mform->setType('studentfeedback', PARAM_INT);
     $mform->setType('studentfeedbackurl', PARAM_URL);
     // Access control -------------------------------------------------------------
     $mform->addElement('header', 'accesscontrolhdr', get_string('accesscontrol', 'lesson'));
     //-----------------------------------------------------------------------------
     // Previous activity
     $this->add_activity_list('entry');
     // Open time
     $mform->addElement('date_time_selector', 'timeopen', get_string('timeopen', 'hotpot'), array('optional' => true));
     $mform->addHelpButton('timeopen', 'timeopenclose', 'hotpot');
     $mform->setAdvanced('timeopen');
     // Close time
     $mform->addElement('date_time_selector', 'timeclose', get_string('timeclose', 'hotpot'), array('optional' => true));
     $mform->addHelpButton('timeclose', 'timeopenclose', 'hotpot');
     $mform->setAdvanced('timeclose');
     // Time limit
     $options = array(hotpot::TIME_SPECIFIC => get_string('timelimitspecific', 'hotpot'), hotpot::TIME_TEMPLATE => get_string('timelimittemplate', 'hotpot'), hotpot::TIME_DISABLE => get_string('disable'));
     $elements = array($mform->createElement('static', '', '', get_string('timelimitsummary', 'hotpot')), $mform->createElement('static', '', '', html_writer::empty_tag('br')), $mform->createElement('select', 'timelimit', '', $options), $mform->createElement('duration', 'timelimitspecific', '', array('optional' => 0, 'defaultunit' => 1)));
     $mform->addGroup($elements, 'timelimit_elements', get_string('timelimit', 'hotpot'), '', false);
     $mform->addHelpButton('timelimit_elements', 'timelimit', 'hotpot');
     $mform->setAdvanced('timelimit_elements');
     $mform->setType('timelimit', PARAM_INT);
     $mform->disabledIf('timelimitspecific[number]', 'timelimit', 'ne', hotpot::TIME_SPECIFIC);
     $mform->disabledIf('timelimitspecific[timeunit]', 'timelimit', 'ne', hotpot::TIME_SPECIFIC);
     // Delay 1
     $elements = array($mform->createElement('static', '', '', get_string('delay1summary', 'hotpot')), $mform->createElement('static', '', '', html_writer::empty_tag('br')), $mform->createElement('duration', 'delay1', '', array('optional' => 1, 'defaultunit' => 1)));
     $mform->addGroup($elements, 'delay1_elements', get_string('delay1', 'hotpot'), '', false);
     $mform->addHelpButton('delay1_elements', 'delay1', 'hotpot');
     $mform->setAdvanced('delay1_elements');
     // the standard disabledIf for the "enable" checkbox doesn't work because we are in group, so ...
     $mform->disabledIf('delay1[number]', 'delay1[enabled]', 'notchecked', '');
     $mform->disabledIf('delay1[timeunit]', 'delay1[enabled]', 'notchecked', '');
     // Delay 2
     $elements = array($mform->createElement('static', '', '', get_string('delay2summary', 'hotpot')), $mform->createElement('static', '', '', html_writer::empty_tag('br')), $mform->createElement('duration', 'delay2', '', array('optional' => 1, 'defaultunit' => 1)));
     $mform->addGroup($elements, 'delay2_elements', get_string('delay2', 'hotpot'), '', false);
     $mform->addHelpButton('delay2_elements', 'delay2', 'hotpot');
     $mform->setAdvanced('delay2_elements');
     // the standard disabledIf for the "enable" checkbox doesn't work because we are in group, so ...
     $mform->disabledIf('delay2[number]', 'delay2[enabled]', 'notchecked', '');
     $mform->disabledIf('delay2[timeunit]', 'delay2[enabled]', 'notchecked', '');
     // Delay 3
     $options = array(hotpot::TIME_SPECIFIC => get_string('delay3specific', 'hotpot'), hotpot::TIME_TEMPLATE => get_string('delay3template', 'hotpot'), hotpot::TIME_AFTEROK => get_string('delay3afterok', 'hotpot'), hotpot::TIME_DISABLE => get_string('delay3disable', 'hotpot'));
     $elements = array($mform->createElement('static', '', '', get_string('delay3summary', 'hotpot')), $mform->createElement('static', '', '', html_writer::empty_tag('br')), $mform->createElement('select', 'delay3', '', $options), $mform->createElement('duration', 'delay3specific', '', array('optional' => 0, 'defaultunit' => 1)));
     $mform->addGroup($elements, 'delay3_elements', get_string('delay3', 'hotpot'), '', false);
     $mform->addHelpButton('delay3_elements', 'delay3', 'hotpot');
     $mform->setAdvanced('delay3_elements');
     $mform->setType('delay3', PARAM_INT);
     $mform->disabledIf('delay3specific[number]', 'delay3', 'ne', hotpot::TIME_SPECIFIC);
     $mform->disabledIf('delay3specific[timeunit]', 'delay3', 'ne', hotpot::TIME_SPECIFIC);
     // Allow review?
     //$mform->addElement('selectyesno', 'allowreview', get_string('allowreview', 'hotpot'));
     //$mform->setDefault('allowreview', get_user_preferences('hotpot_review', 1));
     //$mform->addHelpButton('allowreview', 'allowreview', 'hotpot');
     //$mform->setAdvanced('allowreview');
     // Review options -------------------------------------------------------------
     $mform->addElement('header', 'reviewoptionshdr', get_string('reviewoptions', 'hotpot'));
     //-----------------------------------------------------------------------------
     list($times, $items) = hotpot::reviewoptions_times_items();
     foreach ($times as $timename => $timevalue) {
         $elements = array();
         foreach ($items as $itemname => $itemvalue) {
             $name = $timename . $itemname;
             // e.g. duringattemptresponses
             $elements[] =& $mform->createElement('checkbox', $name, '', get_string($itemname, 'quiz'));
             $mform->setType($name, PARAM_INT);
         }
         $id = 'fgroup_id_' . $timename . '_elements';
         $text = '';
         $text .= html_writer::tag('a', get_string('all'), array('onclick' => 'select_all_in("DIV", "fitem", "' . $id . '")'));
         $text .= ' / ';
         $text .= html_writer::tag('a', get_string('none'), array('onclick' => 'deselect_all_in("DIV", "fitem", "' . $id . '")'));
         $elements[] =& $mform->createElement('static', '', '', html_writer::tag('span', $text));
         $mform->addGroup($elements, $timename . '_elements', get_string('review' . $timename, 'hotpot'), null, false);
         if ($timename == 'afterclose') {
             $mform->disabledIf('afterclose_elements', 'timeclose[off]', 'checked');
         }
     }
     // Security -------------------------------------------------------------------
     $mform->addElement('header', 'securityhdr', get_string('extraattemptrestrictions', 'quiz'));
     //-----------------------------------------------------------------------------
     // Maximum number of attempts
     $mform->addElement('select', 'attemptlimit', get_string('attemptsallowed', 'quiz'), hotpot::available_attemptlimits_list());
     $mform->setDefault('attemptlimit', get_user_preferences('hotpot_attempts', 0));
     // 0=unlimited
     $mform->setAdvanced('attemptlimit');
     $mform->addHelpButton('attemptlimit', 'attemptlimit', 'hotpot');
     // Password
     $mform->addElement('text', 'password', get_string('requirepassword', 'quiz'));
     $mform->setType('password', PARAM_TEXT);
     $mform->addHelpButton('password', 'requirepassword', 'quiz');
     $mform->setAdvanced('password');
     // IP address.
     $mform->addElement('text', 'subnet', get_string('requiresubnet', 'quiz'));
     $mform->setType('subnet', PARAM_TEXT);
     $mform->addHelpButton('subnet', 'requiresubnet', 'quiz');
     $mform->setAdvanced('subnet');
     // Grades ---------------------------------------------------------------------
     $mform->addElement('header', 'gradeshdr', get_string('grades', 'grades'));
     //-----------------------------------------------------------------------------
     // Grading method
     $mform->addElement('select', 'grademethod', get_string('grademethod', 'hotpot'), hotpot::available_grademethods_list());
     $mform->setDefault('grademethod', get_user_preferences('hotpot_grademethod', hotpot::GRADEMETHOD_HIGHEST));
     $mform->addHelpButton('grademethod', 'grademethod', 'hotpot');
     // $mform->setAdvanced('grademethod');
     // Grade weighting
     $mform->addElement('select', 'gradeweighting', get_string('gradeweighting', 'hotpot'), hotpot::available_gradeweightings_list());
     $mform->setDefault('gradeweighting', get_user_preferences('hotpot_gradeweighting', 100));
     $mform->addHelpButton('gradeweighting', 'gradeweighting', 'hotpot');
     $mform->setAdvanced('gradeweighting');
     // Remove grade item
     if ($this->is_add() || !$this->has_grade_item()) {
         $mform->addElement('hidden', 'removegradeitem', 0);
         $mform->setType('removegradeitem', PARAM_INT);
     } else {
         $mform->addElement('selectyesno', 'removegradeitem', get_string('removegradeitem', 'hotpot'));
         $mform->addHelpButton('removegradeitem', 'removegradeitem', 'hotpot');
         $mform->setType('removegradeitem', PARAM_INT);
         $mform->setAdvanced('removegradeitem');
         // this element is only available if gradeweighting==0
         $mform->disabledIf('removegradeitem', 'gradeweighting', 'selected', 0);
     }
     // Standard settings (groups etc), common to all modules ----------------------
     $this->standard_coursemodule_elements();
     // Standard buttons, common to all modules ------------------------------------
     $this->add_action_buttons();
 }