adding some strings
[moodle-linuxchix.git] / course / moodleform_mod.php
bloba0869614cb2320e0e94411416a9ecfd77fd6ef0e
1 <?php
2 require_once ($CFG->libdir.'/formslib.php');
3 /**
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
7 */
8 class moodleform_mod extends moodleform {
9 /**
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
12 * update one.
14 * @var mixed
16 var $_instance;
17 /**
18 * Section of course that module instance will be put in or is in.
19 * This is always the section number itself.
21 * @var mixed
23 var $_section;
24 /**
25 * Coursemodle record of the module that is being updated. Will be null if this is an 'add' form and not an
26 * update one.
28 * @var mixed
30 var $_cm;
32 function moodleform_mod($instance, $section, $cm) {
33 $this->_instance = $instance;
34 $this->_section = $section;
35 $this->_cm = $cm;
36 parent::moodleform('modedit.php');
38 /**
39 * Only available on moodleform_mod.
41 * @param array $default_values passed by reference
43 function data_preprocessing(&$default_values){
45 /**
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
59 /**
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'));
67 if ($supportsgroups){
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
108 * elements.
110 * @param object $course
111 * @param object $cm
112 * @param integer $section
113 * @return unknown
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
122 * @param object $cm
124 function modgroupmode_settings(){
125 global $COURSE;
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
132 * @param object $cm
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(){
137 global $COURSE;
138 $cm=$this->_cm;
139 $section=$this->_section;
140 if ($cm) {
141 $visible = $cm->visible;
142 } else {
143 $visible = 1;
146 $hiddensection = !get_field('course_sections', 'visible', 'section', $section, 'course', $COURSE->id);
147 if ($hiddensection) {
148 $visible = 0;
150 return array('visible'=>$visible);