]> BookStack Code Mirror - bookstack/blob - app/Settings/UserNotificationPreferences.php
Lexical: Fixed code in lists, removed extra old alignment code
[bookstack] / app / Settings / UserNotificationPreferences.php
1 <?php
2
3 namespace BookStack\Settings;
4
5 use BookStack\Users\Models\User;
6
7 class UserNotificationPreferences
8 {
9     public function __construct(
10         protected User $user
11     ) {
12     }
13
14     public function notifyOnOwnPageChanges(): bool
15     {
16         return $this->getNotificationSetting('own-page-changes');
17     }
18
19     public function notifyOnOwnPageComments(): bool
20     {
21         return $this->getNotificationSetting('own-page-comments');
22     }
23
24     public function notifyOnCommentReplies(): bool
25     {
26         return $this->getNotificationSetting('comment-replies');
27     }
28
29     public function updateFromSettingsArray(array $settings)
30     {
31         $allowList = ['own-page-changes', 'own-page-comments', 'comment-replies'];
32         foreach ($settings as $setting => $status) {
33             if (!in_array($setting, $allowList)) {
34                 continue;
35             }
36
37             $value = $status === 'true' ? 'true' : 'false';
38             setting()->putUser($this->user, 'notifications#' . $setting, $value);
39         }
40     }
41
42     protected function getNotificationSetting(string $key): bool
43     {
44         return setting()->getUser($this->user, 'notifications#' . $key);
45     }
46 }