Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.10.x will end 8 November 2021 (12 months).
  • Bug fixes for security issues in 3.10.x will end 9 May 2022 (18 months).
  • PHP version: minimum PHP 7.2.0 Note: minimum PHP version has increased since Moodle 3.8. PHP 7.3.x and 7.4.x are supported too.
   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  /**
  18   * minimalistic edit form
  19   *
  20   * @package   core_user
  21   * @category  files
  22   * @copyright 2010 Petr Skoda (http://skodak.org)
  23   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  require_once("$CFG->libdir/formslib.php");
  29  
  30  /**
  31   * Class user_files_form
  32   * @copyright 2010 Petr Skoda (http://skodak.org)
  33   * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  34   */
  35  class user_files_form extends moodleform {
  36  
  37      /**
  38       * Add elements to this form.
  39       */
  40      public function definition() {
  41          $mform = $this->_form;
  42  
  43          $data = $this->_customdata['data'];
  44          $options = $this->_customdata['options'];
  45  
  46          $mform->addElement('filemanager', 'files_filemanager', get_string('files'), null, $options);
  47          $mform->addElement('hidden', 'returnurl', $data->returnurl);
  48          if (isset($data->emaillink)) {
  49              $emaillink = html_writer::link(new moodle_url('mailto:' . $data->emaillink), $data->emaillink);
  50              $mform->addElement('static', 'emailaddress', '',
  51                  get_string('emailtoprivatefiles', 'moodle', $emaillink));
  52          }
  53          $mform->setType('returnurl', PARAM_LOCALURL);
  54  
  55          $this->add_action_buttons(true, get_string('savechanges'));
  56  
  57          $this->set_data($data);
  58      }
  59  
  60      /**
  61       * Validate incoming data.
  62       *
  63       * @param array $data
  64       * @param array $files
  65       * @return array
  66       */
  67      public function validation($data, $files) {
  68          $errors = array();
  69          $draftitemid = $data['files_filemanager'];
  70          if (file_is_draft_area_limit_reached($draftitemid, $this->_customdata['options']['areamaxbytes'])) {
  71              $errors['files_filemanager'] = get_string('userquotalimit', 'error');
  72          }
  73  
  74          return $errors;
  75      }
  76  }