MDL-67999 core_contentbank: Add namespace to upload form
[moodle.git] / contentbank / classes / form / upload_files.php
CommitLineData
33b8ca26
AA
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
9c070644 17namespace core_contentbank\form;
33b8ca26
AA
18
19/**
9c070644 20 * Upload files to content bank form
33b8ca26
AA
21 *
22 * @package core_contentbank
23 * @copyright 2020 Amaia Anabitarte <amaia@moodle.com>
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
9c070644 26class upload_files extends \moodleform {
33b8ca26
AA
27
28 /**
29 * Add elements to this form.
30 */
31 public function definition() {
32 $mform = $this->_form;
33
34 $mform->addElement('hidden', 'contextid', $this->_customdata['contextid']);
35 $mform->setType('contextid', PARAM_INT);
36
c5a8469a
FR
37 if (!empty($this->_customdata['id'])) {
38 $mform->addElement('hidden', 'id', $this->_customdata['id']);
39 $mform->setType('id', PARAM_INT);
40 }
41
33b8ca26
AA
42 $options = $this->_customdata['options'];
43 $mform->addElement('filepicker', 'file', get_string('file', 'core_contentbank'), null, $options);
44 $mform->addHelpButton('file', 'file', 'core_contentbank');
45 $mform->addRule('file', null, 'required');
46
47 $this->add_action_buttons(true, get_string('savechanges'));
48
49 $data = $this->_customdata['data'];
50 $this->set_data($data);
51 }
52
53 /**
54 * Validate incoming data.
55 *
56 * @param array $data
57 * @param array $files
58 * @return array
59 */
60 public function validation($data, $files) {
61 $errors = array();
62 $draftitemid = $data['file'];
63 if (file_is_draft_area_limit_reached($draftitemid, $this->_customdata['options']['areamaxbytes'])) {
64 $errors['file'] = get_string('userquotalimit', 'error');
65 }
66 return $errors;
67 }
68}