<?php

class Cms_Cms_StatsController extends Pampa_Controller_Action_Cms {

  /**
   * @var Model_Cms_Stats
   */
  private $modelStats;

  public function init() {
    // the models
    $this->modelStats = new Model_Cms_Stats();

    parent::init();
  }

  public function indexAction() {
    $this->_forward("list");
  }

  public function profileAction() {
    // get the logged user
    $user = Pampa_Auth_Cms::getInstance()->getIdentity();

    // redirect
    $this->redirectTo("cms_user", "edit", array("id" => $user->id));
  }

  public function listAction()
  {
    if (isset($_GET['code']))
    {
      $this->modelStats->auth($_GET['code']);
      $this->redirectTo("cms_stats");
    }

    $mes = ((isset($_GET['month']))? $_GET['month']: null);
    $ano = ((isset($_GET['year']))? $_GET['year']: null);

    $this->view->mes = $mes;
    $this->view->ano = $ano;

    $this->view->results = $this->modelStats->teste($mes, $ano);

    //var_dump($results);
    $this->view->headScript()
        ->appendFile('js/highcharts/highcharts.js', 'text/javascript')
        ->appendFile('js/highcharts/modules/exporting.js', 'text/javascript')
        ->appendFile('js/highcharts/charts.js', 'text/javascript');
  }


}