-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimport_forms.php
More file actions
224 lines (185 loc) · 9.7 KB
/
Copy pathimport_forms.php
File metadata and controls
224 lines (185 loc) · 9.7 KB
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
<?php
// This file is part of Moodle - http://moodle.org/
//
// 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.
//
// 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 Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* This file contains the form to define the predefined grade to set
*
* @package assignfeedback_wtpeer
* @copyright 2012 Enrique Castro, ULPGC
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
require_once ($CFG->libdir.'/formslib.php');
/**
* assignfeedback wtpeer iport marker allocation form
*
* @package assignfeedback_wtpeer
* @copyright 2012 Enrique Castro, ULPGC
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignfeedback_wtpeer_importmarkerallocs_form extends moodleform {
function definition (){
global $USER;
$mform = $this->_form;
$wtpeer = $this->_customdata['wtpeer'];
$assignment = $wtpeer->get_assignment();
$mform->addElement('header', 'general', get_string('importmarkers', 'assignfeedback_wtpeer'));
$fileoptions = array('subdirs'=>0,
'maxbytes'=>$assignment->get_course()->maxbytes,
'accepted_types'=>'csv',
'maxfiles'=>1,
'return_types'=>FILE_INTERNAL);
$mform->addElement('filepicker', 'markersfile', get_string('uploadafile'), null, $fileoptions);
$mform->addRule('markersfile', get_string('uploadnofilefound'), 'required', null, 'client');
$mform->addHelpButton('markersfile', 'markersfile', 'assignfeedback_wtpeer');
$a = new stdClass;
$a->user = core_text::strtolower(get_string('user'));
$a->marker = core_text::strtolower(get_string('marker', 'assign'));
$a->item = core_text::strtolower(get_string('assessment', 'assignfeedback_wtpeer'));
$a->itemnames = array();
$weights = $wtpeer->get_assessment_weights();
foreach($weights as $item => $weight) {
if($weight) {
$a->itemnames[]= core_text::strtolower(get_string('row'.$item, 'assignfeedback_wtpeer'));
}
}
if($a->itemnames) {
$a->itemnames = implode ('|', $a->itemnames);
} else {
$a->itemnames = '';
}
$mform->addElement('static', 'explain1', '', get_string('headercolumns', 'assignfeedback_wtpeer', $a));
$encodings = core_text::get_encodings();
$mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
$mform->addHelpButton('encoding', 'encoding', 'grades');
$radio = array();
$radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
$radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
$radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
$radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
$mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
$mform->addHelpButton('separator', 'separator', 'grades');
$mform->setDefault('separator', 'comma');
if ($assignment->get_instance()->teamsubmission) {
$mform->addElement('selectyesno', 'applytoall', get_string('applytoteam', 'assign'));
$mform->setDefault('applytoall', 1);
} else {
$mform->addElement('hidden', 'applytoall', 0);
$mform->setType('applytoall', PARAM_INT);
}
$options = array(0 => get_string('no'),
1 => get_string('removeitemmarkers', 'assignfeedback_wtpeer'),
2 => get_string('removeallmarkers', 'assignfeedback_wtpeer'));
$mform->addElement('select', 'removemarkers', get_string('removeexisting', 'assignfeedback_wtpeer'), $options);
$mform->addHelpButton('removemarkers', 'removeexisting', 'assignfeedback_wtpeer');
$mform->setType('removemarkers', PARAM_INT);
$mform->setDefault('removemarkers', 0);
$mform->addElement('hidden', 'confirmimport', 0);
$mform->setType('confirmimport', PARAM_INT);
$wtpeer->add_standard_form_items($mform);
$this->add_action_buttons();
}
function validation($data, $files) {
global $CFG, $USER, $DB;
$errors = parent::validation($data, $files);
return $errors;
}
}
/**
* assignfeedback wtpeer iport marker allocation form
*
* @package assignfeedback_wtpeer
* @copyright 2012 Enrique Castro, ULPGC
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class assignfeedback_wtpeer_importallocsconfirm_form extends moodleform {
function definition (){
global $USER;
$mform = $this->_form;
$wtpeer = $this->_customdata['wtpeer'];
$confirm = $this->_customdata['confirm'];
$assignment = $wtpeer->get_assignment();
if($confirm) {
// if we are confirming
// we only need the names for retrieving, data is not to be use here
$mform->addElement('hidden', 'importid', 0);
$mform->setType('importid', PARAM_INT);
$mform->addElement('hidden', 'encoding', 'a');
$mform->setType('encoding', PARAM_ALPHANUMEXT);
$mform->addElement('hidden', 'separator', 'a');
$mform->setType('separator', PARAM_ALPHA);
$mform->addElement('hidden', 'draftid', 0);
$mform->setType('draftid', PARAM_INT);
$mform->addElement('hidden', 'removemarkers', 0);
$mform->setType('removemarkers', PARAM_INT);
$mform->addElement('hidden', 'applytoall', 0);
$mform->setType('applytoall', PARAM_INT);
} else {
$mform->addElement('header', 'general', get_string('importmarkersconfirm', 'assignfeedback_wtpeer'));
$csvdata = $this->_customdata['csvdata'];
$gradeimporter = $this->_customdata['gradeimporter'];
$removemarkers = $this->_customdata['removemarkers'];
$draftid = $this->_customdata['draftid'];
$applytoall = $this->_customdata['applytoall'];
if ($csvdata) {
$gradeimporter->parsecsv($csvdata);
}
if (!$gradeimporter->init()) {
$thisurl = new moodle_url('/mod/assign/view.php', array('action'=>'viewpluginpage',
'pluginsubtype'=>'assignfeedback',
'plugin'=>'wtpeer',
'pluginaction'=>'importmarkers',
'id'=>$assignment->get_course_module()->id));
$struser = core_text::strtolower(get_string('user'));
$strmarker = core_text::strtolower(get_string('marker', 'assign'));
$a = $struser. ' '. $strmarker;
print_error('invalidimporter', 'assignfeedback_wtpeer', $thisurl, $a);
return;
}
$skip = array();
$valid = 0;
while ($record = $gradeimporter->next()) {
if(isset($record->skip)) {
$skip[] = $record->skip;
} else {
$valid++;
}
}
$gradeimporter->close(false);
$mform->addElement('static', 'validmarkersassigns', get_string('validmarkersassigns', 'assignfeedback_wtpeer'), $valid);
if($skip) {
$skip = html_writer::alist($skip, array('class'=>'nonvalidmarkersassigns'));
$mform->addElement('static', 'nonvalidmarkersassigns', get_string('nonvalidmarkersassigns', 'assignfeedback_wtpeer'), $skip);
}
$mform->addElement('hidden', 'importid', $gradeimporter->importid);
$mform->setType('importid', PARAM_INT);
$mform->addElement('hidden', 'encoding', $gradeimporter->get_encoding());
$mform->setType('encoding', PARAM_ALPHANUMEXT);
$mform->addElement('hidden', 'separator', $gradeimporter->get_separator());
$mform->setType('separator', PARAM_ALPHA);
$mform->addElement('hidden', 'draftid', $draftid);
$mform->setType('draftid', PARAM_INT);
$mform->addElement('hidden', 'removemarkers', $removemarkers);
$mform->setType('removemarkers', PARAM_INT);
$mform->addElement('hidden', 'applytoall', $applytoall);
$mform->setType('applytoall', PARAM_INT);
}
$mform->addElement('hidden', 'confirmimport', 1);
$mform->setType('confirmimport', PARAM_INT);
$wtpeer->action = 'importallocsconfirm';
$wtpeer->add_standard_form_items($mform);
$this->add_action_buttons();
}
}