connection = new Mysql(); } /** Carrega os campos de uma tabela */ public function Describe() { /** Consulta SQL */ $this->sql = "describe calls_messages"; /** 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 $callMesageId) { /** Parametros de entrada */ $this->callMesageId = $callMesageId; /** Consulta SQL */ $this->sql = 'select * from calls_messages where call_mesage_id = :call_mesage_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_mesage_id', $this->callMesageId); /** 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 $callMessageId, int $callId, int $companyId) { /** Parametros de entrada */ $this->callMesageId = $callMessageId; $this->companyId = $companyId; $this->callId = $callId; /** Consulta SQL */ $this->sql = 'select * from calls_messages cm join users u on cm.user_id = u.users_id where cm.call_mesage_id > :callMessageId and cm.company_id = :companyId and cm.call_id = :callId'; /** Preparo o SQL para execução */ $this->stmt = $this->connection->connect()->prepare($this->sql); /** Preencho os parâmetros do SQL */ $this->stmt->bindParam('callMessageId', $this->callMesageId); $this->stmt->bindParam('companyId', $this->companyId); $this->stmt->bindParam('callId', $this->callId); /** 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_mesage_id) as qtde from calls_messages '; /** 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 $callMesageId, int $callId, int $userId, int $companyId, string $text, string $date, string $history) { /** Parametros */ $this->callMesageId = $callMesageId; $this->callId = $callId; $this->userId = $userId; $this->companyId = $companyId; $this->text = $text; $this->date = $date; $this->history = $history; /** Consulta SQL */ $this->sql = 'insert into calls_messages(call_mesage_id, call_id, user_id, company_id, text, date, history ) values (:call_mesage_id, :call_id, :user_id, :company_id, :text, :date, :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_mesage_id', $this->callMesageId); $this->stmt->bindParam('call_id', $this->callId); $this->stmt->bindParam('user_id', $this->userId); $this->stmt->bindParam('company_id', $this->companyId); $this->stmt->bindParam('text', $this->text); $this->stmt->bindParam('date', $this->date); $this->stmt->bindParam('history', $this->history); /** Executo o SQL */ return $this->stmt->execute(); } /** Deleta um determinado registro no banco de dados */ function Delete(int $callMesageId) { /** Parametros de entrada */ $this->callMesageId = $callMesageId; /** Consulta SQL */ $this->sql = 'delete from calls_messages where call_mesage_id = :call_mesage_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_mesage_id', $this->callMesageId); /** Executo o SQL */ return $this->stmt->execute(); } /** Fecha uma conexão aberta anteriormente com o banco de dados */ function __destruct() { $this->connection = null; } }