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,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 | public function sendGaRequest($project_name, $view, $get_metrics, $get_dimensions, $start, $end, $chart = false, $filter_expression = null) { | 74 | public function sendGaRequest($project_name, $view, $get_metrics, $get_dimensions, $start, $end, $chart = false, $filter_expression = null) { |
62 | 75 | ||
63 | putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/phalcon/'.self::SECRET_JSON); | 76 | putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/phalcon/'.self::SECRET_JSON); |
@@ -92,7 +105,7 @@ class GaController extends CrudResourceController { | @@ -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 | $request = new Google_Service_AnalyticsReporting_ReportRequest(); | 109 | $request = new Google_Service_AnalyticsReporting_ReportRequest(); |
97 | $request->setViewId($view); | 110 | $request->setViewId($view); |
98 | $request->setDateRanges($dateRange); | 111 | $request->setDateRanges($dateRange); |
@@ -110,7 +123,7 @@ class GaController extends CrudResourceController { | @@ -110,7 +123,7 @@ class GaController extends CrudResourceController { | ||
110 | 123 | ||
111 | $response = $analytics->reports->batchGet($body); | 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 | $response = $response->toSimpleObject(); | 127 | $response = $response->toSimpleObject(); |
115 | $response = $response->reports[0]['data']['rows']; | 128 | $response = $response->reports[0]['data']['rows']; |
116 | 129 | ||
@@ -124,6 +137,13 @@ class GaController extends CrudResourceController { | @@ -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 | public static function responseDataTransform(array $response, $project_name) { | 147 | public static function responseDataTransform(array $response, $project_name) { |
128 | 148 | ||
129 | $result = []; | 149 | $result = []; |
@@ -148,6 +168,13 @@ class GaController extends CrudResourceController { | @@ -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 | public static function responseChartTransform(array $response, $project_name) { | 178 | public static function responseChartTransform(array $response, $project_name) { |
152 | 179 | ||
153 | $result = []; | 180 | $result = []; |
@@ -171,11 +198,9 @@ class GaController extends CrudResourceController { | @@ -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 | public function printResults($reports) { | 204 | public function printResults($reports) { |
180 | $res = ''; | 205 | $res = ''; |
181 | for ( $reportIndex = 0; $reportIndex < count( $reports ); $reportIndex++ ) { | 206 | for ( $reportIndex = 0; $reportIndex < count( $reports ); $reportIndex++ ) { |