1 | <?php |
||
33 | class UserSettings { |
||
34 | /** @var IManager */ |
||
35 | protected $manager; |
||
36 | |||
37 | /** @var IConfig */ |
||
38 | protected $config; |
||
39 | |||
40 | /** @var Data */ |
||
41 | protected $data; |
||
42 | |||
43 | const EMAIL_SEND_HOURLY = 0; |
||
44 | const EMAIL_SEND_DAILY = 1; |
||
45 | const EMAIL_SEND_WEEKLY = 2; |
||
46 | |||
47 | /** |
||
48 | * @param IManager $manager |
||
49 | * @param IConfig $config |
||
50 | * @param Data $data |
||
51 | */ |
||
52 | 26 | public function __construct(IManager $manager, IConfig $config, Data $data) { |
|
57 | |||
58 | /** |
||
59 | * Get a setting for a user |
||
60 | * |
||
61 | * Falls back to some good default values if the user does not have a preference |
||
62 | * |
||
63 | * @param string $user |
||
64 | * @param string $method Should be one of 'stream', 'email' or 'setting' |
||
65 | * @param string $type One of the activity types, 'batchtime' or 'self' |
||
66 | * @return bool|int |
||
67 | */ |
||
68 | 6 | public function getUserSetting($user, $method, $type) { |
|
69 | 6 | $defaultSetting = $this->getDefaultSetting($method, $type); |
|
70 | 6 | if (is_bool($defaultSetting)) { |
|
71 | 6 | return (bool) $this->config->getUserValue( |
|
72 | $user, |
||
73 | 6 | 'activity', |
|
74 | 6 | 'notify_' . $method . '_' . $type, |
|
75 | $defaultSetting |
||
76 | ); |
||
77 | } else { |
||
78 | return (int) $this->config->getUserValue( |
||
79 | $user, |
||
80 | 'activity', |
||
81 | 'notify_' . $method . '_' . $type, |
||
82 | $defaultSetting |
||
83 | ); |
||
84 | } |
||
85 | } |
||
86 | |||
87 | /** |
||
88 | * Get a good default setting for a preference |
||
89 | * |
||
90 | * @param string $method Should be one of 'stream', 'email' or 'setting' |
||
91 | * @param string $type One of the activity types, 'batchtime', 'self' or 'selfemail' |
||
92 | * @return bool|int |
||
93 | */ |
||
94 | 18 | public function getDefaultSetting($method, $type) { |
|
108 | |||
109 | /** |
||
110 | * Get a list with enabled notification types for a user |
||
111 | * |
||
112 | * @param string $user Name of the user |
||
113 | * @param string $method Should be one of 'stream' or 'email' |
||
114 | * @return array |
||
115 | */ |
||
116 | 6 | public function getNotificationTypes($user, $method) { |
|
129 | |||
130 | /** |
||
131 | * Filters the given user array by their notification setting |
||
132 | * |
||
133 | * @param array $users |
||
134 | * @param string $method |
||
135 | * @param string $type |
||
136 | * @return array Returns a "username => b:true" Map for method = stream |
||
137 | * Returns a "username => i:batchtime" Map for method = email |
||
138 | */ |
||
139 | 8 | public function filterUsersBySetting($users, $method, $type) { |
|
179 | } |
||
180 |