2 require_once ($CFG->libdir
.'/formslib.php');
4 * This class adds extra methods to form wrapper specific to be used for module
5 * add / update forms (mod/{modname}.mod_form.php replaces deprecared mod/{modname}/mod.html
8 class moodleform_mod
extends moodleform
{
10 * Instance of the module that is being updated. This is the id of the {prefix}{modulename}
11 * record. Can be used in form definition. Will be "" if this is an 'add' form and not an
18 * Section of course that module instance will be put in or is in.
19 * This is always the section number itself.
25 * Coursemodle record of the module that is being updated. Will be null if this is an 'add' form and not an
32 function moodleform_mod($instance, $section, $cm) {
33 $this->_instance
= $instance;
34 $this->_section
= $section;
36 parent
::moodleform('modedit.php');
39 * Only available on moodleform_mod.
41 * @param array $default_values passed by reference
43 function data_preprocessing(&$default_values){
46 * Load in existing data as form defaults. Usually new entry defaults are stored directly in
47 * form definition (new entry form); this function is used to load in data where values
48 * already exist and data is being edited (edit entry form).
50 * @param mixed $default_values object or array of default values
52 function set_data($default_values) {
53 if (is_object($default_values)) {
54 $default_values = (array)$default_values;
56 $this->data_preprocessing($default_values);
57 parent
::set_data($default_values +
$this->standard_coursemodule_elements_settings());//never slashed for moodleform_mod
60 * Adds all the standard elements to a form to edit the settings for an activity module.
62 * @param bool $supportsgroups does this module support groups?
64 function standard_coursemodule_elements($supportsgroups=true){
65 $mform =& $this->_form
;
66 $mform->addElement('header', '', get_string('modstandardels', 'form'));
68 $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
70 $mform->addElement('modvisible', 'visible', get_string('visible'));
72 $this->standard_hidden_coursemodule_elements();
75 function standard_hidden_coursemodule_elements(){
76 $mform =& $this->_form
;
77 $mform->addElement('hidden', 'course', 0);
78 $mform->setType('course', PARAM_INT
);
80 $mform->addElement('hidden', 'coursemodule', 0);
81 $mform->setType('coursemodule', PARAM_INT
);
83 $mform->addElement('hidden', 'section', 0);
84 $mform->setType('section', PARAM_INT
);
86 $mform->addElement('hidden', 'module', 0);
87 $mform->setType('module', PARAM_INT
);
89 $mform->addElement('hidden', 'modulename', '');
90 $mform->setType('modulename', PARAM_SAFEDIR
);
92 $mform->addElement('hidden', 'instance', 0);
93 $mform->setType('instance', PARAM_INT
);
95 $mform->addElement('hidden', 'add', 0);
96 $mform->setType('add', PARAM_ALPHA
);
98 $mform->addElement('hidden', 'update', 0);
99 $mform->setType('update', PARAM_INT
);
101 $mform->addElement('hidden', 'return', 0);
102 $mform->setType('return', PARAM_BOOL
);
106 * This function is called by course/modedit.php to setup defaults for standard form
109 * @param object $course
111 * @param integer $section
114 function standard_coursemodule_elements_settings(){
115 return ($this->modgroupmode_settings() +
$this->modvisible_settings());
118 * This is called from modedit.php to load the default for the groupmode element.
120 * @param object $course
123 function modgroupmode_settings(){
125 return array('groupmode'=>groupmode($COURSE, $this->_cm
));
128 * This is called from modedit.php to set the default for modvisible form element.
130 * @param object $course
132 * @param integer $section section is a db id when updating a activity config
133 * or the section no when adding a new activity
135 function modvisible_settings(){
138 $section=$this->_section
;
140 $visible = $cm->visible
;
145 $hiddensection = !get_field('course_sections', 'visible', 'section', $section, 'course', $COURSE->id
);
146 if ($hiddensection) {
149 return array('visible'=>$visible);