Overview
Comment:Ajout fonction pour créer un select dans un formulaire
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 982aad197fb454e46096299a3d797cb4a16c7a0e
User & Date: bohwaz on 2017-09-05 02:05:33
Other Links: branch diff | manifest | tags
Context
2017-09-05
02:36
Modernisation / mise en objet des modifieurs et fonctions de template check-in: d2f4ecb4df user: bohwaz tags: dev
02:05
Ajout fonction pour créer un select dans un formulaire check-in: 982aad197f user: bohwaz tags: dev
02:05
Corrections pour installation de plugin check-in: 9d0e5678d2 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Template.php from [a5df5d901f] to [308266e2a2].

35
36
37
38
39
40
41

42
43
44
45
46
47
48
49
50
51

52
53
54
55
56
57
58
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60







+










+







            {
                return 'continue;';
            }
        });

        $this->register_function('form_errors', [$this, 'formErrors']);
        $this->register_function('show_error', [$this, 'showError']);
        $this->register_function('form_select', [$this, 'formSelect']);
        $this->register_function('custom_colors', [$this, 'customColors']);
        $this->register_function('plugin_url', ['Garradin\Utils', 'plugin_url']);
        $this->register_function('csrf_field', function ($params) {
            return Form::tokenHTML($params['key']);
        });

        $this->register_modifier('strlen', 'strlen');
        $this->register_modifier('get_country_name', ['Garradin\Utils', 'getCountryName']);
        $this->register_modifier('format_sqlite_date_to_french', ['Garradin\Utils', 'sqliteDateToFrench']);
        $this->register_modifier('format_bytes', ['Garradin\Utils', 'format_bytes']);

    }

    protected function formErrors($params)
    {
        $form = $this->getTemplateVars('form');

        if (!$form->hasErrors())
68
69
70
71
72
73
74














































75
76
77
78
79
80
81
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        if (!$params['if'])
        {
            return '';
        }

        return '<p class="error">' . $this->escape($params['message']) . '</p>';
    }

    protected function formSelect(array $params)
    {
        if (empty($params['name']))
        {
            throw new \BadFunctionCallException("Paramètre name manquant pour select");
        }

        $name = $params['name'];
        $value = '';

        if (f($name) !== null)
        {
            $value = f($name);
        }
        elseif (isset($params['data']) && is_array($params['data']) && isset($params['data'][$name]))
        {
            $value = $params['data'][$name];
        }
        elseif (isset($params['data']) && is_object($params['data']) && isset($params['data']->$name))
        {
            $value = $params['data']->$name;
        }
        elseif (isset($params['default']))
        {
            $value = $params['default'];
        }

        $out = sprintf('<select name="%s" id="f_%1$s">', $params['name']);

        if (!empty($params['values']))
        {
            foreach ($params['values'] as $v)
            {
                $out .= '<option value="'.htmlspecialchars($v, ENT_QUOTES, 'UTF-8').'"';

                if ($v == $value)
                    $out .= ' selected="selected"';

                $out .= '>'.htmlspecialchars($v, ENT_QUOTES, 'UTF-8').'</option>';
            }
        }

        $out .= '</select>';
        return $out;
    }

    protected function customColors()
    {
        $config = Config::getInstance();

        if (!$config->get('couleur1') || !$config->get('couleur2') || !$config->get('image_fond'))
        {