77
88 namespace Keyman \Site \com \keyman \api ;
99
10- function filter_columns_by_name ($ key ) {
11- return !is_numeric ($ key );
10+ // strip out repeated columns with numeric keys (by default the results returned
11+ // give each column twice, once with a column name, and once with a column index)
12+ function filter_columns_by_name ($ data ) {
13+ $ result = [];
14+ foreach ($ data as $ row ) {
15+ $ r = [];
16+ foreach ($ row as $ id => $ val ) {
17+ if (!is_numeric ($ id )) {
18+ $ r [$ id ] = intval ($ val );
19+ }
20+ }
21+ array_push ($ result , $ r );
22+ }
23+ return $ result ;
1224 }
1325
1426class AnnualStatistics {
@@ -22,7 +34,17 @@ function execute($mssql, $startDate, $endDate) {
2234
2335 $ stmt ->execute ();
2436 $ data = $ stmt ->fetchAll ();
25- //$data = array_filter($data, "Keyman\\Site\\com\\keyman\\api\\filter_columns_by_name", ARRAY_FILTER_USE_KEY );
26- return $ data ;
37+ return filter_columns_by_name ($ data );
38+ }
39+
40+ function executeDownloadsByMonth ($ mssql , $ startDate , $ endDate ) {
41+ $ stmt = $ mssql ->prepare ('EXEC sp_keyboard_downloads_by_month_statistics :prmStartDate, :prmEndDate ' );
42+
43+ $ stmt ->bindParam (":prmStartDate " , $ startDate );
44+ $ stmt ->bindParam (":prmEndDate " , $ endDate );
45+
46+ $ stmt ->execute ();
47+ $ data = $ stmt ->fetchAll ();
48+ return filter_columns_by_name ($ data );
2749 }
2850}
0 commit comments