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 tool config variables.
19
 *
20
 * File         CONFIG.php
21
 * Encoding     UTF-8
22
 * @copyright   Sebsoft.nl
23
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 */
25
 
26
namespace tool_usersuspension;
27
 
28
/**
29
 * tool_usersuspension\config
30
 *
31
 * @package     tool_usersuspension
32
 *
33
 * @copyright   Sebsoft.nl
34
 * @author      R.J. van Dongen <rogier@sebsoft.nl>
35
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
36
 */
37
class config {
38
 
39
    /**
40
     *
41
     * @var whether or not config has been loaded yet
42
     */
43
    private static $loaded = false;
44
 
45
    /**
46
     *
47
     * @var \stdClass the tool configuration
48
     */
49
    private static $config = null;
50
 
51
    /**
52
     * initialize the tool configuration
53
     */
54
    private static function init() {
55
        if (!self::$loaded) {
56
            self::$config = get_config('tool_usersuspension');
57
        }
58
    }
59
 
60
    /**
61
     * get a configuration value
62
     *
63
     * @param string $name config name
64
     * @return mixed
65
     */
66
    public static function get($name) {
67
        self::init();
68
        if (isset(self::$config->{$name})) {
69
            return self::$config->{$name};
70
        }
71
        return null;
72
    }
73
 
74
    /**
75
     * set a configuration value
76
     *
77
     * @param string $name config name
78
     * @param mixed $value config value
79
     * @param bool $force force insert if this value does not exist
80
     * @return mixed
81
     */
82
    public static function set($name, $value, $force = true) {
83
        self::init();
84
        if (isset(self::$config->$name) || $force) {
85
            self::$config->$name = $value;
86
            set_config($name, $value, 'tool_usersuspension');
87
        }
88
        return self::$config->$name;
89
    }
90
 
91
    /**
92
     * invalidates the cached configuration and reloads from database
93
     */
94
    public static function invalidate() {
95
        self::$loaded = false;
96
        self::$config = null;
97
        self::init();
98
    }
99
 
100
}