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', 'modstandardelshdr', get_string('modstandardels', 'form'));
68 // TODO: we must define this as mod property!
69 $mform->addElement('modgroupmode', 'groupmode', get_string('groupmode'));
71 $mform->addElement('modvisible', 'visible', get_string('visible'));
72 $mform->addElement('text', 'cmidnumber', get_string('idnumber'));
73 $this->standard_hidden_coursemodule_elements();
76 function standard_hidden_coursemodule_elements(){
77 $mform =& $this->_form
;
78 $mform->addElement('hidden', 'course', 0);
79 $mform->setType('course', PARAM_INT
);
81 $mform->addElement('hidden', 'coursemodule', 0);
82 $mform->setType('coursemodule', PARAM_INT
);
84 $mform->addElement('hidden', 'section', 0);
85 $mform->setType('section', PARAM_INT
);
87 $mform->addElement('hidden', 'module', 0);
88 $mform->setType('module', PARAM_INT
);
90 $mform->addElement('hidden', 'modulename', '');
91 $mform->setType('modulename', PARAM_SAFEDIR
);
93 $mform->addElement('hidden', 'instance', 0);
94 $mform->setType('instance', PARAM_INT
);
96 $mform->addElement('hidden', 'add', 0);
97 $mform->setType('add', PARAM_ALPHA
);
99 $mform->addElement('hidden', 'update', 0);
100 $mform->setType('update', PARAM_INT
);
102 $mform->addElement('hidden', 'return', 0);
103 $mform->setType('return', PARAM_BOOL
);
107 * This function is called by course/modedit.php to setup defaults for standard form
110 * @param object $course
112 * @param integer $section
115 function standard_coursemodule_elements_settings(){
116 return ($this->modgroupmode_settings() +
$this->modvisible_settings());
119 * This is called from modedit.php to load the default for the groupmode element.
121 * @param object $course
124 function modgroupmode_settings(){
126 return array('groupmode'=>groupmode($COURSE, $this->_cm
));
129 * This is called from modedit.php to set the default for modvisible form element.
131 * @param object $course
133 * @param integer $section section is a db id when updating a activity config
134 * or the section no when adding a new activity
136 function modvisible_settings(){
139 $section=$this->_section
;
141 $visible = $cm->visible
;
146 $hiddensection = !get_field('course_sections', 'visible', 'section', $section, 'course', $COURSE->id
);
147 if ($hiddensection) {
150 return array('visible'=>$visible);