Welcome to mirror list, hosted at ThFree Co, Russian Federation.

SystemConfigSetting.php « Plugin « Settings « core - github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1f7953542c7347b3e74de36bb1a15c7a66652082 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/**
 * Piwik - free/libre analytics platform
 *
 * @link https://matomo.org
 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
 *
 */

namespace Piwik\Settings\Plugin;

use Piwik\Config;
use Piwik\Container\StaticContainer;
use Piwik\Piwik;
use Piwik\Settings\Setting;
use Piwik\Settings\Storage;

/**
 * Describes a system wide setting. Only the Super User can change this type of setting by d efault and
 * the value of this setting will affect all users.
 *
 * See {@link \Piwik\Settings\Setting}.
 *
 * @api
 */
class SystemConfigSetting extends Setting
{
    protected $configSection = null;
    /**
     * Constructor.
     *
     * @param string $name The setting's persisted name.
     * @param mixed $defaultValue  Default value for this setting if no value was specified.
     * @param string $type Eg an array, int, ... see TYPE_* constants
     * @param string $pluginName The name of the plugin the system setting belongs to.
     */
    public function __construct($name, $defaultValue, $type, $pluginName, $configSectionName)
    {
        parent::__construct($name, $defaultValue, $type, $pluginName);

        $factory = StaticContainer::get('Piwik\Settings\Storage\Factory');
        $this->configSection = $configSectionName;
        $this->storage = $factory->getConfigStorage($configSectionName);
    }

    /**
     * Returns `true` if this setting is writable for the current user, `false` if otherwise. In case it returns
     * writable for the current user it will be visible in the Plugin settings UI.
     *
     * @return bool
     */
    public function isWritableByCurrentUser()
    {
        if (isset($this->hasWritePermission)) {
            return $this->hasWritePermission;
        }

        // performance improvement, do not detect this in __construct otherwise likely rather "big" query to DB.
        $this->hasWritePermission = Piwik::hasUserSuperUserAccess();

        return $this->hasWritePermission;
    }

    /**
     * Returns the config section the setting is for
     *
     * @return string
     */
    public function getConfigSectionName()
    {
        return $this->configSection;
    }
}