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
namespace core_external;
18
 
19
/**
20
 * A pre-filled external_value class for text format.
21
 *
22
 * Default is FORMAT_HTML
23
 * This should be used all the time in external xxx_params()/xxx_returns functions
24
 * as it is the standard way to implement text format param/return values.
25
 *
26
 * @package    core_webservice
27
 * @copyright  2012 Jerome Mouneyrac
28
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
29
 * @since Moodle 2.3
30
 */
31
class external_format_value extends external_value {
32
 
33
    /**
34
     * Constructor
35
     *
36
     * @param string $textfieldname Name of the text field
37
     * @param int $required if VALUE_REQUIRED then set standard default FORMAT_HTML
38
     * @param int $default Default value.
39
     */
40
    public function __construct($textfieldname, $required = VALUE_REQUIRED, $default = null) {
41
        // Make sure the default format's value is correct.
42
        if ($default !== null && !in_array($default, [FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, FORMAT_MARKDOWN])) {
43
            debugging("Invalid default format for $textfieldname: $default. " .
44
                      "It must be either FORMAT_MOODLE, FORMAT_HTML, FORMAT_PLAIN, or FORMAT_MARKDOWN.", DEBUG_DEVELOPER);
45
            $default = null;
46
        }
47
 
48
        if ($default == null && $required == VALUE_DEFAULT) {
49
            $default = FORMAT_HTML;
50
        }
51
 
52
        $desc = sprintf(
53
            "%s format (%s = HTML, %s = MOODLE, %s = PLAIN, or %s = MARKDOWN)",
54
            $textfieldname,
55
            FORMAT_HTML,
56
            FORMAT_MOODLE,
57
            FORMAT_PLAIN,
58
            FORMAT_MARKDOWN,
59
        );
60
 
61
        parent::__construct(PARAM_INT, $desc, $required, $default);
62
    }
63
}