Blame view

app/library/App/Bootstrap/RouteBootstrap.php 2.62 KB
15479603   Alex Savenko   initialize
1
2
3
4
5
6
7
8
9
  <?php
  
  namespace App\Bootstrap;
  
  use App\BootstrapInterface;
  use App\Constants\Services;
  use Phalcon\Config;
  use Phalcon\DiInterface;
  use PhalconRest\Api;
843214bf   Alex Savenko   test google lib
10
  
2e1db97a   Alex Savenko   test google lib
11
12
  use Google_Client;
  use Google_Service_AnalyticsReporting;
15479603   Alex Savenko   initialize
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
  
  class RouteBootstrap implements BootstrapInterface
  {
      public function run(Api $api, DiInterface $di, Config $config)
      {
          $api->get('/', function() use ($api) {
  
              /** @var \Phalcon\Mvc\View\Simple $view */
              $view = $api->di->get(Services::VIEW);
  
              return $view->render('general/index');
          });
  
          $api->get('/proxy.html', function() use ($api, $config) {
  
              /** @var \Phalcon\Mvc\View\Simple $view */
              $view = $api->di->get(Services::VIEW);
  
              $view->setVar('client', $config->clientHostName);
              return $view->render('general/proxy');
          });
  
          $api->get('/documentation.html', function() use ($api, $config) {
  
              /** @var \Phalcon\Mvc\View\Simple $view */
              $view = $api->di->get(Services::VIEW);
  
              $view->setVar('title', $config->application->title);
              $view->setVar('description', $config->application->description);
              $view->setVar('documentationPath', $config->hostName . '/export/documentation.json');
              return $view->render('general/documentation');
          });
1f3b737a   Alex Savenko   test new routing
45
46
47
48
49
50
  
          $api->get('/test.html', function() use ($api) {
  
              /** @var \Phalcon\Mvc\View\Simple $view */
              $view = $api->di->get(Services::VIEW);
  
2e1db97a   Alex Savenko   test google lib
51
52
53
54
              $client = new Google_Client();
              $api_key = 'AIzaSyCXzrwqxLN2bCvBhw2cJfdeEu9aj1aH5b8';
              $client->setDeveloperKey($api_key);
              $analytics = new Google_Service_AnalyticsReporting($client);
c0ced521   Alex Savenko   test google lib
55
  
843214bf   Alex Savenko   test google lib
56
57
58
59
60
61
62
63
64
65
66
67
              $param[] = ['metric' => 'ga:sessions', 'alias' => 'Сессии'];
              $param[] = ['metric' => 'ga:users', 'alias' => 'Пользователи'];
              $param[] = ['metric' => 'ga:CTR', 'alias' => 'CTR'];
              $param[] = ['metric' => 'ga:goal1Value', 'alias' => 'цель "Корзина"'];
  
              foreach ($param as $item) {
  
                  $response = $this->getReport($analytics, $item['metric'], $item['alias']);
  
              }
  
              $var_2 = var_dump($response);
c0ced521   Alex Savenko   test google lib
68
  
f5c8ea14   Alex Savenko   test new routing ...
69
70
71
              $msg = "testing fine";
  
              return $view->render('general/test', [
c0ced521   Alex Savenko   test google lib
72
73
                  'var1' => $msg,
                  'var2' => $var_2
f5c8ea14   Alex Savenko   test new routing ...
74
              ]);
1f3b737a   Alex Savenko   test new routing
75
          });
15479603   Alex Savenko   initialize
76
      }
843214bf   Alex Savenko   test google lib
77
  
8d4186ce   Alex Savenko   test google lib
78
      function getReport($analytics, $metric, $alias) {
843214bf   Alex Savenko   test google lib
79
  
8d4186ce   Alex Savenko   test google lib
80
81
82
83
84
          // Замена на свой идентификатор представления, напр. XXXX.
          $VIEW_ID = "119240817";
  
          return $VIEW_ID;
      }
15479603   Alex Savenko   initialize
85
  }