1 |
efrain |
1 |
<?php
|
|
|
2 |
// This file is part of Moodle - http://moodle.org/
|
|
|
3 |
//
|
|
|
4 |
// Moodle is free software: you can redistribute it and/or modify
|
|
|
5 |
// it under the terms of the GNU General Public License as published by
|
|
|
6 |
// the Free Software Foundation, either version 3 of the License, or
|
|
|
7 |
// (at your option) any later version.
|
|
|
8 |
//
|
|
|
9 |
// Moodle is distributed in the hope that it will be useful,
|
|
|
10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
12 |
// GNU General Public License for more details.
|
|
|
13 |
//
|
|
|
14 |
// You should have received a copy of the GNU General Public License
|
|
|
15 |
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
16 |
|
|
|
17 |
require_once($CFG->libdir.'/formslib.php');
|
|
|
18 |
require_once($CFG->libdir.'/gradelib.php');
|
|
|
19 |
|
|
|
20 |
if (!defined('MOODLE_INTERNAL')) {
|
|
|
21 |
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Form for mapping columns to the fields in the table.
|
|
|
26 |
*
|
|
|
27 |
* @package gradeimport_direct
|
|
|
28 |
* @copyright 2014 Adrian Greeve <adrian@moodle.com>
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class gradeimport_direct_mapping_form extends moodleform {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* Definition method.
|
|
|
35 |
*/
|
|
|
36 |
public function definition() {
|
|
|
37 |
global $CFG, $COURSE;
|
|
|
38 |
$mform = $this->_form;
|
|
|
39 |
|
|
|
40 |
// This is an array of headers.
|
|
|
41 |
$header = $this->_customdata['header'];
|
|
|
42 |
// Course id.
|
|
|
43 |
|
|
|
44 |
$mform->addElement('header', 'general', get_string('identifier', 'grades'));
|
|
|
45 |
$mapfromoptions = array();
|
|
|
46 |
|
|
|
47 |
if ($header) {
|
|
|
48 |
foreach ($header as $i => $h) {
|
|
|
49 |
$mapfromoptions[$i] = s($h);
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
$mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
|
|
|
53 |
$mform->addHelpButton('mapfrom', 'mapfrom', 'grades');
|
|
|
54 |
|
|
|
55 |
$maptooptions = array(
|
|
|
56 |
'userid' => get_string('userid', 'grades'),
|
|
|
57 |
'username' => get_string('username'),
|
|
|
58 |
'useridnumber' => get_string('idnumber'),
|
|
|
59 |
'useremail' => get_string('email'),
|
|
|
60 |
'0' => get_string('ignore', 'grades')
|
|
|
61 |
);
|
|
|
62 |
$mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
|
|
|
63 |
$mform->addHelpButton('mapto', 'mapto', 'grades');
|
|
|
64 |
|
|
|
65 |
$mform->addElement('header', 'general_map', get_string('mappings', 'grades'));
|
|
|
66 |
$mform->addHelpButton('general_map', 'mappings', 'grades');
|
|
|
67 |
|
|
|
68 |
// Add a feedback option.
|
|
|
69 |
$feedbacks = array();
|
|
|
70 |
if ($gradeitems = $this->_customdata['gradeitems']) {
|
|
|
71 |
foreach ($gradeitems as $itemid => $itemname) {
|
|
|
72 |
$feedbacks['feedback_'.$itemid] = get_string('feedbackforgradeitems', 'grades', $itemname);
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
if ($header) {
|
|
|
77 |
$i = 0;
|
|
|
78 |
foreach ($header as $h) {
|
|
|
79 |
$h = trim($h);
|
|
|
80 |
// This is what each header maps to.
|
|
|
81 |
$headermapsto = array(
|
|
|
82 |
get_string('others', 'grades') => array(
|
|
|
83 |
'0' => get_string('ignore', 'grades'),
|
|
|
84 |
'new' => get_string('newitem', 'grades')
|
|
|
85 |
),
|
|
|
86 |
get_string('gradeitems', 'grades') => $gradeitems,
|
|
|
87 |
get_string('feedbacks', 'grades') => $feedbacks
|
|
|
88 |
);
|
|
|
89 |
$mform->addElement('selectgroups', 'mapping_'.$i, s($h), $headermapsto);
|
|
|
90 |
$i++;
|
|
|
91 |
}
|
|
|
92 |
}
|
|
|
93 |
// Course id needs to be passed for auth purposes.
|
|
|
94 |
$mform->addElement('hidden', 'map', 1);
|
|
|
95 |
$mform->setType('map', PARAM_INT);
|
|
|
96 |
$mform->setConstant('map', 1);
|
|
|
97 |
$mform->addElement('hidden', 'id', $this->_customdata['id']);
|
|
|
98 |
$mform->setType('id', PARAM_INT);
|
|
|
99 |
$mform->setConstant('id', $this->_customdata['id']);
|
|
|
100 |
$mform->addElement('hidden', 'iid', $this->_customdata['iid']);
|
|
|
101 |
$mform->setType('iid', PARAM_INT);
|
|
|
102 |
$mform->setConstant('iid', $this->_customdata['iid']);
|
|
|
103 |
$mform->addElement('hidden', 'importcode', $this->_customdata['importcode']);
|
|
|
104 |
$mform->setType('importcode', PARAM_FILE);
|
|
|
105 |
$mform->setConstant('importcode', $this->_customdata['importcode']);
|
|
|
106 |
$mform->addElement('hidden', 'verbosescales', 1);
|
|
|
107 |
$mform->setType('verbosescales', PARAM_INT);
|
|
|
108 |
$mform->setConstant('verbosescales', $this->_customdata['importcode']);
|
|
|
109 |
$mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
|
|
|
110 |
$mform->setType('groupid', PARAM_INT);
|
|
|
111 |
$mform->setConstant('groupid', groups_get_course_group($COURSE));
|
|
|
112 |
$mform->addElement('hidden', 'forceimport', $this->_customdata['forceimport']);
|
|
|
113 |
$mform->setType('forceimport', PARAM_BOOL);
|
|
|
114 |
$mform->setConstant('forceimport', $this->_customdata['forceimport']);
|
|
|
115 |
$this->add_sticky_action_buttons(false, get_string('uploadgrades', 'grades'));
|
|
|
116 |
}
|
|
|
117 |
}
|