Example #1
0
 public function process()
 {
     $date = $this->ga->getDates();
     $beforeDate = $this->ga->getDates('Y-m-d', true);
     $url = $this->ga->buildUrl($date['begin'], $date['end'], array('ga:date'), $this->metrics);
     $cacheKey = md5($this->ga->cacheKey);
     $fromCache = $this->modx->cacheManager->get($cacheKey);
     if (!empty($fromCache)) {
         return $this->success('Fetched data from cache', $fromCache);
     }
     if (!$this->ga->loadOAuth()) {
         return $this->failure('Could not load the OAuth file.');
     }
     if (!$this->ga->getReport($url)) {
         return $this->failure($this->ga->getOutput());
     }
     $this->addSerie();
     // Get the second area for comparion
     $url = $this->ga->buildUrl($beforeDate['begin'], $beforeDate['end'], array('ga:date'), $this->metrics);
     if (!$this->ga->getReport($url)) {
         return $this->failure($this->ga->getOutput());
     }
     $this->addSerie(true);
     $this->modx->cacheManager->set($cacheKey, $this->series, $this->ga->getOption('cache_timeout'));
     return $this->success('Fetched data from Google', $this->series);
 }
Example #2
0
 public function process()
 {
     $date = $this->ga->getDates();
     $url = $this->ga->buildUrl($date['begin'], $date['end'], array('ga:date'), $this->metrics, array('-ga:visits'));
     $cacheKey = $this->ga->cacheKey;
     $fromCache = $this->modx->cacheManager->get($cacheKey);
     if (!empty($fromCache)) {
         return $this->success('Fetched data from cache', $fromCache, true);
     }
     if (!$this->ga->loadOAuth()) {
         return $this->failure('Could not load the OAuth file.');
     }
     if (!$this->ga->getReport($url)) {
         return $this->failure($this->ga->getOutput());
     }
     $this->formatData();
     $date = $this->ga->getDates('Y-m-d', true);
     $url = $this->ga->buildUrl($date['begin'], $date['end'], null, $this->metrics, array('-ga:visits'));
     if (!$this->ga->getReport($url)) {
         return $this->failure($this->ga->getOutput());
     }
     $this->compareData();
     $this->modx->cacheManager->set($cacheKey, $this->output, $this->ga->getOption('cache_timeout'));
     return $this->success('Fetched data from Google', $this->output);
 }
Example #3
0
 public function process()
 {
     $date = $this->ga->getDates();
     $url = $this->ga->buildUrl($date['begin'], $date['end'], $this->dimensions, $this->metrics, $this->sort);
     $cacheKey = $this->ga->cacheKey;
     $fromCache = $this->modx->cacheManager->get($cacheKey);
     if (!empty($fromCache)) {
         return $this->success('Fetched data from cache', $fromCache, true);
     }
     if (!$this->ga->loadOAuth()) {
         return $this->failure('Could not load the OAuth file.');
     }
     if (!$this->ga->getReport($url)) {
         return $this->failure($this->ga->getOutput());
     }
     $this->addSerie();
     $this->modx->cacheManager->set($cacheKey, $this->series, $this->ga->getOption('cache_timeout'));
     return $this->success('Fetched data from Google', $this->series);
 }
Example #4
0
 public function process()
 {
     $date = $this->ga->getDates();
     $url = $this->ga->buildUrl($date['begin'], $date['end'], $this->dimension, $this->metrics, array('-ga:visits'), $this->filters, $this->limit);
     $cacheKey = $this->ga->cacheKey;
     $fromCache = $this->modx->cacheManager->get($cacheKey);
     if (!empty($fromCache)) {
         return $this->success('Fetched data from cache', $fromCache, true);
     }
     if (!$this->ga->loadOAuth()) {
         return $this->failure('Could not load the OAuth file.');
     }
     if (!$this->ga->getReport($url)) {
         return $this->failure($this->ga->getOutput());
     }
     $this->visits = $this->ga->getTotalVisits($date['begin'], $date['end']);
     $response = $this->iterate();
     $this->modx->cacheManager->set($cacheKey, $response, $this->ga->getOption('cache_timeout'));
     return $this->success('Fetched data from Google', $response);
 }
Example #5
0
    public function render()
    {
        $this->bigbrother = new BigBrother($this->modx);
        // Make sure we have a valid access token _before_ showing the widget
        $this->bigbrother->createAuthHeader();
        $this->modx->controller->addCss($this->bigbrother->config['css_url'] . 'dashboard.css');
        //jQuery + charts class
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/jquery.min.js');
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/highcharts.js');
        //Basic reusable panels
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/classes.js');
        $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'mgr/lib/charts.js');
        $account = $this->bigbrother->getOption('account');
        if ($account == null) {
            $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'dashboard/notlogged.js');
        } else {
            $this->modx->controller->addJavascript($this->bigbrother->config['assets_url'] . 'dashboard/dashboard.js');
        }
        $date = $this->bigbrother->getDates('d M Y');
        /** @var $page modAction */
        $page = $this->modx->getObject('modAction', array('namespace' => 'bigbrother', 'controller' => 'index'));
        $url = $this->bigbrother->getManagerLink() . '?a=' . $page->get('id');
        $this->modx->controller->addHtml('<script type="text/javascript">
    BigBrother.RedirectUrl = "' . $url . '";
    BigBrother.ConnectorUrl = "' . $this->bigbrother->config['connector_url'] . '";
    BigBrother.DateBegin = "' . $date['begin'] . '";
    BigBrother.DateEnd = "' . $date['end'] . '";
    BigBrother.account = "' . $this->bigbrother->getOption('account') . '";
    BigBrother.accountName = "' . $this->bigbrother->getOption('account_name') . '";
    Ext.applyIf(MODx.lang, ' . $this->modx->toJSON($this->modx->lexicon->loadCache('bigbrother', 'dashboard')) . ');
    Ext.onReady(function() {
        MODx.load({
            xtype: "bb-panel"
            ,user: "******" // Not needed, yet ?
        });
    });
</script>');
        return '<div id="bb-panel"></div>';
    }