Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 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
namespace core_cache\form;
18
 
19
use core_cache\config as cache_config;
20
use moodleform;
21
 
22
/**
23
 * Form to add a cache lock instance.
24
 *
25
 * All cache lock plugins that wish to have custom configuration should override
26
 * this form, and more explicitly the plugin_definition and plugin_validation methods.
27
 *
28
 * @package    core_cache
29
 * @category   cache
30
 * @copyright  2013 Sam Hemelryk
31
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class cache_lock_form extends moodleform {
34
    /**
35
     * Defines this form.
36
     */
37
    final public function definition() {
38
        $plugin = $this->_customdata['lock'];
39
 
40
        $this->_form->addElement('hidden', 'action', 'newlockinstance');
41
        $this->_form->setType('action', PARAM_ALPHANUMEXT);
42
        $this->_form->addElement('hidden', 'lock', $plugin);
43
        $this->_form->setType('lock', PARAM_COMPONENT);
44
        $this->_form->addElement('text', 'name', get_string('lockname', 'cache'));
45
        $this->_form->setType('name', PARAM_ALPHANUMEXT);
46
        $this->_form->addRule('name', get_string('required'), 'required');
47
        $this->_form->addElement('static', 'namedesc', '', get_string('locknamedesc', 'cache'));
48
 
49
        $this->plugin_definition();
50
 
51
        $this->add_action_buttons();
52
    }
53
 
54
    /**
55
     * Validates this form.
56
     *
57
     * @param array $data
58
     * @param array $files
59
     * @return array
60
     */
61
    final public function validation($data, $files) {
62
        $errors = parent::validation($data, $files);
63
        if (!isset($errors['name'])) {
64
            $config = cache_config::instance();
65
            if (in_array($data['name'], array_keys($config->get_locks()))) {
66
                $errors['name'] = get_string('locknamenotunique', 'cache');
67
            }
68
        }
69
        $errors = $this->plugin_validation($data, $files, $errors);
70
        return $errors;
71
    }
72
 
73
    /**
74
     * Plugin specific definition.
75
     */
76
    public function plugin_definition() {
77
        // No custom validation going on here.
78
    }
79
 
80
    /**
81
     * Plugin specific validation.
82
     *
83
     * @param array $data
84
     * @param array $files
85
     * @param array $errors
86
     * @return array
87
     */
88
    public function plugin_validation($data, $files, array $errors) {
89
        return $errors;
90
    }
91
}
92
 
93
// Alias this class to the old name.
94
// This file will be autoloaded by the legacyclasses autoload system.
95
// In future all uses of this class will be corrected and the legacy references will be removed.
96
class_alias(cache_lock_form::class, \cache_lock_form::class);