1 line
No EOL
8.5 KiB
PHP
1 line
No EOL
8.5 KiB
PHP
<?php
|
|
/**
|
|
* Classe CallsActivitiesUsers.class.php
|
|
* @filesource
|
|
* @autor Kenio de Souza
|
|
* @copyright Copyright 2022 - Souza Consultoria Tecnológica
|
|
* @package vendor
|
|
* @subpackage model
|
|
* @version 1.0
|
|
* @date 02/04/2022
|
|
*/
|
|
|
|
|
|
/** Defino o local onde esta a classe */
|
|
namespace vendor\model;
|
|
|
|
class CallsActivitiesUsers
|
|
{
|
|
/** 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 $callActivityUserId = null;
|
|
private $callActivityId = null;
|
|
private $callId = null;
|
|
private $userId = null;
|
|
private $companyId = null;
|
|
private $dateExpected = null;
|
|
private $dateStart = null;
|
|
private $dateClose = 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_activities_users";
|
|
|
|
/** 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 $callAactivityId, int $userId)
|
|
{
|
|
|
|
/** Parametros de entrada */
|
|
$this->callActivityId = $callAactivityId;
|
|
$this->userId = $userId;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'select * from calls_activities_users
|
|
where call_activity_id = :callActivityId and user_id = :userId limit 1';
|
|
|
|
/** Preparo o SQL para execução */
|
|
$this->stmt = $this->connection->connect()->prepare($this->sql);
|
|
|
|
/** Preencho os parâmetros do SQL */
|
|
$this->stmt->bindParam(':callActivityId', $this->callActivityId);
|
|
$this->stmt->bindParam(':userId', $this->userId);
|
|
|
|
/** 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 $callActivityId, int $companyId)
|
|
{
|
|
|
|
/** Parâmetros de entrada */
|
|
$this->callId = $callId;
|
|
$this->callActivityId = $callActivityId;
|
|
$this->companyId = $companyId;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'select * from calls_activities_users cau
|
|
join users u on cau.user_id = u.users_id
|
|
where cau.call_id = :callId and cau.call_activity_id = :callActivityId and cau.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('callActivityId', $this->callActivityId);
|
|
$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_activity_id) as qtde
|
|
from calls_activities_users ';
|
|
|
|
/** 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 $callActivityUserId, int $callActivityId, int $callId, int $userId, int $companyId, string $dateExpected, string $history)
|
|
{
|
|
|
|
/** Parametros */
|
|
$this->callActivityUserId = $callActivityUserId;
|
|
$this->callActivityId = $callActivityId;
|
|
$this->callId = $callId;
|
|
$this->userId = $userId;
|
|
$this->companyId = $companyId;
|
|
$this->dateExpected = $dateExpected;
|
|
$this->history = $history;
|
|
|
|
/** Verifica se o ID do registro foi informado */
|
|
if($this->callActivityUserId > 0){
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'update calls_activities_users set call_activity_id = :call_activity_id,
|
|
user_id = :user_id,
|
|
company_id = :company_id,
|
|
date_expected = :date_expected,
|
|
history = :history
|
|
where call_activity_user_id = :call_activity_user_id';
|
|
|
|
}else{//Se o ID não foi informado, grava-se um novo registro
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'insert into calls_activities_users(call_activity_user_id,
|
|
call_activity_id,
|
|
call_id,
|
|
user_id,
|
|
company_id,
|
|
date_expected,
|
|
history
|
|
) values (:call_activity_user_id,
|
|
:call_activity_id,
|
|
:call_id,
|
|
:user_id,
|
|
:company_id,
|
|
:date_expected,
|
|
: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_activity_user_id', $this->callActivityUserId);
|
|
$this->stmt->bindParam('call_activity_id', $this->callActivityId);
|
|
$this->stmt->bindParam('call_id', $this->callId);
|
|
$this->stmt->bindParam('user_id', $this->userId);
|
|
$this->stmt->bindParam('company_id', $this->companyId);
|
|
$this->stmt->bindParam('date_expected', $this->dateExpected);
|
|
$this->stmt->bindParam('history', $this->history);
|
|
|
|
/** Executo o SQL */
|
|
return $this->stmt->execute();
|
|
|
|
}
|
|
|
|
/** Insere um novo registro no banco */
|
|
public function SaveStart(int $callActivityId, string $userId, string $dateStart)
|
|
{
|
|
|
|
/** Parametros */
|
|
$this->callActivityId = $callActivityId;
|
|
$this->userId = $userId;
|
|
$this->dateStart = $dateStart;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'update calls_activities_users set date_start = :dateStart
|
|
where call_activity_id = :callActivityId and user_id = :userId';
|
|
|
|
/** Preparo o sql para receber os valores */
|
|
$this->stmt = $this->connection->connect()->prepare($this->sql);
|
|
|
|
/** Preencho os parâmetros do SQL */
|
|
$this->stmt->bindParam('callActivityId', $this->callActivityId);
|
|
$this->stmt->bindParam('userId', $this->userId);
|
|
$this->stmt->bindParam('dateStart', $this->dateStart);
|
|
|
|
/** Executo o SQL */
|
|
return $this->stmt->execute();
|
|
|
|
}
|
|
|
|
/** Insere um novo registro no banco */
|
|
public function SaveClose(int $callActivityId, string $userId, string $dateClose)
|
|
{
|
|
|
|
/** Parametros */
|
|
$this->callActivityId = $callActivityId;
|
|
$this->userId = $userId;
|
|
$this->dateClose = $dateClose;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'update calls_activities_users set date_close = :dateClose
|
|
where call_activity_id = :callActivityId and user_id = :userId';
|
|
|
|
/** Preparo o sql para receber os valores */
|
|
$this->stmt = $this->connection->connect()->prepare($this->sql);
|
|
|
|
/** Preencho os parâmetros do SQL */
|
|
$this->stmt->bindParam('callActivityId', $this->callActivityId);
|
|
$this->stmt->bindParam('userId', $this->userId);
|
|
$this->stmt->bindParam('dateClose', $this->dateClose);
|
|
|
|
/** Executo o SQL */
|
|
return $this->stmt->execute();
|
|
|
|
}
|
|
|
|
/** Deleta um determinado registro no banco de dados */
|
|
function Delete(int $callActivityId)
|
|
{
|
|
/** Parametros de entrada */
|
|
$this->callActivityId = $callActivityId;
|
|
|
|
/** Consulta SQL */
|
|
$this->sql = 'delete from calls_activities_users
|
|
where call_activity_user_id = :call_activity_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_activity_id', $this->callActivityId);
|
|
|
|
/** Executo o SQL */
|
|
return $this->stmt->execute();
|
|
|
|
}
|
|
|
|
/** Fecha uma conexão aberta anteriormente com o banco de dados */
|
|
function __destruct()
|
|
{
|
|
$this->connection = null;
|
|
}
|
|
}
|