connection = new Mysql(); } /** Carrega os campos de uma tabela */ public function Describe() { /** Consulta SQL */ $this->sql = "describe calls_activities"; /** 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 $callActivityId) { /** Parametros de entrada */ $this->callActivityId = $callActivityId; /** Consulta SQL */ $this->sql = 'select * from calls_activities where call_activity_id = :call_activity_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_activity_id', $this->callActivityId); /** 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_activities ca where ca.call_id = :callId and ca.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_activity_id) as qtde from calls_activities '; /** 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 $callActivityId, int $callId, int $companyId, string $name, string $description, string $dateExpected, string $history) { /** Parametros */ $this->callActivityId = $callActivityId; $this->callId = $callId; $this->companyId = $companyId; $this->name = $name; $this->description = $description; $this->dateExpected = $dateExpected; $this->history = $history; /** Verifica se o ID do registro foi informado */ if($this->callActivityId > 0){ /** Consulta SQL */ $this->sql = 'update calls_activities set call_id = :call_id, company_id = :company_id, name = :name, description = :description, date_expected = :date_expected, history = :history where call_activity_id = :call_activity_id'; }else{//Se o ID não foi informado, grava-se um novo registro /** Consulta SQL */ $this->sql = 'insert into calls_activities(call_activity_id, call_id, company_id, name, description, date_expected, history ) values (:call_activity_id, :call_id, :company_id, :name, :description, :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_id', $this->callActivityId); $this->stmt->bindParam('call_id', $this->callId); $this->stmt->bindParam('company_id', $this->companyId); $this->stmt->bindParam('name', $this->name); $this->stmt->bindParam('description', $this->description); $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 SaveClose(int $callActivityId, int $callId, string $dateClose, string $history) { /** Parametros */ $this->callActivityId = $callActivityId; $this->callId = $callId; $this->dateClose = $dateClose; $this->history = $history; /** Consulta SQL */ $this->sql = 'update calls_activities set date_close = :date_close, history = :history where call_activity_id = :call_activity_id and call_id = :call_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); $this->stmt->bindParam('call_id', $this->callId); $this->stmt->bindParam('date_close', $this->dateClose); $this->stmt->bindParam('history', $this->history); /** 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 where call_activity_id = :call_activity_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; } }