1
+ <?php
2
+
3
+ declare (strict_types=1 );
4
+
5
+ namespace OCA \Notifications \Settings ;
6
+
7
+ use OCA \Notifications \AppInfo \Application ;
8
+ use OCA \Notifications \Model \Settings ;
9
+ use OCA \Notifications \Model \SettingsMapper ;
10
+ use OCP \AppFramework \Db \DoesNotExistException ;
11
+ use OCP \AppFramework \Http \TemplateResponse ;
12
+ use OCP \AppFramework \Services \IInitialState ;
13
+ use OCP \IConfig ;
14
+ use OCP \IL10N ;
15
+ use OCP \IUser ;
16
+ use OCP \Settings \ISettings ;
17
+ use OCP \IUserSession ;
18
+ use OCP \Util ;
19
+
20
+ class Admin implements ISettings
21
+ {
22
+ /** @var \OCP\IConfig */
23
+ protected $ config ;
24
+
25
+ /** @var \OCP\IL10N */
26
+ protected $ l10n ;
27
+
28
+ /** @var SettingsMapper */
29
+ private $ settingsMapper ;
30
+
31
+ /** @var IUserSession */
32
+ private $ session ;
33
+
34
+ /** @var IInitialState */
35
+ private $ initialState ;
36
+
37
+ public function __construct (IConfig $ config ,
38
+ IL10N $ l10n ,
39
+ IUserSession $ session ,
40
+ SettingsMapper $ settingsMapper ,
41
+ IInitialState $ initialState )
42
+ {
43
+ $ this ->config = $ config ;
44
+ $ this ->l10n = $ l10n ;
45
+ $ this ->settingsMapper = $ settingsMapper ;
46
+ $ this ->session = $ session ;
47
+ $ this ->initialState = $ initialState ;
48
+ }
49
+
50
+ /**
51
+ * @return TemplateResponse
52
+ */
53
+ public function getForm (): TemplateResponse
54
+ {
55
+ Util::addScript ('notifications ' , 'notifications-adminSettings ' );
56
+
57
+ $ default_sound_notification = $ this ->config ->getAppValue (Application::APP_ID , 'sound_notification ' ) === 'yes ' ? 'yes ' : 'no ' ;
58
+ $ default_sound_talk = $ this ->config ->getAppValue (Application::APP_ID , 'sound_talk ' ) === 'yes ' ? 'yes ' : 'no ' ;
59
+ $ default_batchtime = $ this ->config ->getAppValue (Application::APP_ID , 'setting_batchtime ' );
60
+
61
+ if ($ default_batchtime != Settings::EMAIL_SEND_WEEKLY
62
+ && $ default_batchtime != Settings::EMAIL_SEND_DAILY
63
+ && $ default_batchtime != Settings::EMAIL_SEND_3HOURLY
64
+ && $ default_batchtime != Settings::EMAIL_SEND_HOURLY
65
+ && $ default_batchtime != Settings::EMAIL_SEND_OFF ) {
66
+ $ default_batchtime = Settings::EMAIL_SEND_3HOURLY ;
67
+ }
68
+
69
+ $ this ->initialState ->provideInitialState ('config ' , [
70
+ 'setting ' => 'admin ' ,
71
+ 'setting_batchtime ' => $ default_batchtime ,
72
+ 'sound_notification ' => $ default_sound_notification === 'yes ' ,
73
+ 'sound_talk ' => $ default_sound_talk === 'yes ' ,
74
+ ]);
75
+
76
+ return new TemplateResponse ('notifications ' , 'settings/admin ' );
77
+ }
78
+
79
+ /**
80
+ * @return string the section ID, e.g. 'sharing'
81
+ */
82
+ public function getSection (): string
83
+ {
84
+ return 'notifications ' ;
85
+ }
86
+
87
+ /**
88
+ * @return int whether the form should be rather on the top or bottom of
89
+ * the admin section. The forms are arranged in ascending order of the
90
+ * priority values. It is required to return a value between 0 and 100.
91
+ *
92
+ * E.g.: 70
93
+ */
94
+ public function getPriority (): int
95
+ {
96
+ return 20 ;
97
+ }
98
+ }
0 commit comments