PageRenderTime 65ms CodeModel.GetById 31ms RepoModel.GetById 1ms app.codeStats 0ms

/moodle/grade/import/grade_import_form.php

https://bitbucket.org/geek745/moodle-db2
PHP | 135 lines | 90 code | 22 blank | 23 comment | 7 complexity | 1e3c843e24a193bb2184a96f5d46731c MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, BSD-3-Clause, LGPL-2.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. class grade_import_form extends moodleform {
  19. function definition (){
  20. global $COURSE;
  21. $mform =& $this->_form;
  22. if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
  23. $features = $this->_customdata;
  24. } else {
  25. $features = array();
  26. }
  27. // course id needs to be passed for auth purposes
  28. $mform->addElement('hidden', 'id', optional_param('id'));
  29. $mform->setType('id', PARAM_INT);
  30. $mform->addElement('header', 'general', get_string('importfile', 'grades'));
  31. // file upload
  32. $mform->addElement('file', 'userfile', get_string('file'));
  33. $mform->setType('userfile', PARAM_FILE);
  34. $mform->addRule('userfile', null, 'required');
  35. $textlib = textlib_get_instance();
  36. $encodings = $textlib->get_encodings();
  37. $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
  38. if (!empty($features['includeseparator'])) {
  39. $radio = array();
  40. $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
  41. $radio[] = &MoodleQuickForm::createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
  42. $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
  43. $mform->setDefault('separator', 'comma');
  44. }
  45. if (!empty($features['verbosescales'])) {
  46. $options = array(1=>get_string('yes'), 0=>get_string('no'));
  47. $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
  48. }
  49. $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
  50. $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options); // TODO: localize
  51. $mform->setType('previewrows', PARAM_INT);
  52. $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
  53. $mform->setType('groupid', PARAM_INT);
  54. $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
  55. }
  56. }
  57. class grade_import_mapping_form extends moodleform {
  58. function definition () {
  59. global $CFG, $COURSE;
  60. $mform =& $this->_form;
  61. // this is an array of headers
  62. $header = $this->_customdata['header'];
  63. // course id
  64. $mform->addElement('header', 'general', get_string('identifier', 'grades'));
  65. $mapfromoptions = array();
  66. if ($header) {
  67. foreach ($header as $i=>$h) {
  68. $mapfromoptions[$i] = s($h);
  69. }
  70. }
  71. $mform->addElement('select', 'mapfrom', get_string('mapfrom', 'grades'), $mapfromoptions);
  72. //choose_from_menu($mapfromoptions, 'mapfrom');
  73. $maptooptions = array('userid'=>'userid', 'username'=>'username', 'useridnumber'=>'useridnumber', 'useremail'=>'useremail', '0'=>'ignore');
  74. //choose_from_menu($maptooptions, 'mapto');
  75. $mform->addElement('select', 'mapto', get_string('mapto', 'grades'), $maptooptions);
  76. $mform->addElement('header', 'general', get_string('mappings', 'grades'));
  77. // add a comment option
  78. if ($gradeitems = $this->_customdata['gradeitems']) {
  79. $comments = array();
  80. foreach ($gradeitems as $itemid => $itemname) {
  81. $comments['feedback_'.$itemid] = 'comments for '.$itemname;
  82. }
  83. }
  84. if ($header) {
  85. $i = 0; // index
  86. foreach ($header as $h) {
  87. $h = trim($h);
  88. // this is what each header maps to
  89. $mform->addElement('selectgroups',
  90. 'mapping_'.$i, s($h),
  91. array('others'=>array('0'=>'ignore', 'new'=>'new gradeitem'),
  92. 'gradeitems'=>$gradeitems,
  93. 'comments'=>$comments));
  94. $i++;
  95. }
  96. }
  97. // course id needs to be passed for auth purposes
  98. $mform->addElement('hidden', 'map', 1);
  99. $mform->setType('map', PARAM_INT);
  100. $mform->addElement('hidden', 'id');
  101. $mform->setType('id', PARAM_INT);
  102. $mform->addElement('hidden', 'importcode');
  103. $mform->setType('importcode', PARAM_FILE);
  104. $mform->addElement('hidden', 'verbosescales', 1);
  105. $mform->setType('separator', PARAM_ALPHA);
  106. $mform->addElement('hidden', 'separator', 'comma');
  107. $mform->setType('verbosescales', PARAM_INT);
  108. $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
  109. $mform->setType('groupid', PARAM_INT);
  110. $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
  111. }
  112. }
  113. ?>