@@ -34,6 +34,94 @@ class AppKernelControllerProvider extends BaseControllerProvider
34
34
35
35
const DEFAULT_DELIM =', ' ;
36
36
37
+ /**
38
+ * Format NotificationSettings from client form submittion
39
+ *
40
+ * @param array $s the input array.
41
+ * @param bool $preserveCheckBoxes ?
42
+ *
43
+ * @return null
44
+ */
45
+ public static function formatNotificationSettingsFromClient (&$ s , $ preserveCheckBoxes = false )
46
+ {
47
+ //set report periodisity
48
+ $ groupCombine =array ('daily_report ' ,'weekly_report ' ,'monthly_report ' );
49
+
50
+ foreach ($ groupCombine as $ g ) {
51
+ $ s [$ g ]=array ();
52
+ foreach ($ s as $ key => $ value ) {
53
+ if (strpos ($ key , $ g .'_ ' ) === 0 ) {
54
+ $ s [$ g ][str_replace ($ g .'_ ' , '' , $ key )]=$ value ;
55
+ unset($ s [$ key ]);
56
+ }
57
+ }
58
+ }
59
+ //make list of resources and appkernels
60
+ $ s ['resource ' ]=array ();
61
+ $ s ['appKer ' ]=array ();
62
+ foreach ($ s as $ key => $ value ) {
63
+ if (strpos ($ key , 'resourcesList_ ' ) === 0 ) {
64
+ $ s ['resource ' ][]=str_replace ('resourcesList_ ' , '' , $ key );
65
+ if ($ preserveCheckBoxes ) {
66
+ $ s [$ key ]='' ;
67
+ } else {
68
+ unset($ s [$ key ]);
69
+ }
70
+ }
71
+ if (strpos ($ key , 'appkernelsList_ ' ) === 0 ) {
72
+ $ s ['appKer ' ][]=str_replace ('appkernelsList_ ' , '' , $ key );
73
+ if ($ preserveCheckBoxes ) {
74
+ $ s [$ key ]='' ;
75
+ } else {
76
+ unset($ s [$ key ]);
77
+ }
78
+ }
79
+ }
80
+
81
+ if (count ($ s ['resource ' ])==1 && $ s ['resource ' ][0 ]=='all ' ) {
82
+ $ s ["resource " ]=array ();//None means all
83
+ }
84
+ if (count ($ s ['appKer ' ])==1 && $ s ['appKer ' ][0 ]=='all ' ) {
85
+ $ s ["appKer " ]=array ();//None means all
86
+ }
87
+ }
88
+
89
+ /**
90
+ * Format NotificationSettings for client
91
+ *
92
+ * @param array $s the input array
93
+ *
94
+ * @return null
95
+ */
96
+ public static function formatNotificationSettingsForClient (&$ s )
97
+ {
98
+ //make list of resources and appkernels
99
+ if (count ($ s ['resource ' ])==0 ) {
100
+ $ s ["resource " ]=array ('all ' );//None means all
101
+ }
102
+ if (count ($ s ['appKer ' ])==0 ) {
103
+ $ s ["appKer " ]=array ('all ' );//None means all
104
+ }
105
+ foreach ($ s ['resource ' ] as $ value ) {
106
+ $ s ['resourcesList_ ' .$ value ]='on ' ;
107
+ }
108
+ foreach ($ s ['appKer ' ] as $ value ) {
109
+ $ s ['appkernelsList_ ' .$ value ]='on ' ;
110
+ }
111
+
112
+ unset($ s ['resource ' ]);
113
+ unset($ s ['appKer ' ]);
114
+
115
+ $ groupCombine =array ('daily_report ' ,'weekly_report ' ,'monthly_report ' );
116
+
117
+ foreach ($ groupCombine as $ g ) {
118
+ foreach ($ s [$ g ] as $ key => $ value ) {
119
+ $ s [$ g .'_ ' .$ key ]=$ value ;
120
+ }
121
+ unset($ s [$ g ]);
122
+ }
123
+ }
124
+
37
125
/**
38
126
* @see BaseControllerProvider::setupRoutes
39
127
*/
@@ -737,7 +825,7 @@ public function getNotifications(Request $request, Application $app)
737
825
738
826
$ user_id = $ this ->getUserFromRequest ($ request )->getUserID ();
739
827
740
- formatNotificationSettingsFromClient ($ curent_tmp_settings , true );
828
+ self :: formatNotificationSettingsFromClient ($ curent_tmp_settings , true );
741
829
742
830
$ sqlres = $ pdo ->query (
743
831
'SELECT user_id,send_report_daily,send_report_weekly,send_report_monthly,settings
@@ -755,7 +843,7 @@ public function getNotifications(Request $request, Application $app)
755
843
} else {
756
844
throw new Exception ('settings is not set in db use default ' );
757
845
}
758
- formatNotificationSettingsForClient ($ curent_tmp_settings );
846
+ self :: formatNotificationSettingsForClient ($ curent_tmp_settings );
759
847
$ response ['data ' ] = $ curent_tmp_settings ;
760
848
$ response ['success ' ] = true ;
761
849
return $ app ->json ($ response );
@@ -781,7 +869,7 @@ public function putNotifications(Request $request, Application $app)
781
869
782
870
$ user_id = $ this ->getUserFromRequest ($ request )->getUserID ();
783
871
784
- formatNotificationSettingsFromClient ($ curent_tmp_settings );
872
+ self :: formatNotificationSettingsFromClient ($ curent_tmp_settings );
785
873
786
874
$ send_report_daily = ($ curent_tmp_settings ['daily_report ' ]['send_on_event ' ] === 'sendNever ' ) ? (0 ) : (1 );
787
875
$ send_report_weekly = ($ curent_tmp_settings ['weekly_report ' ]['send_on_event ' ] === 'sendNever ' ) ? (-$ curent_tmp_settings ['weekly_report ' ]['send_on ' ]) : ($ curent_tmp_settings ['weekly_report ' ]['send_on ' ]);
@@ -846,13 +934,13 @@ public function getDefaultNotifications(Request $request, Application $app)
846
934
$ curent_tmp_settings = $ this ->getStringParam ($ request , 'curent_tmp_settings ' , true );
847
935
$ curent_tmp_settings = json_decode ($ curent_tmp_settings , true );
848
936
849
- formatNotificationSettingsFromClient ($ curent_tmp_settings , true );
937
+ self :: formatNotificationSettingsFromClient ($ curent_tmp_settings , true );
850
938
851
939
$ curent_tmp_settings ["controlThresholdCoeff " ] = '1.0 ' ;
852
940
$ curent_tmp_settings ["resource " ] = array ();//None means all
853
941
$ curent_tmp_settings ["appKer " ] = array ();//None means all
854
942
855
- formatNotificationSettingsForClient ($ curent_tmp_settings );
943
+ self :: formatNotificationSettingsForClient ($ curent_tmp_settings );
856
944
857
945
$ response ['data ' ] = $ curent_tmp_settings ;
858
946
$ response ['success ' ] = true ;
@@ -998,7 +1086,7 @@ public function sendNotification(Request $request, Application $app)
998
1086
$ report_param = $ this ->getStringParam ($ request , 'report_param ' , true );
999
1087
$ report_param = json_decode ($ report_param , true );
1000
1088
1001
- formatNotificationSettingsFromClient ($ report_param );
1089
+ self :: formatNotificationSettingsFromClient ($ report_param );
1002
1090
1003
1091
$ report = new Report (array (
1004
1092
'start_date ' => $ start_date ,
0 commit comments