| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php 2 require_once ($CFG->dirroot.'/course/moodleform_mod.php'); 3 4 class mod_choice_mod_form extends moodleform_mod { 5 6 function definition() { 7 global $CFG, $CHOICE_SHOWRESULTS, $CHOICE_PUBLISH, $CHOICE_DISPLAY; 8 9 $mform =& $this->_form; 10 11 //------------------------------------------------------------------------------- 12 $mform->addElement('header', 'general', get_string('general', 'form')); 13 14 $mform->addElement('text', 'name', get_string('choicename', 'choice'), array('size'=>'64')); 15 if (!empty($CFG->formatstringstriptags)) { 16 $mform->setType('name', PARAM_TEXT); 17 } else { 18 $mform->setType('name', PARAM_CLEAN); 19 } 20 $mform->addRule('name', null, 'required', null, 'client'); 21 22 $mform->addElement('htmleditor', 'text', get_string('choicetext', 'choice')); 23 $mform->setType('text', PARAM_RAW); 24 $mform->addRule('text', null, 'required', null, 'client'); 25 $mform->setHelpButton('text', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton'); 26 27 $mform->addElement('format', 'format', get_string('format')); 28 29 //------------------------------------------------------------------------------- 30 $repeatarray=array(); 31 $repeatarray[] = &MoodleQuickForm::createElement('header', '', get_string('choice','choice').' {no}'); 32 $repeatarray[] = &MoodleQuickForm::createElement('text', 'option', get_string('choice','choice')); 33 $repeatarray[] = &MoodleQuickForm::createElement('text', 'limit', get_string('limit','choice')); 34 $repeatarray[] = &MoodleQuickForm::createElement('hidden', 'optionid', 0); 35 36 $menuoptions=array(); 37 $menuoptions[0] = get_string('disable'); 38 $menuoptions[1] = get_string('enable'); 39 $mform->addElement('header', 'timerestricthdr', get_string('limit', 'choice')); 40 $mform->addElement('select', 'limitanswers', get_string('limitanswers', 'choice'), $menuoptions); 41 $mform->setHelpButton('limitanswers', array('limit', get_string('limit', 'choice'), 'choice')); 42 43 if ($this->_instance){ 44 $repeatno=count_records('choice_options', 'choiceid', $this->_instance); 45 $repeatno += 2; 46 } else { 47 $repeatno = 5; 48 } 49 50 $repeateloptions = array(); 51 $repeateloptions['limit']['default'] = 0; 52 $repeateloptions['limit']['disabledif'] = array('limitanswers', 'eq', 0); 53 $mform->setType('limit', PARAM_INT); 54 55 $repeateloptions['option']['helpbutton'] = array('options', get_string('modulenameplural', 'choice'), 'choice'); 56 $mform->setType('option', PARAM_CLEAN); 57 58 $mform->setType('optionid', PARAM_INT); 59 60 $this->repeat_elements($repeatarray, $repeatno, 61 $repeateloptions, 'option_repeats', 'option_add_fields', 3); 62 63 64 65 66 //------------------------------------------------------------------------------- 67 $mform->addElement('header', 'timerestricthdr', get_string('timerestrict', 'choice')); 68 $mform->addElement('checkbox', 'timerestrict', get_string('timerestrict', 'choice')); 69 $mform->setHelpButton('timerestrict', array("timerestrict", get_string("timerestrict","choice"), "choice")); 70 71 72 $mform->addElement('date_time_selector', 'timeopen', get_string("choiceopen", "choice")); 73 $mform->disabledIf('timeopen', 'timerestrict'); 74 75 $mform->addElement('date_time_selector', 'timeclose', get_string("choiceclose", "choice")); 76 $mform->disabledIf('timeclose', 'timerestrict'); 77 78 //------------------------------------------------------------------------------- 79 $mform->addElement('header', 'miscellaneoussettingshdr', get_string('miscellaneoussettings', 'form')); 80 81 $mform->addElement('select', 'display', get_string("displaymode","choice"), $CHOICE_DISPLAY); 82 83 $mform->addElement('select', 'showresults', get_string("publish", "choice"), $CHOICE_SHOWRESULTS); 84 85 $mform->addElement('select', 'publish', get_string("privacy", "choice"), $CHOICE_PUBLISH); 86 $mform->disabledIf('publish', 'showresults', 'eq', 0); 87 88 $mform->addElement('selectyesno', 'allowupdate', get_string("allowupdate", "choice")); 89 90 $mform->addElement('selectyesno', 'showunanswered', get_string("showunanswered", "choice")); 91 92 93 //------------------------------------------------------------------------------- 94 $features = new stdClass; 95 $features->groups = true; 96 $features->groupings = true; 97 $features->groupmembersonly = true; 98 $features->gradecat = false; 99 $this->standard_coursemodule_elements($features); 100 //------------------------------------------------------------------------------- 101 $this->add_action_buttons(); 102 } 103 104 function data_preprocessing(&$default_values){ 105 if (!empty($this->_instance) && ($options = get_records_menu('choice_options','choiceid', $this->_instance, 'id', 'id,text')) 106 && ($options2 = get_records_menu('choice_options','choiceid', $this->_instance, 'id', 'id,maxanswers')) ) { 107 $choiceids=array_keys($options); 108 $options=array_values($options); 109 $options2=array_values($options2); 110 111 foreach (array_keys($options) as $key){ 112 $default_values['option['.$key.']'] = $options[$key]; 113 $default_values['limit['.$key.']'] = $options2[$key]; 114 $default_values['optionid['.$key.']'] = $choiceids[$key]; 115 } 116 117 } 118 if (empty($default_values['timeopen'])) { 119 $default_values['timerestrict'] = 0; 120 } else { 121 $default_values['timerestrict'] = 1; 122 } 123 124 } 125 126 function validation($data, $files) { 127 $errors = parent::validation($data, $files); 128 129 $choices = 0; 130 foreach ($data['option'] as $option){ 131 if (trim($option) != ''){ 132 $choices++; 133 } 134 } 135 136 if ($choices < 1) { 137 $errors['option[0]'] = get_string('fillinatleastoneoption', 'choice'); 138 } 139 140 if ($choices < 2) { 141 $errors['option[1]'] = get_string('fillinatleastoneoption', 'choice'); 142 } 143 144 return $errors; 145 } 146 147 } 148 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |