-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod_form.php
131 lines (104 loc) · 6.1 KB
/
mod_form.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
require_once ($CFG->dirroot.'/course/moodleform_mod.php');
class mod_programming_mod_form extends moodleform_mod {
function definition() {
global $CFG, $COURSE;
$mform =& $this->_form;
//-------------------------------------------------------------------------------
$mform->addElement('header', 'general', get_string('general', 'form'));
$mform->addElement('text', 'globalid', get_string('globalid', 'programming'));
$mform->addElement('text', 'name', get_string('name'), array('size'=>'30'));
if (!empty($CFG->formatstringstriptags)) {
$mform->setType('name', PARAM_TEXT);
} else {
$mform->setType('name', PARAM_CLEAN);
}
$mform->addRule('name', null, 'required', null, 'client');
$mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
$mform->addElement('htmleditor', 'description', get_string('description', 'programming'));
$mform->setType('description', PARAM_RAW);
$mform->addRule('description', get_string('required'), 'required', null, 'client');
$mform->setHelpButton('description', array('writing', 'questions', 'richtext'), false, 'editorhelpbutton');
$mform->addElement('format', 'descformat', get_string('format'));
//-------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('grade'));
$options = array();
$options[0] = get_string('nograde', 'programming');
for ($i = 5; $i <= 100; $i += 5) {
$options[$i] = $i;
}
$mform->addElement('select', 'grade', get_string('grade'), $options);
$options = array();
for ($i = 10; $i > 0; $i -= 1) {
$options[$i] = $i / 10.0;
}
$mform->addElement('select', 'discount', get_string('discount', 'programming'), $options);
$mform->addElement('date_time_selector', 'timeopen', get_string('timeopen', 'programming'));
$mform->addElement('date_time_selector', 'timediscount', get_string('timediscount', 'programming'));
$mform->addElement('date_time_selector', 'timeclose', get_string('timeclose', 'programming'));
$mform->addElement('selectyesno', 'allowlate', get_string('allowlate', 'programming'));
//-------------------------------------------------------------------------------
$mform->addElement('header', '', get_string('program', 'programming'));
$langs = programming_get_language_options();
$select = $mform->addElement('select', 'langlimit', get_string('langlimit', 'programming'), $langs);
$select->setMultiple(true);
$inputs = array();
$inputs[] = &MoodleQuickForm::createElement('radio', 'inputs', null, get_string('stdin', 'programming'), 0);
$inputs[] = &MoodleQuickForm::createElement('radio', 'inputs', null, get_string('inputfromfile', 'programming'), 1);
$inputs[] = &MoodleQuickForm::createElement('text', 'inputfile');
$mform->addGroup($inputs, 'inputs', get_string('inputfile', 'programming'), ' ', false);
$mform->disabledIf('inputfile', 'inputs', 'eq', 0);
$outputs = array();
$outputs[] = &MoodleQuickForm::createElement('radio', 'outputs', null, get_string('stdout', 'programming'), 0);
$outputs[] = &MoodleQuickForm::createElement('radio', 'outputs', null, get_string('outputtofile', 'programming'), 1);
$outputs[] = &MoodleQuickForm::createElement('text', 'outputfile');
$mform->addGroup($outputs, 'outputs', get_string('outputfile', 'programming'), ' ', false);
$mform->disabledIf('outputfile', 'outputs', 'eq', 0);
$options = programming_get_timelimit_options();
$mform->addElement('select', 'timelimit', get_string('timelimit', 'programming'), $options);
$options = programming_get_memlimit_options();
$mform->addElement('select', 'memlimit', get_string('memlimit', 'programming'), $options);
$options = programming_get_nproc_options();
$mform->addElement('select', 'nproc', get_string('extraproc', 'programming'), $options);
$options = array();
$options[0] = get_string('attemptsunlimited', 'programming');
$options[1] = get_string('1attempt', 'programming');
for ($i = 2; $i <= PROGRAMMING_MAX_ATTEMPTS; $i++) {
$options[$i] = get_string('nattempts', 'programming', $i);
}
$mform->addElement('select', 'attempts', get_string('attempts', 'programming'), $options);
$mform->addElement('selectyesno', 'keeplatestonly', get_string('keeplatestonly', 'programming'));
$options = programming_get_showmode_options();
$mform->addElement('select', 'showmode', get_string('showmode', 'programming'), $options);
//-------------------------------------------------------------------------------
$features = new stdClass;
$features->groups = true;
$features->groupings = true;
$features->groupmembersonly = true;
$this->standard_coursemodule_elements($features);
//-------------------------------------------------------------------------------
// buttons
$this->add_action_buttons();
}
function data_preprocessing(&$default_values) {
if (empty($default_values['discount'])) {
$default_values['discount'] = 8;
}
if (empty($default_values['inputs'])) {
$default_values['inputs'] = (isset($default_values['inputfile']) && $default_values['inputfile']) ? 1 : 0;
}
if (empty($default_values['outputs'])) {
$default_values['outputs'] = (isset($default_values['outputfile']) && $default_values['outputfile']) ? 1 : 0;
}
if (empty($default_values['langlimit']) && !empty($default_values['id'])) {
$default_values['langlimit'] = array();
$rows = get_records('programming_langlimit', 'programmingid', $default_values['id']);
if (is_array($rows)) {
foreach ($rows as $row) {
$default_values['langlimit'][] = $row->languageid;
}
}
}
}
}
?>