PageRenderTime 40ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/grade/import/direct/classes/mapping_form.php

https://bitbucket.org/moodle/moodle
PHP | 117 lines | 77 code | 11 blank | 29 comment | 4 complexity | 2069938e8dcb4c1b8961c8a6c1dd8d8c MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1, BSD-3-Clause, MIT, GPL-3.0
  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. require_once($CFG->libdir.'/formslib.php');
  17. require_once($CFG->libdir.'/gradelib.php');
  18. if (!defined('MOODLE_INTERNAL')) {
  19. die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
  20. }
  21. /**
  22. * Form for mapping columns to the fields in the table.
  23. *
  24. * @package gradeimport_direct
  25. * @copyright 2014 Adrian Greeve <adrian@moodle.com>
  26. * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  27. */
  28. class gradeimport_direct_mapping_form extends moodleform {
  29. /**
  30. * Definition method.
  31. */
  32. public function definition() {
  33. global $CFG, $COURSE;
  34. $mform = $this->_form;
  35. // This is an array of headers.
  36. $header = $this->_customdata['header'];
  37. // Course id.
  38. $mform->addElement('header', 'general', get_string('identifier', 'grades'));
  39. $mapfromoptions = array();
  40. if ($header) {
  41. foreach ($header as $i => $h) {
  42. $mapfromoptions[$i] = s($h);
  43. }
  44. }
  45. $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
  46. $mform->addHelpButton('mapfrom', 'mapfrom', 'grades');
  47. $maptooptions = array(
  48. 'userid' => get_string('userid', 'grades'),
  49. 'username' => get_string('username'),
  50. 'useridnumber' => get_string('idnumber'),
  51. 'useremail' => get_string('email'),
  52. '0' => get_string('ignore', 'grades')
  53. );
  54. $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
  55. $mform->addHelpButton('mapto', 'mapto', 'grades');
  56. $mform->addElement('header', 'general_map', get_string('mappings', 'grades'));
  57. $mform->addHelpButton('general_map', 'mappings', 'grades');
  58. // Add a feedback option.
  59. $feedbacks = array();
  60. if ($gradeitems = $this->_customdata['gradeitems']) {
  61. foreach ($gradeitems as $itemid => $itemname) {
  62. $feedbacks['feedback_'.$itemid] = get_string('feedbackforgradeitems', 'grades', $itemname);
  63. }
  64. }
  65. if ($header) {
  66. $i = 0;
  67. foreach ($header as $h) {
  68. $h = trim($h);
  69. // This is what each header maps to.
  70. $headermapsto = array(
  71. get_string('others', 'grades') => array(
  72. '0' => get_string('ignore', 'grades'),
  73. 'new' => get_string('newitem', 'grades')
  74. ),
  75. get_string('gradeitems', 'grades') => $gradeitems,
  76. get_string('feedbacks', 'grades') => $feedbacks
  77. );
  78. $mform->addElement('selectgroups', 'mapping_'.$i, s($h), $headermapsto);
  79. $i++;
  80. }
  81. }
  82. // Course id needs to be passed for auth purposes.
  83. $mform->addElement('hidden', 'map', 1);
  84. $mform->setType('map', PARAM_INT);
  85. $mform->setConstant('map', 1);
  86. $mform->addElement('hidden', 'id', $this->_customdata['id']);
  87. $mform->setType('id', PARAM_INT);
  88. $mform->setConstant('id', $this->_customdata['id']);
  89. $mform->addElement('hidden', 'iid', $this->_customdata['iid']);
  90. $mform->setType('iid', PARAM_INT);
  91. $mform->setConstant('iid', $this->_customdata['iid']);
  92. $mform->addElement('hidden', 'importcode', $this->_customdata['importcode']);
  93. $mform->setType('importcode', PARAM_FILE);
  94. $mform->setConstant('importcode', $this->_customdata['importcode']);
  95. $mform->addElement('hidden', 'verbosescales', 1);
  96. $mform->setType('verbosescales', PARAM_INT);
  97. $mform->setConstant('verbosescales', $this->_customdata['importcode']);
  98. $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
  99. $mform->setType('groupid', PARAM_INT);
  100. $mform->setConstant('groupid', groups_get_course_group($COURSE));
  101. $mform->addElement('hidden', 'forceimport', $this->_customdata['forceimport']);
  102. $mform->setType('forceimport', PARAM_BOOL);
  103. $mform->setConstant('forceimport', $this->_customdata['forceimport']);
  104. $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
  105. }
  106. }