Issues (59)

classes/edulegit_config.php (1 issue)

Labels
Severity
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
 * The assignsubmission_edulegit config class.
19
 *
20
 * This class handles the configuration settings for the assignsubmission_edulegit plugin.
21
 *
22
 * @package   assignsubmission_edulegit
23
 * @author    Alex Crosby <[email protected]>
24
 * @copyright @2024 EduLegit.com
25
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26
 */
27
28
namespace assignsubmission_edulegit;
29
30
/**
31
 * Class edulegit_config
32
 *
33
 * Manages configuration for the assignsubmission_edulegit plugin.
34
 */
35
class edulegit_config {
36
37
    /**
38
     * Stores the plugin-specific configuration.
39
     *
40
     * @var \stdClass|null
41
     */
42
    private ?\stdClass $config = null;
43
44
    /**
45
     * Initializes the config class with a specific configuration object.
46
     *
47
     * @param \stdClass $config The configuration object for the plugin.
48
     */
49
    public function __construct(\stdClass $config) {
50
        $this->config = $config;
51
    }
52
53
    /**
54
     * Retrieves a specific config value by name.
55
     *
56
     * @param string $name The name of the configuration setting.
57
     * @param mixed $default The default value if the config setting is not found.
58
     * @return mixed The configuration value or the default if not found.
59
     */
60
    public function get($name, $default = null) {
61
        $value = $this->config->{$name} ?? false;
62
        return $value !== false ? $value : $default;
63
    }
64
65
    /**
66
     * Retrieves a global configuration value.
67
     *
68
     * @param string $name The name of the global configuration setting.
69
     * @param mixed $default The default value if the global config setting is not found.
70
     * @return mixed The global configuration value or the default if not found.
71
     */
72
    public function get_global($name, $default = null) {
73
        $value = get_config('assignsubmission_edulegit', $name);
0 ignored issues
show
The function get_config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $value = /** @scrutinizer ignore-call */ get_config('assignsubmission_edulegit', $name);
Loading history...
74
        return $value !== false ? $value : $default;
75
    }
76
77
    /**
78
     * Retrieves a configuration value from either the plugin or global config.
79
     *
80
     * First attempts to retrieve a configuration setting from the plugin's config.
81
     * If not found, it defaults to the global Moodle configuration.
82
     *
83
     * @param string $name The name of the configuration setting.
84
     * @param mixed $default The default value if neither the plugin nor global config contains the setting.
85
     * @return mixed The configuration value or the default if not found.
86
     */
87
    public function get_plugin_or_global_config($name, $default = null) {
88
        return $this->get($name, $this->get_global($name, $default));
89
    }
90
91
    /**
92
     * Retrieves the Moodle release version.
93
     *
94
     * @return string|null The Moodle version or release, or null if not found.
95
     * @global object $CFG The global Moodle configuration object.
96
     */
97
    public function get_release() {
98
        global $CFG;
99
        if (isset($CFG->version)) {
100
            return $CFG->version;
101
        }
102
        if (isset($CFG->release)) {
103
            return $CFG->release;
104
        }
105
        return null;
106
    }
107
108
    /**
109
     * Retrieves the plugin's release version.
110
     *
111
     * @return mixed The plugin's version, or null if not found.
112
     */
113
    public function get_plugin_release() {
114
        return $this->get_global('version');
115
    }
116
117
}
118