PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/grade/export/grade_export_form.php

https://bitbucket.org/synergylearning/campusconnect
PHP | 162 lines | 104 code | 26 blank | 32 comment | 15 complexity | f13d4e73afd4f24ec5c46a960728aab7 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, LGPL-3.0, GPL-3.0, LGPL-2.1, Apache-2.0, BSD-3-Clause, AGPL-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. if (!defined('MOODLE_INTERNAL')) {
  17. die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
  18. }
  19. require_once $CFG->libdir.'/formslib.php';
  20. class grade_export_form extends moodleform {
  21. function definition() {
  22. global $CFG, $COURSE, $USER, $DB;
  23. $mform =& $this->_form;
  24. if (isset($this->_customdata)) { // hardcoding plugin names here is hacky
  25. $features = $this->_customdata;
  26. } else {
  27. $features = array();
  28. }
  29. $mform->addElement('header', 'options', get_string('options', 'grades'));
  30. $mform->addElement('advcheckbox', 'export_feedback', get_string('exportfeedback', 'grades'));
  31. $mform->setDefault('export_feedback', 0);
  32. $coursecontext = context_course::instance($COURSE->id);
  33. if (has_capability('moodle/course:viewsuspendedusers', $coursecontext)) {
  34. $mform->addElement('advcheckbox', 'export_onlyactive', get_string('exportonlyactive', 'grades'));
  35. $mform->setType('export_onlyactive', PARAM_BOOL);
  36. $mform->setDefault('export_onlyactive', 1);
  37. $mform->addHelpButton('export_onlyactive', 'exportonlyactive', 'grades');
  38. } else {
  39. $mform->addElement('hidden', 'export_onlyactive', 1);
  40. $mform->setType('export_onlyactive', PARAM_BOOL);
  41. $mform->setConstant('export_onlyactive', 1);
  42. }
  43. $options = array('10'=>10, '20'=>20, '100'=>100, '1000'=>1000, '100000'=>100000);
  44. $mform->addElement('select', 'previewrows', get_string('previewrows', 'grades'), $options);
  45. if (!empty($features['updategradesonly'])) {
  46. $mform->addElement('advcheckbox', 'updatedgradesonly', get_string('updatedgradesonly', 'grades'));
  47. }
  48. /// selections for decimal points and format, MDL-11667, defaults to site settings, if set
  49. //$default_gradedisplaytype = $CFG->grade_export_displaytype;
  50. $options = array(GRADE_DISPLAY_TYPE_REAL => get_string('real', 'grades'),
  51. GRADE_DISPLAY_TYPE_PERCENTAGE => get_string('percentage', 'grades'),
  52. GRADE_DISPLAY_TYPE_LETTER => get_string('letter', 'grades'));
  53. /*
  54. foreach ($options as $key=>$option) {
  55. if ($key == $default_gradedisplaytype) {
  56. $options[GRADE_DISPLAY_TYPE_DEFAULT] = get_string('defaultprev', 'grades', $option);
  57. break;
  58. }
  59. }
  60. */
  61. $mform->addElement('select', 'display', get_string('gradeexportdisplaytype', 'grades'), $options);
  62. $mform->setDefault('display', $CFG->grade_export_displaytype);
  63. //$default_gradedecimals = $CFG->grade_export_decimalpoints;
  64. $options = array(0=>0, 1=>1, 2=>2, 3=>3, 4=>4, 5=>5);
  65. $mform->addElement('select', 'decimals', get_string('gradeexportdecimalpoints', 'grades'), $options);
  66. $mform->setDefault('decimals', $CFG->grade_export_decimalpoints);
  67. $mform->disabledIf('decimals', 'display', 'eq', GRADE_DISPLAY_TYPE_LETTER);
  68. /*
  69. if ($default_gradedisplaytype == GRADE_DISPLAY_TYPE_LETTER) {
  70. $mform->disabledIf('decimals', 'display', "eq", GRADE_DISPLAY_TYPE_DEFAULT);
  71. }
  72. */
  73. if (!empty($features['includeseparator'])) {
  74. $radio = array();
  75. $radio[] = $mform->createElement('radio', 'separator', null, get_string('septab', 'grades'), 'tab');
  76. $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcomma', 'grades'), 'comma');
  77. $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepcolon', 'grades'), 'colon');
  78. $radio[] = $mform->createElement('radio', 'separator', null, get_string('sepsemicolon', 'grades'), 'semicolon');
  79. $mform->addGroup($radio, 'separator', get_string('separator', 'grades'), ' ', false);
  80. $mform->setDefault('separator', 'comma');
  81. }
  82. if (!empty($CFG->gradepublishing) and !empty($features['publishing'])) {
  83. $mform->addElement('header', 'publishing', get_string('publishing', 'grades'));
  84. $options = array(get_string('nopublish', 'grades'), get_string('createnewkey', 'userkey'));
  85. $keys = $DB->get_records_select('user_private_key', "script='grade/export' AND instance=? AND userid=?",
  86. array($COURSE->id, $USER->id));
  87. if ($keys) {
  88. foreach ($keys as $key) {
  89. $options[$key->value] = $key->value; // TODO: add more details - ip restriction, valid until ??
  90. }
  91. }
  92. $mform->addElement('select', 'key', get_string('userkey', 'userkey'), $options);
  93. $mform->addHelpButton('key', 'userkey', 'userkey');
  94. $mform->addElement('static', 'keymanagerlink', get_string('keymanager', 'userkey'),
  95. '<a href="'.$CFG->wwwroot.'/grade/export/keymanager.php?id='.$COURSE->id.'">'.get_string('keymanager', 'userkey').'</a>');
  96. $mform->addElement('text', 'iprestriction', get_string('keyiprestriction', 'userkey'), array('size'=>80));
  97. $mform->addHelpButton('iprestriction', 'keyiprestriction', 'userkey');
  98. $mform->setDefault('iprestriction', getremoteaddr()); // own IP - just in case somebody does not know what user key is
  99. $mform->setType('iprestriction', PARAM_RAW_TRIMMED);
  100. $mform->addElement('date_time_selector', 'validuntil', get_string('keyvaliduntil', 'userkey'), array('optional'=>true));
  101. $mform->addHelpButton('validuntil', 'keyvaliduntil', 'userkey');
  102. $mform->setDefault('validuntil', time()+3600*24*7); // only 1 week default duration - just in case somebody does not know what user key is
  103. $mform->setType('validuntil', PARAM_INT);
  104. $mform->disabledIf('iprestriction', 'key', 'noteq', 1);
  105. $mform->disabledIf('validuntil', 'key', 'noteq', 1);
  106. }
  107. $mform->addElement('header', 'gradeitems', get_string('gradeitemsinc', 'grades'));
  108. $switch = grade_get_setting($COURSE->id, 'aggregationposition', $CFG->grade_aggregationposition);
  109. // Grab the grade_seq for this course
  110. $gseq = new grade_seq($COURSE->id, $switch);
  111. if ($grade_items = $gseq->items) {
  112. $needs_multiselect = false;
  113. $canviewhidden = has_capability('moodle/grade:viewhidden', context_course::instance($COURSE->id));
  114. foreach ($grade_items as $grade_item) {
  115. // Is the grade_item hidden? If so, can the user see hidden grade_items?
  116. if ($grade_item->is_hidden() && !$canviewhidden) {
  117. continue;
  118. }
  119. if (!empty($features['idnumberrequired']) and empty($grade_item->idnumber)) {
  120. $mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), get_string('noidnumber', 'grades'));
  121. $mform->hardFreeze('itemids['.$grade_item->id.']');
  122. } else {
  123. $mform->addElement('advcheckbox', 'itemids['.$grade_item->id.']', $grade_item->get_name(), null, array('group' => 1));
  124. $mform->setDefault('itemids['.$grade_item->id.']', 1);
  125. $needs_multiselect = true;
  126. }
  127. }
  128. if ($needs_multiselect) {
  129. $this->add_checkbox_controller(1, null, null, 1); // 1st argument is group name, 2nd is link text, 3rd is attributes and 4th is original value
  130. }
  131. }
  132. $mform->addElement('hidden', 'id', $COURSE->id);
  133. $mform->setType('id', PARAM_INT);
  134. $this->add_action_buttons(false, get_string('submit'));
  135. }
  136. }