1 line
No EOL
5.5 KiB
PHP
1 line
No EOL
5.5 KiB
PHP
<?php
|
|
/**
|
|
* Classe CallsUsers.class.php
|
|
* @filesource
|
|
* @autor Kenio de Souza
|
|
* @copyright Copyright 2022 - Souza Consultoria Tecnológica
|
|
* @package vendor
|
|
* @subpackage model
|
|
* @version 1.0
|
|
* @date 09/03/2022
|
|
*/
|
|
|
|
/** Defino o local onde esta a classe */
|
|
namespace vendor\model;
|
|
|
|
class CallsUsers
|
|
{
|
|
/** Declaro as vaiavéis da classe */
|
|
private $connection = null;
|
|
private $sql = null;
|
|
private $stmt = null;
|
|
private $callUserId = null;
|
|
private $callId = null;
|
|
private $userId = null;
|
|
private $companyId = null;
|
|
private $history = null;
|
|
|
|
/** Construtor da classe */
|
|
function __construct()
|
|
{
|
|
/** Cria o objeto de conexão com o banco de dados */
|
|
$this->connection = new Mysql();
|
|
}
|
|
|
|
/** Lista os registros do banco de dados com limitação */
|
|
public function Get(int $callUserId)
|
|
{
|
|
|
|
/** Parametros de entrada */
|
|
$this->callUserId = $callUserId;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'select * from calls_users
|
|
where call_user_id = :call_user_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_user_id', $this->callUserId);
|
|
|
|
/** 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_users cu
|
|
join users u on cu.user_id = u.users_id
|
|
where cu.call_id = :callId and cu.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);
|
|
|
|
}
|
|
|
|
/** Lista todos os egistros do banco com ou sem paginação*/
|
|
public function AllAvailable(int $callId, int $companyId, int $callActivityId)
|
|
{
|
|
|
|
/** Parâmetros de entrada */
|
|
$this->callId = $callId;
|
|
$this->companyId = $companyId;
|
|
$this->callActivityId = $callActivityId;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'select * from calls_users cu
|
|
join users u on cu.user_id = u.users_id
|
|
where user_id not in (select user_id from calls_activities_users where call_activity_id = :callActivityId)
|
|
and cu.call_id = :callId and cu.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);
|
|
$this->stmt->bindParam('callActivityId', $this->callActivityId);
|
|
|
|
/** Executo o SQL */
|
|
$this->stmt->execute();
|
|
|
|
/** Retorno o resultado */
|
|
return $this->stmt->fetchAll(\PDO::FETCH_OBJ);
|
|
|
|
}
|
|
|
|
/** Insere um novo registro no banco */
|
|
public function Save(int $callUserId, string $callId, string $userId, string $companyId, string $history)
|
|
{
|
|
|
|
|
|
/** Parametros */
|
|
$this->callUserId = $callUserId;
|
|
$this->callId = $callId;
|
|
$this->userId = $userId;
|
|
$this->companyId = $companyId;
|
|
$this->history = $history;
|
|
|
|
|
|
/** Verifica se o ID do registro foi informado */
|
|
if($this->callUserId > 0){
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'update calls_users set call_id = :call_id,
|
|
user_id = :user_id,
|
|
company_id = :company_id,
|
|
history = :history
|
|
where call_user_id = :call_user_id';
|
|
|
|
}else{//Se o ID não foi informado, grava-se um novo registro
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'insert into calls_users(call_user_id,
|
|
call_id,
|
|
user_id,
|
|
company_id,
|
|
history
|
|
) values (:call_user_id,
|
|
:call_id,
|
|
:user_id,
|
|
:company_id,
|
|
: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_user_id', $this->callUserId);
|
|
$this->stmt->bindParam('call_id', $this->callId);
|
|
$this->stmt->bindParam('user_id', $this->userId);
|
|
$this->stmt->bindParam('company_id', $this->companyId);
|
|
$this->stmt->bindParam('history', $this->history);
|
|
|
|
/** Executo o SQL */
|
|
return $this->stmt->execute();
|
|
|
|
}
|
|
|
|
/** Deleta um determinado registro no banco de dados */
|
|
function Delete(int $callUserId)
|
|
{
|
|
/** Parametros de entrada */
|
|
$this->callUserId = $callUserId;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'delete from calls_users
|
|
where call_user_id = :call_user_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_user_id', $this->callUserId);
|
|
|
|
/** Executo o SQL */
|
|
return $this->stmt->execute();
|
|
|
|
}
|
|
|
|
/** Fecha uma conexão aberta anteriormente com o banco de dados */
|
|
function __destruct()
|
|
{
|
|
$this->connection = null;
|
|
}
|
|
}
|