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 generic moodleform bridge for the backup user interface
19
 * as well as the individual forms that relate to the different stages the user
20
 * interface can exist within.
21
 *
22
 * @package   core_backup
23
 * @copyright 2010 Sam Hemelryk
24
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
/**
30
 * Backup moodleform bridge
31
 *
32
 * Ahhh the mighty moodleform bridge! Strong enough to take the weight of 682 full
33
 * grown african swallows all of whom have been carring coconuts for several days.
34
 * EWWWWW!!!!!!!!!!!!!!!!!!!!!!!!
35
 *
36
 * @package core_backup
37
 * @copyright 2010 Sam Hemelryk
38
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
39
 */
40
abstract class backup_moodleform extends base_moodleform {
41
    /**
42
     * Creates the form
43
     *
44
     * Overridden for type hinting on the first arg.
45
     *
46
     * @param backup_ui_stage $uistage
47
     * @param moodle_url|string $action
48
     * @param mixed $customdata
49
     * @param string $method get|post
50
     * @param string $target
51
     * @param array $attributes
52
     * @param bool $editable
53
     */
54
    public function __construct(backup_ui_stage $uistage, $action = null, $customdata = null, $method = 'post',
55
                                $target = '', $attributes = null, $editable = true) {
56
        parent::__construct($uistage, $action, $customdata, $method, $target, $attributes, $editable);
57
    }
58
}
59
 
60
/**
61
 * Initial backup user interface stage moodleform.
62
 *
63
 * Nothing to override we only need it defined so that moodleform doesn't get confused
64
 * between stages.
65
 *
66
 * @package   core_backup
67
 * @copyright 2010 Sam Hemelryk
68
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
69
 */
70
class backup_initial_form extends backup_moodleform {}
71
 
72
/**
73
 * Schema backup user interface stage moodleform.
74
 *
75
 * Nothing to override we only need it defined so that moodleform doesn't get confused
76
 * between stages.
77
 *
78
 * @package   core_backup
79
 * @copyright 2010 Sam Hemelryk
80
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
81
 */
82
class backup_schema_form extends backup_moodleform {}
83
 
84
/**
85
 * Confirmation backup user interface stage moodleform.
86
 *
87
 * Nothing to override we only need it defined so that moodleform doesn't get confused
88
 * between stages.
89
 *
90
 * @package   core_backup
91
 * @copyright 2010 Sam Hemelryk
92
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
93
 */
94
class backup_confirmation_form extends backup_moodleform {
95
 
96
    /**
97
     * Adds the last elements, rules, settings etc to the form after data has been set.
98
     *
99
     * We override this to add a rule and type to the filename setting.
100
     *
101
     * @throws coding_exception
102
     */
103
    public function definition_after_data() {
104
        parent::definition_after_data();
105
        $this->_form->addRule('setting_root_filename', get_string('errorfilenamerequired', 'backup'), 'required');
106
        $this->_form->setType('setting_root_filename', PARAM_FILE);
107
    }
108
 
109
    /**
110
     * Validates the form.
111
     *
112
     * Relies on the parent::validation for the bulk of the work.
113
     *
114
     * @param array $data
115
     * @param array $files
116
     * @return array
117
     * @throws coding_exception
118
     */
119
    public function validation($data, $files) {
120
        $errors = parent::validation($data, $files);
121
 
122
        if (!array_key_exists('setting_root_filename', $errors)) {
123
            if (trim($data['setting_root_filename']) == '') {
124
                $errors['setting_root_filename'] = get_string('errorfilenamerequired', 'backup');
125
            } else if (strlen(trim($data['setting_root_filename'])) > 255) {
126
                $errors['setting_root_filename'] = get_string('errorfilenametoolong', 'backup');
127
            } else if (!preg_match('#\.mbz$#i', $data['setting_root_filename'])) {
128
                $errors['setting_root_filename'] = get_string('errorfilenamemustbezip', 'backup');
129
            }
130
        }
131
 
132
        return $errors;
133
    }
134
}