Commit 9c05b430a13a32337df1add2de170a03980f7f9d
1 parent
45aa4e58
ga
Showing
1 changed file
with
29 additions
and
22 deletions
Show diff stats
backend/views/report/index.php
| ... | ... | @@ -44,17 +44,9 @@ if (isset($_SESSION['access_token']) && $_SESSION['access_token']) { |
| 44 | 44 | |
| 45 | 45 | // Вывод ответа. |
| 46 | 46 | printResults($response); |
| 47 | + printDataTable($response); | |
| 47 | 48 | |
| 48 | 49 | |
| 49 | - try { | |
| 50 | - $results = queryCoreReportingApi(); | |
| 51 | - // Success. Do something cool! | |
| 52 | - | |
| 53 | - } catch (apiServiceException $e) { | |
| 54 | - // Handle API service exceptions. | |
| 55 | - $error = $e->getMessage(); | |
| 56 | - } | |
| 57 | - | |
| 58 | 50 | } else { |
| 59 | 51 | $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/admin/report/callback'; |
| 60 | 52 | header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL)); |
| ... | ... | @@ -117,19 +109,34 @@ function printResults($reports) { |
| 117 | 109 | } |
| 118 | 110 | } |
| 119 | 111 | |
| 120 | -function queryCoreReportingApi() { | |
| 121 | - $optParams = array( | |
| 122 | - 'dimensions' => 'ga:source,ga:keyword', | |
| 123 | - 'sort' => '-ga:sessions,ga:source', | |
| 124 | - 'filters' => 'ga:medium==organic', | |
| 125 | - 'max-results' => '25'); | |
| 126 | - | |
| 127 | - return $service->data_ga->get( | |
| 128 | - TABLE_ID, | |
| 129 | - '2010-01-01', | |
| 130 | - '2010-01-15', | |
| 131 | - 'ga:sessions', | |
| 132 | - $optParams); | |
| 112 | +private function printDataTable(&$results) { | |
| 113 | + if (count($results->getRows()) > 0) { | |
| 114 | + $table .= '<table>'; | |
| 115 | + | |
| 116 | + // Print headers. | |
| 117 | + $table .= '<tr>'; | |
| 118 | + | |
| 119 | + foreach ($results->getColumnHeaders() as $header) { | |
| 120 | + $table .= '<th>' . $header->name . '</th>'; | |
| 121 | + } | |
| 122 | + $table .= '</tr>'; | |
| 123 | + | |
| 124 | + // Print table rows. | |
| 125 | + foreach ($results->getRows() as $row) { | |
| 126 | + $table .= '<tr>'; | |
| 127 | + foreach ($row as $cell) { | |
| 128 | + $table .= '<td>' | |
| 129 | + . htmlspecialchars($cell, ENT_NOQUOTES) | |
| 130 | + . '</td>'; | |
| 131 | + } | |
| 132 | + $table .= '</tr>'; | |
| 133 | + } | |
| 134 | + $table .= '</table>'; | |
| 135 | + | |
| 136 | + } else { | |
| 137 | + $table .= '<p>No Results Found.</p>'; | |
| 138 | + } | |
| 139 | + print $table; | |
| 133 | 140 | } |
| 134 | 141 | |
| 135 | 142 | ... | ... |