Commit 5937dcc70db5cf5b302d49753aaa73df4af164a2
1 parent
c0f7b2aa
ga output
Showing
1 changed file
with
49 additions
and
33 deletions
Show diff stats
app/library/App/Controllers/GaController.php
| ... | ... | @@ -34,6 +34,7 @@ class GaController extends CrudResourceController { |
| 34 | 34 | $get_dimensions = $this->request->get('dimension'); |
| 35 | 35 | $get_start_date = $this->request->get('start') ?? '30daysAgo'; |
| 36 | 36 | $get_end_date = $this->request->get('end') ?? 'today'; |
| 37 | + $chart = $this->request->get('chart') ?? false; | |
| 37 | 38 | |
| 38 | 39 | if (empty($view_id)) { |
| 39 | 40 | $result = []; |
| ... | ... | @@ -51,38 +52,6 @@ class GaController extends CrudResourceController { |
| 51 | 52 | |
| 52 | 53 | } |
| 53 | 54 | |
| 54 | - public function printResults($reports) { | |
| 55 | - $res = ''; | |
| 56 | - for ( $reportIndex = 0; $reportIndex < count( $reports ); $reportIndex++ ) { | |
| 57 | - $report = $reports[ $reportIndex ]; | |
| 58 | - $header = $report->getColumnHeader(); | |
| 59 | - $dimensionHeaders = $header->getDimensions(); | |
| 60 | - $metricHeaders = $header->getMetricHeader()->getMetricHeaderEntries(); | |
| 61 | - $rows = $report->getData()->getRows(); | |
| 62 | - | |
| 63 | - for ( $rowIndex = 0; $rowIndex < count($rows); $rowIndex++) { | |
| 64 | - $row = $rows[ $rowIndex ]; | |
| 65 | - $dimensions = $row->getDimensions(); | |
| 66 | - $metrics = $row->getMetrics(); | |
| 67 | - for ($i = 0; $i < count($dimensionHeaders) && $i < count($dimensions); $i++) { | |
| 68 | - print($dimensionHeaders[$i] . ": " . $dimensions[$i] . "\n"); | |
| 69 | - } | |
| 70 | - | |
| 71 | - for ($j = 0; $j < count( $metricHeaders ) && $j < count( $metrics ); $j++) { | |
| 72 | - $entry = $metricHeaders[$j]; | |
| 73 | - $values = $metrics[$j]; | |
| 74 | - //print("Metric type: " . $entry->getType() . "\n" ); | |
| 75 | - for ( $valueIndex = 0; $valueIndex < count( $values->getValues() ); $valueIndex++ ) { | |
| 76 | - $value = $values->getValues()[ $valueIndex ]; | |
| 77 | - $res .= "<b>" . $entry->getName() . "</b>: " . $value . '<br/>'; | |
| 78 | - } | |
| 79 | - } | |
| 80 | - } | |
| 81 | - } | |
| 82 | - | |
| 83 | - return $res; | |
| 84 | - } | |
| 85 | - | |
| 86 | 55 | public function sendGaRequest($project_name, $view, $get_metrics, $get_dimensions, $start, $end) { |
| 87 | 56 | |
| 88 | 57 | putenv('GOOGLE_APPLICATION_CREDENTIALS=/var/www/phalcon/'.self::SECRET_JSON); |
| ... | ... | @@ -135,6 +104,14 @@ class GaController extends CrudResourceController { |
| 135 | 104 | $response = $response->toSimpleObject(); |
| 136 | 105 | $response = $response->reports[0]['data']['rows']; |
| 137 | 106 | |
| 107 | + $result = self::responseTransform($response, $project_name); | |
| 108 | + | |
| 109 | + return ($result); | |
| 110 | + | |
| 111 | + } | |
| 112 | + | |
| 113 | + public static function responseTransform(array $response, $project_name) { | |
| 114 | + | |
| 138 | 115 | $result = []; |
| 139 | 116 | |
| 140 | 117 | foreach ($response as $item) { |
| ... | ... | @@ -153,7 +130,46 @@ class GaController extends CrudResourceController { |
| 153 | 130 | } |
| 154 | 131 | } |
| 155 | 132 | |
| 156 | - return ($result); | |
| 133 | + return $result; | |
| 157 | 134 | |
| 158 | 135 | } |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + public function printResults($reports) { | |
| 144 | + $res = ''; | |
| 145 | + for ( $reportIndex = 0; $reportIndex < count( $reports ); $reportIndex++ ) { | |
| 146 | + $report = $reports[ $reportIndex ]; | |
| 147 | + $header = $report->getColumnHeader(); | |
| 148 | + $dimensionHeaders = $header->getDimensions(); | |
| 149 | + $metricHeaders = $header->getMetricHeader()->getMetricHeaderEntries(); | |
| 150 | + $rows = $report->getData()->getRows(); | |
| 151 | + | |
| 152 | + for ( $rowIndex = 0; $rowIndex < count($rows); $rowIndex++) { | |
| 153 | + $row = $rows[ $rowIndex ]; | |
| 154 | + $dimensions = $row->getDimensions(); | |
| 155 | + $metrics = $row->getMetrics(); | |
| 156 | + for ($i = 0; $i < count($dimensionHeaders) && $i < count($dimensions); $i++) { | |
| 157 | + print($dimensionHeaders[$i] . ": " . $dimensions[$i] . "\n"); | |
| 158 | + } | |
| 159 | + | |
| 160 | + for ($j = 0; $j < count( $metricHeaders ) && $j < count( $metrics ); $j++) { | |
| 161 | + $entry = $metricHeaders[$j]; | |
| 162 | + $values = $metrics[$j]; | |
| 163 | + //print("Metric type: " . $entry->getType() . "\n" ); | |
| 164 | + for ( $valueIndex = 0; $valueIndex < count( $values->getValues() ); $valueIndex++ ) { | |
| 165 | + $value = $values->getValues()[ $valueIndex ]; | |
| 166 | + $res .= "<b>" . $entry->getName() . "</b>: " . $value . '<br/>'; | |
| 167 | + } | |
| 168 | + } | |
| 169 | + } | |
| 170 | + } | |
| 171 | + | |
| 172 | + return $res; | |
| 173 | + } | |
| 174 | + | |
| 159 | 175 | } |
| 160 | 176 | \ No newline at end of file | ... | ... |