|
7 | 7 |
|
8 | 8 | namespace Keyman\Site\com\keyman\api; |
9 | 9 |
|
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; |
24 | | - } |
25 | | - |
26 | 10 | class AnnualStatistics { |
27 | 11 |
|
28 | 12 | function execute($mssql, $startDate, $endDate) { |
| 13 | + return $this->_execute('sp_annual_statistics', $mssql, $startDate, $endDate); |
| 14 | + } |
29 | 15 |
|
30 | | - $stmt = $mssql->prepare('EXEC sp_annual_statistics :prmStartDate, :prmEndDate'); |
31 | | - |
32 | | - $stmt->bindParam(":prmStartDate", $startDate); |
33 | | - $stmt->bindParam(":prmEndDate", $endDate); |
| 16 | + function executeDownloadsByMonth($mssql, $startDate, $endDate) { |
| 17 | + return $this->_execute('sp_keyboard_downloads_by_month_statistics', $mssql, $startDate, $endDate); |
| 18 | + } |
34 | 19 |
|
35 | | - $stmt->execute(); |
36 | | - $data = $stmt->fetchAll(); |
37 | | - return filter_columns_by_name($data); |
| 20 | + function executeKeyboards($mssql, $startDate, $endDate) { |
| 21 | + return $this->_execute('sp_statistics_keyboard_downloads_by_id', $mssql, $startDate, $endDate); |
38 | 22 | } |
39 | 23 |
|
40 | | - function executeDownloadsByMonth($mssql, $startDate, $endDate) { |
41 | | - $stmt = $mssql->prepare('EXEC sp_keyboard_downloads_by_month_statistics :prmStartDate, :prmEndDate'); |
| 24 | + private function _execute($proc, $mssql, $startDate, $endDate) { |
| 25 | + $stmt = $mssql->prepare("EXEC $proc :prmStartDate, :prmEndDate"); |
42 | 26 |
|
43 | 27 | $stmt->bindParam(":prmStartDate", $startDate); |
44 | 28 | $stmt->bindParam(":prmEndDate", $endDate); |
45 | 29 |
|
46 | 30 | $stmt->execute(); |
47 | 31 | $data = $stmt->fetchAll(); |
48 | | - return filter_columns_by_name($data); |
| 32 | + return $this->filter_columns_by_name($data); |
| 33 | + } |
| 34 | + |
| 35 | + // strip out repeated columns with numeric keys (by default the results returned |
| 36 | + // give each column twice, once with a column name, and once with a column index) |
| 37 | + private function filter_columns_by_name($data) { |
| 38 | + $result = []; |
| 39 | + foreach($data as $row) { |
| 40 | + $r = []; |
| 41 | + foreach($row as $id => $val) { |
| 42 | + if(!is_numeric($id)) { |
| 43 | + $r[$id] = is_numeric($val) ? intval($val) : $val; |
| 44 | + } |
| 45 | + } |
| 46 | + array_push($result, $r); |
| 47 | + } |
| 48 | + return $result; |
49 | 49 | } |
50 | 50 | } |
0 commit comments