From 52e8a0d868069c090997aaa134ecc51ef275b4c2 Mon Sep 17 00:00:00 2001 From: Thomas Steur Date: Thu, 24 Oct 2013 01:43:51 +0000 Subject: refs #4126 added more example, handle type array and field multi select correct, code cleanup --- plugins/ExampleSettingsPlugin/Settings.php | 49 ++++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) (limited to 'plugins/ExampleSettingsPlugin') diff --git a/plugins/ExampleSettingsPlugin/Settings.php b/plugins/ExampleSettingsPlugin/Settings.php index 400b74184d..89afa86b37 100644 --- a/plugins/ExampleSettingsPlugin/Settings.php +++ b/plugins/ExampleSettingsPlugin/Settings.php @@ -32,8 +32,17 @@ class Settings extends PluginSettings // User setting --> textbox converted to int defining a validator and filter $this->addSetting($this->getRefreshIntervalSetting()); - // System setting --> allows selection of a value + // System setting --> allows selection of a single value $this->addSetting($this->getMetricSetting()); + + // System setting --> allows selection of multiple values + $this->addSetting($this->getBrowsersSetting()); + + // System setting --> textarea + $this->addSetting($this->getDescriptionSetting()); + + // System setting --> textarea + $this->addSetting($this->getPasswordSetting()); } public function isAutoRefreshEnabled() @@ -93,10 +102,44 @@ class Settings extends PluginSettings $metric->type = static::TYPE_STRING; $metric->field = static::FIELD_SINGLE_SELECT; $metric->fieldOptions = array('nb_visits' => 'Visits', 'nb_actions' => 'Actions', 'visitors' => 'Visitors'); - $metric->introduction = 'Only super users can change this setting.'; - $metric->description = Piwik::translate('LiveTab_MetricDescription'); + $metric->introduction = 'Only super users can change the following settings:'; + $metric->description = 'Choose the metric that should be displayed in the browser tab'; $metric->defaultValue = 'nb_visits'; return $metric; } + + private function getBrowsersSetting() + { + $browsers = new SystemSetting('browsers', 'Supported Browsers'); + $browsers->type = static::TYPE_ARRAY; + $browsers->field = static::FIELD_MULTI_SELECT; + $browsers->fieldOptions = array('firefox' => 'Firefox', 'chromium' => 'Chromium', 'safari' => 'safari'); + $browsers->description = 'The value will be only displayed in the following browsers'; + $browsers->defaultValue = array('firefox', 'chromium', 'safari'); + + return $browsers; + } + + private function getDescriptionSetting() + { + $description = new SystemSetting('description', 'Description for value'); + $description->field = static::FIELD_TEXTAREA; + $description->description = 'This description will be displayed next to the value'; + $description->defaultValue = "This is the value: \nAnother line"; + + return $description; + } + + private function getPasswordSetting() + { + $description = new SystemSetting('password', 'API password'); + $description->field = static::FIELD_PASSWORD; + $description->description = 'Password for the 3rd API where we fetch the value'; + $description->filter = function ($value) { + return sha1($value . 'salt'); + }; + + return $description; + } } -- cgit v1.2.3