2 if (!defined('MOODLE_INTERNAL')) {
3 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
6 require_once ($CFG->dirroot
.'/course/moodleform_mod.php');
8 class mod_data_mod_form
extends moodleform_mod
{
10 function definition() {
13 $mform =& $this->_form
;
15 //-------------------------------------------------------------------------------
16 $mform->addElement('header', 'general', get_string('general', 'form'));
18 $mform->addElement('text', 'name', get_string('name'), array('size'=>'64'));
19 if (!empty($CFG->formatstringstriptags
)) {
20 $mform->setType('name', PARAM_TEXT
);
22 $mform->setType('name', PARAM_CLEANHTML
);
24 $mform->addRule('name', null, 'required', null, 'client');
25 $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
27 $this->standard_intro_elements(get_string('intro', 'data'));
29 // ----------------------------------------------------------------------
30 $mform->addElement('header', 'entrieshdr', get_string('entries', 'data'));
32 $mform->addElement('selectyesno', 'approval', get_string('requireapproval', 'data'));
33 $mform->addHelpButton('approval', 'requireapproval', 'data');
35 $mform->addElement('selectyesno', 'manageapproved', get_string('manageapproved', 'data'));
36 $mform->addHelpButton('manageapproved', 'manageapproved', 'data');
37 $mform->setDefault('manageapproved', 1);
38 $mform->disabledIf('manageapproved', 'approval', 'eq', 0);
40 $mform->addElement('selectyesno', 'comments', get_string('allowcomments', 'data'));
42 $countoptions = array(0=>get_string('none'))+
43 (array_combine(range(1, DATA_MAX_ENTRIES
), // Keys.
44 range(1, DATA_MAX_ENTRIES
))); // Values.
45 $mform->addElement('select', 'requiredentries', get_string('requiredentries', 'data'), $countoptions);
46 $mform->addHelpButton('requiredentries', 'requiredentries', 'data');
48 $mform->addElement('select', 'requiredentriestoview', get_string('requiredentriestoview', 'data'), $countoptions);
49 $mform->addHelpButton('requiredentriestoview', 'requiredentriestoview', 'data');
51 $mform->addElement('select', 'maxentries', get_string('maxentries', 'data'), $countoptions);
52 $mform->addHelpButton('maxentries', 'maxentries', 'data');
54 // ----------------------------------------------------------------------
55 $mform->addElement('header', 'availibilityhdr', get_string('availability'));
57 $mform->addElement('date_time_selector', 'timeavailablefrom', get_string('availablefromdate', 'data'),
58 array('optional' => true));
60 $mform->addElement('date_time_selector', 'timeavailableto', get_string('availabletodate', 'data'),
61 array('optional' => true));
63 $mform->addElement('date_time_selector', 'timeviewfrom', get_string('viewfromdate', 'data'),
64 array('optional' => true));
66 $mform->addElement('date_time_selector', 'timeviewto', get_string('viewtodate', 'data'),
67 array('optional' => true));
69 // ----------------------------------------------------------------------
70 if ($CFG->enablerssfeeds
&& $CFG->data_enablerssfeeds
) {
71 $mform->addElement('header', 'rsshdr', get_string('rss'));
72 $mform->addElement('select', 'rssarticles', get_string('numberrssarticles', 'data') , $countoptions);
75 $this->standard_grading_coursemodule_elements();
77 $this->standard_coursemodule_elements();
79 //-------------------------------------------------------------------------------
81 $this->add_action_buttons();
85 * Enforce validation rules here
87 * @param array $data array of ("fieldname"=>value) of submitted data
88 * @param array $files array of uploaded files "element_name"=>tmp_file_path
91 public function validation($data, $files) {
92 $errors = parent
::validation($data, $files);
94 // Check open and close times are consistent.
95 if ($data['timeavailablefrom'] && $data['timeavailableto'] &&
96 $data['timeavailableto'] < $data['timeavailablefrom']) {
97 $errors['timeavailableto'] = get_string('availabletodatevalidation', 'data');
99 if ($data['timeviewfrom'] && $data['timeviewto'] &&
100 $data['timeviewto'] < $data['timeviewfrom']) {
101 $errors['timeviewto'] = get_string('viewtodatevalidation', 'data');
107 function data_preprocessing(&$default_values){
108 parent
::data_preprocessing($default_values);