-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathUserSettings.php
More file actions
62 lines (55 loc) · 1.59 KB
/
UserSettings.php
File metadata and controls
62 lines (55 loc) · 1.59 KB
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
<?php
/**
* Piwik - free/libre analytics platform.
*
* @see https://matomo.org
*
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\IP2Proxy;
use Piwik\Common;
use Piwik\Db;
use Piwik\Piwik;
use Piwik\Settings\FieldConfig;
use Piwik\Settings\Setting;
/**
* Defines Settings for IP2Proxy.
*
* Usage like this:
* $settings = new UserSettings();
* $settings->autoRefresh->getValue();
* $settings->color->getValue();
*/
class UserSettings extends \Piwik\Settings\Plugin\UserSettings
{
public function getSubscribedToEmailReportValueForUser($userLogin)
{
try {
$sql = 'SELECT * FROM ' . Common::prefixTable('plugin_setting') . "
WHERE plugin_name = 'IP2Proxy'
AND setting_name = 'subscribedToEmailReport'
AND setting_value = '1'
AND user_login = ?";
$result = Db::fetchAll($sql, [$userLogin]);
} catch (Exception $e) {
// Ignore error if table already exists
if (!Db::get()->isErrNo($e, '1050')) {
throw $e;
}
}
return \count($result) == 1;
}
protected function init()
{
// User setting --> checkbox converted to bool
$this->subscribedToEmailReport = $this->createSubscribedToEmailReportSetting();
}
private function createSubscribedToEmailReportSetting()
{
return $this->makeSetting('subscribedToEmailReport', $default = false, FieldConfig::TYPE_BOOL, function (FieldConfig $field) {
$field->title = Piwik::translate('IP2Proxy_SubscribeToEmailReport');
$field->uiControl = FieldConfig::UI_CONTROL_CHECKBOX;
$field->description = Piwik::translate('IP2Proxy_WantToReceiveDailyReport');
});
}
}