diff options
author | Thomas Steur <thomas.steur@gmail.com> | 2016-03-10 00:55:45 +0300 |
---|---|---|
committer | Thomas Steur <thomas.steur@gmail.com> | 2016-04-11 05:11:33 +0300 |
commit | b52ae4e7e488e0474d67c54578e1d6c1aa066bff (patch) | |
tree | f94b02f774cbc24faaa18f29ee1e19fef8b338af /plugins/CorePluginsAdmin/API.php | |
parent | 6ba622a68a26792af8cc22131f488f7ff5189d2c (diff) |
refs #7983 let plugins add or remove fields to websites and better settings api
Diffstat (limited to 'plugins/CorePluginsAdmin/API.php')
-rw-r--r-- | plugins/CorePluginsAdmin/API.php | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/plugins/CorePluginsAdmin/API.php b/plugins/CorePluginsAdmin/API.php new file mode 100644 index 0000000000..5ebd6dddbb --- /dev/null +++ b/plugins/CorePluginsAdmin/API.php @@ -0,0 +1,109 @@ +<?php +/** + * Piwik - free/libre analytics platform + * + * @link http://piwik.org + * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later + */ + +namespace Piwik\Plugins\CorePluginsAdmin; +use Piwik\Piwik; +use Piwik\Plugin\SettingsProvider; +use Exception; + +/** + * API for plugin CorePluginsAdmin + * + * @method static \Piwik\Plugins\CorePluginsAdmin\API getInstance() + */ +class API extends \Piwik\Plugin\API +{ + /** + * @var SettingsMetadata + */ + private $settingsMetadata; + + /** + * @var SettingsProvider + */ + private $settingsProvider; + + public function __construct(SettingsProvider $settingsProvider, SettingsMetadata $settingsMetadata) + { + $this->settingsProvider = $settingsProvider; + $this->settingsMetadata = $settingsMetadata; + } + + /** + * @ignore + * @param array $settingValues Format: array('PluginName' => array(array('name' => 'SettingName1', 'value' => 'SettingValue1), ..)) + * @throws Exception + */ + public function setSystemSettings($settingValues) + { + Piwik::checkUserHasSuperUserAccess(); + + $pluginsSettings = $this->settingsProvider->getAllSystemSettings(); + + $this->settingsMetadata->setPluginSettings($pluginsSettings, $settingValues); + + try { + foreach ($pluginsSettings as $pluginSetting) { + $pluginSetting->save(); + } + } catch (Exception $e) { + throw new Exception(Piwik::translate('CoreAdminHome_PluginSettingsSaveFailed')); + } + } + + /** + * @ignore + * @param array $settingValues Format: array('PluginName' => array(array('name' => 'SettingName1', 'value' => 'SettingValue1), ..)) + * @throws Exception + */ + public function setUserSettings($settingValues) + { + Piwik::checkUserIsNotAnonymous(); + + $pluginsSettings = $this->settingsProvider->getAllUserSettings(); + + $this->settingsMetadata->setPluginSettings($pluginsSettings, $settingValues); + + try { + foreach ($pluginsSettings as $pluginSetting) { + $pluginSetting->save(); + } + } catch (Exception $e) { + throw new Exception(Piwik::translate('CoreAdminHome_PluginSettingsSaveFailed')); + } + } + + /** + * @ignore + * @return array + * @throws \Piwik\NoAccessException + */ + public function getSystemSettings() + { + Piwik::checkUserHasSuperUserAccess(); + + $systemSettings = $this->settingsProvider->getAllSystemSettings(); + + return $this->settingsMetadata->formatSettings($systemSettings); + } + + /** + * @ignore + * @return array + * @throws \Piwik\NoAccessException + */ + public function getUserSettings() + { + Piwik::checkUserIsNotAnonymous(); + + $userSettings = $this->settingsProvider->getAllUserSettings(); + + return $this->settingsMetadata->formatSettings($userSettings); + } + +} |