-
Notifications
You must be signed in to change notification settings - Fork 88
/
mod_form.php
142 lines (137 loc) · 6.8 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
132
133
134
135
136
137
138
139
140
141
142
<?php
// This file is part of VPL for Moodle - http://vpl.dis.ulpgc.es/
//
// VPL for Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// VPL for Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with VPL for Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* VPL instance form
*
* @package mod_vpl
* @copyright 2012 Juan Carlos Rodríguez-del-Pino
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @author Juan Carlos Rodríguez-del-Pino <[email protected]>
*/
defined('MOODLE_INTERNAL') || die();
require_once(dirname(__FILE__).'/../../course/moodleform_mod.php');
require_once(dirname(__FILE__).'/lib.php');
require_once(dirname(__FILE__).'/vpl.class.php');
class mod_vpl_mod_form extends moodleform_mod {
protected function definition() {
global $CFG;
$plugincfg = get_config('mod_vpl');
$mform = & $this->_form;
$mform->addElement( 'header', 'general', get_string( 'general', 'form' ) );
$mform->addElement( 'text', 'name', get_string( 'name' ), [
'size' => '50',
] );
$mform->setType( 'name', PARAM_TEXT );
$mform->addRule( 'name', null, 'required', null, 'client' );
$mform->applyFilter( 'name', 'trim' );
$mform->addElement( 'textarea', 'shortdescription', get_string( 'shortdescription', VPL ), [
'cols' => 70,
'rows' => 1,
] );
$mform->setType( 'shortdescription', PARAM_RAW );
if ($CFG->version < 2015041700.00) { // Moodle version < 2.9Beta.
$this->add_intro_editor( false, get_string( 'fulldescription', VPL ) ); // Deprecated from 2.9beta.
} else {
$this->standard_intro_elements( get_string( 'fulldescription', VPL ) );
}
$mform->addElement( 'header', 'submissionperiod', get_string( 'submissionperiod', VPL ) );
$secondsday = 24 * 60 * 60;
$now = time();
$inittime = round( $now / $secondsday ) * $secondsday + 5 * 60;
$endtime = $inittime + (8 * $secondsday) - 5 * 60;
$mform->addElement( 'date_time_selector', 'startdate', get_string( 'startdate', VPL ), [
'optional' => true,
] );
$mform->setDefault( 'startdate', 0 );
$mform->addElement( 'date_time_selector', 'duedate', get_string( 'duedate', VPL ), [
'optional' => true,
] );
$mform->setDefault( 'duedate', $endtime );
$mform->addElement( 'header', 'submissionrestrictions', get_string( 'submissionrestrictions', VPL ) );
$mform->addElement( 'text', 'maxfiles', get_string( 'maxfiles', VPL ) );
$mform->setType( 'maxfiles', PARAM_INT);
$mform->setDefault( 'maxfiles', 1 );
$mform->addElement( 'select', 'worktype', get_string( 'worktype', VPL ), [
0 => get_string( 'individualwork', VPL ),
1 => get_string( 'groupwork', VPL ),
] );
$mform->addElement( 'selectyesno', 'restrictededitor', get_string( 'restrictededitor', VPL ) );
$mform->setDefault( 'restrictededitor', false );
$mform->setAdvanced( 'restrictededitor' );
$mform->addElement( 'selectyesno', 'example', get_string( 'isexample', VPL ) );
$mform->setDefault( 'example', false );
$mform->setAdvanced( 'example' );
$max = \mod_vpl\util\phpconfig::get_post_max_size();
if ($plugincfg->maxfilesize > 0 && $plugincfg->maxfilesize < $max) {
$max = $plugincfg->maxfilesize;
}
$mform->addElement( 'select', 'maxfilesize', get_string( 'maxfilesize', VPL ), vpl_get_select_sizes( 16 * 1024, $max ) );
$mform->setType( 'maxfilesize', PARAM_INT );
$mform->setDefault( 'maxfilesize', 1 );
$mform->setAdvanced( 'maxfilesize' );
$mform->addElement( 'passwordunmask', 'password', get_string( 'password' ) );
$mform->setType( 'password', PARAM_TEXT );
$mform->setAdvanced( 'password' );
$mform->addElement( 'text', 'requirednet', get_string( 'requirednet', VPL ), [
'size' => '60',
] );
$mform->setType( 'requirednet', PARAM_TEXT );
$mform->setDefault( 'requirednet', '' );
$mform->setAdvanced( 'requirednet' );
$mform->addElement( 'selectyesno', 'sebrequired', get_string( 'sebrequired', VPL ) );
$mform->setDefault( 'sebrequired', 0 );
$mform->addHelpButton('sebrequired', 'sebrequired', VPL);
$mform->setAdvanced( 'sebrequired' );
$mform->addElement( 'textarea', 'sebkeys', get_string( 'sebkeys', VPL ), [
'cols' => 66,
'rows' => 2,
] );
$mform->setType( 'sebkeys', PARAM_TEXT);
$mform->setDefault( 'sebkeys', '' );
$mform->addHelpButton('sebkeys', 'sebkeys', VPL);
$mform->setAdvanced( 'sebkeys' );
// Grade.
$this->standard_grading_coursemodule_elements();
$mform->addElement( 'text', 'reductionbyevaluation', get_string( 'reductionbyevaluation', VPL ));
$mform->setType( 'reductionbyevaluation', PARAM_TEXT);
$mform->setDefault( 'reductionbyevaluation', 0 );
$mform->addHelpButton('reductionbyevaluation', 'reductionbyevaluation', VPL);
$mform->addElement( 'text', 'freeevaluations', get_string( 'freeevaluations', VPL ));
$mform->setType( 'freeevaluations', PARAM_INT);
$mform->setDefault( 'freeevaluations', 0 );
$mform->addHelpButton('freeevaluations', 'freeevaluations', VPL);
$mform->addElement( 'selectyesno', 'visiblegrade', get_string( 'visiblegrade', VPL ) );
$mform->setDefault( 'visiblegrade', 1 );
// Standard course elements.
$this->standard_coursemodule_elements();
// End form.
$this->add_action_buttons();
}
public function validate($field, $pattern, $message, & $data, & $errors) {
$data[$field] = trim( $data[$field] );
$res = preg_match($pattern, $data[$field]);
if ( $res == 0 || $res == false) {
$errors[$field] = $message;
}
}
public function validation($data, $files) {
$errors = parent::validation($data, $files);
$this->validate('freeevaluations', '/^[0-9]*$/', '[0..]', $data, $errors);
$this->validate('maxfiles', '/^[0-9]*$/', '[0..]', $data, $errors);
$this->validate('reductionbyevaluation', '/^[0-9]*(\.[0-9]+)?%?$/', '#[.#][%]', $data, $errors);
return $errors;
}
}