<?php

App::uses('AppController', 'Controller');
App::uses('ApiHelper', 'View/Helper');

/**
 * Calls Controller
 *
 * @property Call $Call
 */
class ApiController extends AppController {

    public $helpers = array(
        'Api',
    );
    public $components = array(
        'Session',
    );

    /**
     * Retorna o filtro de filas
     */
    public function getDashboardFilter($dashboard, $type) {

        if ($this->Session->read($dashboard . '_' . $type) == '') {
            $this->loadModel('ReportFilter');
            $this->ReportFilter->recursive = -1;
            $report = $this->ReportFilter->findByUserIdAndReportAndFilterType(
                    $this->Auth->user('id'), $dashboard, $type);
            $this->Session->write($dashboard . '_' . $type, $report['ReportFilter']['value']);
        }
        return $this->Session->read($dashboard . '_' . $type);
    }

    /**
     * Retorna o filtro de ramais em formato array
     */
    public function explodeDashboardFilters($dashboard, $type) {
        if ($this->getDashboardFilter($dashboard, $type) == '') {
            return array();
        }
        return explode(' ', $this->getDashboardFilter($dashboard, $type));
    }

    /**
     * Mostra o sql da consulta realizada
     */
    public function showsql($object) {
        $log = $object->getDataSource()->getLog(false, false);
        debug($log);
    }

}
