Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 4.0.x will end 8 May 2023 (12 months).
  • Bug fixes for security issues in 4.0.x will end 13 November 2023 (18 months).
  • PHP version: minimum PHP 7.3.0 Note: the minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is also supported.

Differences Between: [Versions 39 and 400] [Versions 400 and 403]

   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  
  19  if (!defined('MOODLE_INTERNAL')) {
  20      die('Direct access to this script is forbidden.');    // It must be included from a Moodle page.
  21  }
  22  
  23  /**
  24   * Form for copying and pasting from a spreadsheet.
  25   *
  26   * @package   gradeimport_direct
  27   * @copyright 2014 Adrian Greeve <adrian@moodle.com>
  28   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  29   */
  30  class gradeimport_direct_import_form extends moodleform {
  31  
  32      /**
  33       * Definition method.
  34       */
  35      public function definition() {
  36          global $COURSE;
  37  
  38          $mform = $this->_form;
  39  
  40          if (isset($this->_customdata)) {  // Hardcoding plugin names here is hacky.
  41              $features = $this->_customdata;
  42          } else {
  43              $features = array();
  44          }
  45  
  46          // Course id needs to be passed for auth purposes.
  47          $mform->addElement('hidden', 'id', optional_param('id', 0, PARAM_INT));
  48          $mform->setType('id', PARAM_INT);
  49  
  50          $mform->addElement('header', 'general', get_string('pluginname', 'gradeimport_direct'));
  51          // Data upload from copy/paste.
  52          $mform->addElement('textarea', 'userdata', get_string('importdata', 'core_grades'),
  53              array('rows' => 10, 'class' => 'gradeimport_data_area'));
  54          $mform->addHelpButton('userdata', 'importdata', 'core_grades');
  55          $mform->addRule('userdata', null, 'required');
  56          $mform->setType('userdata', PARAM_RAW);
  57  
  58          $encodings = core_text::get_encodings();
  59          $mform->addElement('select', 'encoding', get_string('encoding', 'grades'), $encodings);
  60          $mform->addHelpButton('encoding', 'encoding', 'grades');
  61  
  62          if (!empty($features['verbosescales'])) {
  63              $options = array(1 => get_string('yes'), 0 => get_string('no'));
  64              $mform->addElement('select', 'verbosescales', get_string('verbosescales', 'grades'), $options);
  65              $mform->addHelpButton('verbosescales', 'verbosescales', 'grades');
  66          }
  67  
  68          $options = array('10' => 10, '20' => 20, '100' => 100, '1000' => 1000, '100000' => 100000);
  69          $mform->addElement('select', 'previewrows', get_string('rowpreviewnum', 'grades'), $options);
  70          $mform->addHelpButton('previewrows', 'rowpreviewnum', 'grades');
  71          $mform->setType('previewrows', PARAM_INT);
  72          $mform->addElement('hidden', 'groupid', groups_get_course_group($COURSE));
  73          $mform->setType('groupid', PARAM_INT);
  74          $mform->addElement('advcheckbox', 'forceimport', get_string('forceimport', 'grades'));
  75          $mform->addHelpButton('forceimport', 'forceimport', 'grades');
  76          $mform->setDefault('forceimport', false);
  77          $this->add_action_buttons(false, get_string('uploadgrades', 'grades'));
  78      }
  79  }