forked from Claudio/integracao
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
108 lines
3.7 KiB
108 lines
3.7 KiB
2 years ago
|
<?php
|
||
|
|
||
|
require_once 'Integracao.php';
|
||
|
require_once "util/Conexao.php";
|
||
|
include "config.php";
|
||
|
|
||
|
/**
|
||
|
* Classe para consultas no banco de dados King Dialer
|
||
|
* -> Banco de dados MySQL
|
||
|
* @author Lucas Awade
|
||
|
* @function developer
|
||
|
* @company SimplesIP
|
||
|
* @version 1.0.0
|
||
|
*/
|
||
|
class KingDialerModel extends Integracao {
|
||
|
|
||
|
private $condb;
|
||
|
private $debug;
|
||
|
|
||
|
########################################################################
|
||
|
## QUERYS DE MYSQL ##
|
||
|
########################################################################
|
||
|
|
||
|
public function buscarContatosPorTelefone($telefone) {
|
||
|
$this->debug = debug_backtrace();
|
||
|
if ($this->getArgs(func_get_args())) {
|
||
|
$query = "SELECT * FROM campanha_contatos WHERE numero = '{$telefone}' AND calldate = '0000-00-00 00:00:00';";
|
||
|
return $this->response($this->mysql_exec($query));
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#########################################################################
|
||
|
## FUNCOES DEFAULT DA CLASSE ##
|
||
|
########################################################################
|
||
|
|
||
|
/**
|
||
|
* Coleta as informacoes iniciais para o inicio da integracao com a API.
|
||
|
*
|
||
|
* @param string $token
|
||
|
* @param string $url
|
||
|
* @param boolean $log
|
||
|
*/
|
||
|
public function __construct() {
|
||
|
$data = $this->db()->getConexaoAPI(CONF_ID_CREDENCIAIS);
|
||
|
$this->setLog(CONF_LOGGER_ATIVO);
|
||
|
|
||
|
if ($data['url'] && $data['id_user'] && $data['token']) {
|
||
|
$this->condb = $this->connectMysql($data);
|
||
|
} else {
|
||
|
$this->log->info("Os dados informados para " . __CLASS__ . " estao incompletos!", debug_backtrace());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Cria uma conexao com a base de dados do king
|
||
|
* @throws Exception
|
||
|
*/
|
||
|
private function connectMysql($data) {
|
||
|
if ($data) {
|
||
|
$link = mysql_connect($data['url'], $data['user'], $data['password']);
|
||
|
if (!$link) {
|
||
|
$this->log->error("Nao foi possivel conectar no banco de dados. MySQLError: " . mysql_error(), debug_backtrace());
|
||
|
return false;
|
||
|
}
|
||
|
mysql_select_db($data['token'], $link);
|
||
|
}
|
||
|
if (mysql_error()) {
|
||
|
$this->log->error("Nao foi possivel conectar no banco de dados. MySQLError: " . mysql_error(), debug_backtrace());
|
||
|
return false;
|
||
|
}
|
||
|
return $link;
|
||
|
}
|
||
|
|
||
|
private function mysql_exec($query, $type = 'ASSOC') {
|
||
|
$result = mysql_query($query);
|
||
|
if ($result && $type) {
|
||
|
switch (strtoupper($type)) {
|
||
|
case 'ASSOC':
|
||
|
return mysql_fetch_assoc($result);
|
||
|
case 'ALL':
|
||
|
$data = array();
|
||
|
while ($dados = mysql_fetch_array($result)) {
|
||
|
$data[] = $dados;
|
||
|
}
|
||
|
return $data;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Prepara dos dados para serem transmitidos para o metodo a serem retornados a
|
||
|
* integracao.
|
||
|
*
|
||
|
* @return array
|
||
|
*/
|
||
|
private function response($data) {
|
||
|
$this->log->debug("Reponse API: " . print_r($data, true), $this->debug);
|
||
|
if ($data) {
|
||
|
return $data;
|
||
|
} else {
|
||
|
return false;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|