myadmin/vendor/model/CallsDrafts.class.php
2025-07-03 13:11:29 -03:00

1 line
No EOL
6.7 KiB
PHP

<?php
/**
* Classe CallsDrafts.class.php
* @filesource
* @autor Kenio de Souza
* @copyright Copyright 2022 - Souza Consultoria Tecnológica
* @package vendor
* @subpackage model
* @version 1.0
* @date 01/04/2022
*/
/** Defino o local onde esta a classe */
namespace vendor\model;
class CallsDrafts
{
/** Declaro as vaiavéis da classe */
private $connection = null;
private $sql = null;
private $stmt = null;
private $start = null;
private $max = null;
private $limit = null;
private $callDraftId = null;
private $callId = null;
private $draftId = null;
private $companyId = null;
private $text = null;
private $history = null;
/** Construtor da classe */
function __construct()
{
/** Cria o objeto de conexão com o banco de dados */
$this->connection = new Mysql();
}
/** Carrega os campos de uma tabela */
public function Describe()
{
/** Consulta SQL */
$this->sql = "describe calls_drafts";
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Executo o SQL */
$this->stmt->execute();
/** Retorno o resultado */
$this->field = $this->stmt->fetchAll(\PDO::FETCH_OBJ);
/** Declara o objeto */
$resultDescribe = new \stdClass();
$Field = '';
/** Lista os campos da tabela para objetos */
foreach($this->field as $UsersKey => $Result){
/** Pega o nome do Field/Campo */
$Field = $Result->Field;
/** Carrega os objetos como null */
$resultDescribe->$Field = null;
}
/** Retorna os campos declarados como vazios */
return $resultDescribe;
}
/** Lista os registros do banco de dados com limitação */
public function Get(int $callDraftId)
{
/** Parametros de entrada */
$this->callDraftId = $callDraftId;
/** Consulta SQL */
$this->sql = 'select * from calls_drafts
where call_draft_id = :call_draft_id';
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam(':call_draft_id', $this->callDraftId);
/** Executo o SQL */
$this->stmt->execute();
/** Retorno o resultado */
return $this->stmt->fetchObject();
}
/** Lista todos os egistros do banco com ou sem paginação*/
public function All(int $callId, int $companyId)
{
/** Parâmetros de entrada */
$this->callId = $callId;
$this->companyId = $companyId;
/** Consulta SQL */
$this->sql = 'select * from calls_drafts cd
left join drafts d on cd.draft_id = d.draft_id
where cd.call_id = :callId and cd.company_id = :companyId';
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('callId', $this->callId);
$this->stmt->bindParam('companyId', $this->companyId);
/** Executo o SQL */
$this->stmt->execute();
/** Retorno o resultado */
return $this->stmt->fetchAll(\PDO::FETCH_OBJ);
}
/** Conta a quantidades de registros */
public function Count()
{
/** Consulta SQL */
$this->sql = 'select count(call_draft_id) as qtde
from calls_drafts ';
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Executo o SQL */
$this->stmt->execute();
/** Retorno o resultado */
return $this->stmt->fetchObject()->qtde;
}
/** Insere um novo registro no banco */
public function Save(int $callDraftId, string $callId, string $draftId, string $companyId, string $text, string $history)
{
/** Parametros */
$this->callDraftId = $callDraftId;
$this->callId = $callId;
$this->draftId = $draftId;
$this->companyId = $companyId;
$this->text = $text;
$this->history = $history;
/** Verifica se o ID do registro foi informado */
if($this->callDraftId > 0){
/** Consulta SQL */
$this->sql = 'update calls_drafts set call_id = :call_id,
draft_id = :draft_id,
company_id = :company_id,
text = :text,
history = :history
where call_draft_id = :call_draft_id';
}else{//Se o ID não foi informado, grava-se um novo registro
/** Consulta SQL */
$this->sql = 'insert into calls_drafts(call_draft_id,
call_id,
draft_id,
company_id,
text,
history
) values (:call_draft_id,
:call_id,
:draft_id,
:company_id,
:text,
:history)';
}
/** Preparo o sql para receber os valores */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('call_draft_id', $this->callDraftId);
$this->stmt->bindParam('call_id', $this->callId);
$this->stmt->bindParam('draft_id', $this->draftId);
$this->stmt->bindParam('company_id', $this->companyId);
$this->stmt->bindParam('text', $this->text);
$this->stmt->bindParam('history', $this->history);
/** Executo o SQL */
return $this->stmt->execute();
}
/** Insere um novo registro no banco */
public function SaveText(int $callDraftId, string $text, string $history)
{
/** Parametros */
$this->callDraftId = $callDraftId;
$this->text = $text;
$this->history = $history;
/** Consulta SQL */
$this->sql = 'update calls_drafts set text = :text,
history = :history
where call_draft_id = :call_draft_id';
/** Preparo o sql para receber os valores */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('call_draft_id', $this->callDraftId);
$this->stmt->bindParam('text', $this->text);
$this->stmt->bindParam('history', $this->history);
/** Executo o SQL */
return $this->stmt->execute();
}
/** Deleta um determinado registro no banco de dados */
function Delete(int $callDraftId)
{
/** Parametros de entrada */
$this->callDraftId = $callDraftId;
/** Consulta SQL */
$this->sql = 'delete from calls_drafts
where call_draft_id = :call_draft_id';
/** Preparo o sql para receber os valores */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('call_draft_id', $this->callDraftId);
/** Executo o SQL */
return $this->stmt->execute();
}
/** Fecha uma conexão aberta anteriormente com o banco de dados */
function __destruct()
{
$this->connection = null;
}
}