Commit c6c9c77eccffc63132784958c927db57ca5eb59e
1 parent
0c1a07f0
add php docs to ga controller
Showing
1 changed file
with
32 additions
and
7 deletions
Show diff stats
app/library/App/Controllers/GaController.php
... | ... | @@ -58,6 +58,19 @@ class GaController extends CrudResourceController { |
58 | 58 | |
59 | 59 | } |
60 | 60 | |
61 | + /** | |
62 | + * Send request to Google Analytics Reporting API | |
63 | + * | |
64 | + * @param string $project_name | |
65 | + * @param string $view | |
66 | + * @param string $get_metrics | |
67 | + * @param string $get_dimensions | |
68 | + * @param string $start | |
69 | + * @param string $end | |
70 | + * @param bool $chart | |
71 | + * @param string $filter_expression | |
72 | + * @return array | |
73 | + */ | |
61 | 74 | public function sendGaRequest($project_name, $view, $get_metrics, $get_dimensions, $start, $end, $chart = false, $filter_expression = null) { |
62 | 75 | |
63 | 76 | putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/phalcon/'.self::SECRET_JSON); |
... | ... | @@ -92,7 +105,7 @@ class GaController extends CrudResourceController { |
92 | 105 | } |
93 | 106 | } |
94 | 107 | |
95 | - //Create the ReportRequest object. | |
108 | + /** Create the ReportRequest object. **/ | |
96 | 109 | $request = new Google_Service_AnalyticsReporting_ReportRequest(); |
97 | 110 | $request->setViewId($view); |
98 | 111 | $request->setDateRanges($dateRange); |
... | ... | @@ -110,7 +123,7 @@ class GaController extends CrudResourceController { |
110 | 123 | |
111 | 124 | $response = $analytics->reports->batchGet($body); |
112 | 125 | |
113 | - //have to rewrite code below (2 rows) | |
126 | + /** can be refactored (code below 2 rows) **/ | |
114 | 127 | $response = $response->toSimpleObject(); |
115 | 128 | $response = $response->reports[0]['data']['rows']; |
116 | 129 | |
... | ... | @@ -124,6 +137,13 @@ class GaController extends CrudResourceController { |
124 | 137 | |
125 | 138 | } |
126 | 139 | |
140 | + /** | |
141 | + * Data-transformer for tables. Used by default. | |
142 | + * | |
143 | + * @param array $response | |
144 | + * @param string $project_name | |
145 | + * @return array | |
146 | + */ | |
127 | 147 | public static function responseDataTransform(array $response, $project_name) { |
128 | 148 | |
129 | 149 | $result = []; |
... | ... | @@ -148,6 +168,13 @@ class GaController extends CrudResourceController { |
148 | 168 | |
149 | 169 | } |
150 | 170 | |
171 | + /** | |
172 | + * Data-transformer for charts, when query string contains "?chart=true" | |
173 | + * | |
174 | + * @param array $response | |
175 | + * @param string $project_name | |
176 | + * @return array | |
177 | + */ | |
151 | 178 | public static function responseChartTransform(array $response, $project_name) { |
152 | 179 | |
153 | 180 | $result = []; |
... | ... | @@ -171,11 +198,9 @@ class GaController extends CrudResourceController { |
171 | 198 | } |
172 | 199 | |
173 | 200 | |
174 | - | |
175 | - | |
176 | - | |
177 | - | |
178 | - | |
201 | + /** | |
202 | + * without usage, from google docs. | |
203 | + */ | |
179 | 204 | public function printResults($reports) { |
180 | 205 | $res = ''; |
181 | 206 | for ( $reportIndex = 0; $reportIndex < count( $reports ); $reportIndex++ ) { | ... | ... |