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 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 forms to create and edit an instance of this module
19
 *
20
 * @package mod_imscp
21
 * @copyright  2009 Petr Skoda  {@link http://skodak.org}
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
require_once($CFG->dirroot.'/course/moodleform_mod.php');
28
require_once($CFG->libdir.'/filelib.php');
29
 
30
/**
31
 * IMS CP configuration form
32
 *
33
 * @package mod_imscp
34
 * @copyright  2009 Petr Skoda  {@link http://skodak.org}
35
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class mod_imscp_mod_form extends moodleform_mod {
38
    /**
39
     * Define the form - called by parent constructor
40
     */
41
    public function definition() {
42
        global $CFG, $DB;
43
        $mform = $this->_form;
44
 
45
        $config = get_config('imscp');
46
 
47
        // Title and description.
48
        $mform->addElement('header', 'general', get_string('general', 'form'));
49
        $mform->addElement('text', 'name', get_string('name'), array('size' => '48'));
50
        if (!empty($CFG->formatstringstriptags)) {
51
            $mform->setType('name', PARAM_TEXT);
52
        } else {
53
            $mform->setType('name', PARAM_CLEANHTML);
54
        }
55
        $mform->addRule('name', null, 'required', null, 'client');
56
        $mform->addRule('name', get_string('maximumchars', '', 255), 'maxlength', 255, 'client');
57
        $this->standard_intro_elements();
58
 
59
        // IMS-CP file upload.
60
        $mform->addElement('header', 'content', get_string('contentheader', 'imscp'));
61
        $mform->setExpanded('content', true);
62
 
63
        $mform->addElement('filepicker', 'package', get_string('packagefile', 'imscp'), null,
64
            ['accepted_types' => ['application/zip', '.imscc']]);
65
 
66
        $options = array('-1' => get_string('all'), '0' => get_string('no'),
67
                         '1' => '1', '2' => '2', '5' => '5', '10' => '10', '20' => '20');
68
        $mform->addElement('select', 'keepold', get_string('keepold', 'imscp'), $options);
69
        $mform->setDefault('keepold', $config->keepold);
70
        $mform->setAdvanced('keepold', $config->keepold_adv);
71
 
72
        $this->standard_coursemodule_elements();
73
 
74
        $this->add_action_buttons();
75
    }
76
 
77
    /**
78
     * Perform minimal validation on the settings form
79
     * @param array $data
80
     * @param array $files
81
     */
82
    public function validation($data, $files) {
83
        if ($errors = parent::validation($data, $files)) {
84
            return $errors;
85
        }
86
 
87
        if (!$this->get_draft_files('package')) {
88
            if (!$this->current->instance) {
89
                $errors['package'] = get_string('required');
90
                return $errors;
91
            }
92
        }
93
 
94
        return $errors;
95
    }
96
}