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\administration_helper;
20
use core_cache\store;
21
use html_writer;
22
use moodleform;
23
 
24
/**
25
 * Form to set definition mappings
26
 *
27
 * @package    core_cache
28
 * @category   cache
29
 * @copyright  2012 Sam Hemelryk
30
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31
 */
32
class cache_definition_mappings_form extends moodleform {
33
    /**
34
     * The definition of the form
35
     */
36
    final protected function definition() {
37
        global $OUTPUT;
38
 
39
        $definition = $this->_customdata['definition'];
40
        $form = $this->_form;
41
 
42
        [$component, $area] = explode('/', $definition, 2);
43
        [$currentstores, $storeoptions, $defaults] =
44
                administration_helper::get_definition_store_options($component, $area);
45
 
46
        $storedata = administration_helper::get_definition_summaries();
47
        if ($storedata[$definition]['mode'] != store::MODE_REQUEST) {
48
            if (isset($storedata[$definition]['canuselocalstore']) && $storedata[$definition]['canuselocalstore']) {
49
                $form->addElement('html', $OUTPUT->notification(get_string('localstorenotification', 'cache'), 'notifymessage'));
50
            } else {
51
                $form->addElement('html', $OUTPUT->notification(get_string('sharedstorenotification', 'cache'), 'notifymessage'));
52
            }
53
        }
54
        $form->addElement('hidden', 'definition', $definition);
55
        $form->setType('definition', PARAM_SAFEPATH);
56
        $form->addElement('hidden', 'action', 'editdefinitionmapping');
57
        $form->setType('action', PARAM_ALPHA);
58
 
59
        $requiredoptions = max(3, count($currentstores) + 1);
60
        $requiredoptions = min($requiredoptions, count($storeoptions));
61
 
62
        $options = ['' => get_string('none')];
63
        foreach ($storeoptions as $option => $def) {
64
            $options[$option] = $option;
65
            if ($def['default']) {
66
                $options[$option] .= ' ' . get_string('mappingdefault', 'cache');
67
            }
68
        }
69
 
70
        for ($i = 0; $i < $requiredoptions; $i++) {
71
            $title = '...';
72
            if ($i === 0) {
73
                $title = get_string('mappingprimary', 'cache');
74
            } else if ($i === $requiredoptions - 1) {
75
                $title = get_string('mappingfinal', 'cache');
76
            }
77
            $form->addElement('select', 'mappings[' . $i . ']', $title, $options);
78
        }
79
        $i = 0;
80
        foreach ($currentstores as $store => $def) {
81
            $form->setDefault('mappings[' . $i . ']', $store);
82
            $i++;
83
        }
84
 
85
        if (!empty($defaults)) {
86
            $form->addElement(
87
                'static',
88
                'defaults',
89
                get_string('defaultmappings', 'cache'),
90
                html_writer::tag('strong', join(', ', $defaults))
91
            );
92
            $form->addHelpButton('defaults', 'defaultmappings', 'cache');
93
        }
94
 
95
        $this->add_action_buttons();
96
    }
97
}
98
 
99
// Alias this class to the old name.
100
// This file will be autoloaded by the legacyclasses autoload system.
101
// In future all uses of this class will be corrected and the legacy references will be removed.
102
class_alias(cache_definition_mappings_form::class, \cache_definition_mappings_form::class);