Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 1
<?php
2
// This file is part of the customcert module for 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
 * This file contains the class that handles uploading files.
19
 *
20
 * @package    mod_customcert
21
 * @copyright  2013 Mark Nelson <markn@moodle.com>
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace mod_customcert;
26
 
27
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
28
 
29
require_once($CFG->libdir.'/formslib.php');
30
 
31
/**
32
 * Handles uploading files.
33
 *
34
 * @package    mod_customcert
35
 * @copyright  2013 Mark Nelson <markn@moodle.com>
36
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class upload_image_form extends \moodleform {
39
 
40
    /** @var array the filemanager options */
41
    protected $filemanageroptions = [];
42
 
43
    /**
44
     * Form definition.
45
     */
46
    public function definition() {
47
        global $CFG;
48
 
49
        $mform = $this->_form;
50
        $this->filemanageroptions = [
51
            'maxbytes' => $CFG->maxbytes,
52
            'subdirs' => 1,
53
            'accepted_types' => 'image'];
54
        $mform->addElement('filemanager', 'customcertimage', get_string('uploadimage', 'customcert'), '',
55
            $this->filemanageroptions);
56
 
57
        $this->add_action_buttons();
58
    }
59
 
60
    /**
61
     * Fill in the current page data for this customcert.
62
     */
63
    public function definition_after_data() {
64
        $mform = $this->_form;
65
 
66
        // Editing existing instance - copy existing files into draft area.
67
        $draftitemid = file_get_submitted_draft_itemid('customcertimage');
68
        file_prepare_draft_area($draftitemid, \context_system::instance()->id, 'mod_customcert', 'image', 0,
69
            $this->filemanageroptions);
70
        $element = $mform->getElement('customcertimage');
71
        $element->setValue($draftitemid);
72
    }
73
}