api_monitor/vendor/model/Backup.class.php

272 lines
6.5 KiB
PHP

<?php
/**
* Classe Backup.class.php
* @filesource
* @autor Kenio de Souza
* @copyright Copyright 2024 - Souza Consultoria Tecnológica
* @package vendor
* @subpackage model
* @version 1.0
* @date 10/08/2024
*/
/** Defino o local onde esta a classe */
namespace vendor\model;
class Backup
{
/** 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 $backupId = null;
private $clientId = null;
private $file = null;
private $fileDate = null;
private $fileHour = null;
private $period = null;
private $day = null;
private $size = null;
private $path = null;
private $dateRegister = null;
private $field = null;
private $stationId = 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 backup";
/** 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 $backupId)
{
/** Parametros de entrada */
$this->backupId = $backupId;
/** Consulta SQL */
$this->sql = 'select * from backup
where backup_id = :backup_id';
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam(':backup_id', $this->backupId);
/** Executo o SQL */
$this->stmt->execute();
/** Retorno o resultado */
return $this->stmt->fetchObject();
}
/** Consulta um arquivo pelo nome */
public function Search(int $clientId, string $file)
{
/** Parametros de entrada */
$this->clientId = $clientId;
$this->file = $file;
/** Consulta SQL */
$this->sql = 'select * from backup
where client_id = :client_id
and file = :file';
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam(':backup_id', $this->backupId);
$this->stmt->bindParam(':client_id', $this->clientId);
/** 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 $clientId, int $stationId)
{
/** Parametros de entrada */
$this->clientId = $clientId;
$this->stationId = $stationId;
/** Consulta SQL */
$this->sql = 'select * from backup
where client_id = :client_id
and station_id = :station_id';
/** Preparo o SQL para execução */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam(':client_id', $this->clientId);
$this->stmt->bindParam(':station_id', $this->stationId);
/** 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(backup_id) as qtde
from backup ';
/** 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 $clientId,
int $stationId,
string $file,
string $fileDate,
string $fileHour,
string $period,
string $day,
string $size,
string $path)
{
/** Parametros */
$this->clientId = $clientId;
$this->stationId = $stationId;
$this->file = $file;
$this->fileDate = $fileDate;
$this->fileHour = $fileHour;
$this->period = $period;
$this->day = $day;
$this->size = $size;
$this->path = $path;
/** Consulta SQL */
$this->sql = 'insert into backup(client_id,
station_id,
file,
file_date,
file_hour,
period,
day,
size,
path
) values (:client_id,
:station_id,
:file,
:file_date,
:file_hour,
:period,
:day,
:size,
:path)';
/** Preparo o sql para receber os valores */
$this->stmt = $this->connection->connect()->prepare($this->sql);
/** Preencho os parâmetros do SQL */
$this->stmt->bindParam('client_id', $this->clientId);
$this->stmt->bindParam('station_id', $this->stationId);
$this->stmt->bindParam('file', $this->file);
$this->stmt->bindParam('file_date', $this->fileDate);
$this->stmt->bindParam('file_hour', $this->fileHour);
$this->stmt->bindParam('period', $this->period);
$this->stmt->bindParam('day', $this->day);
$this->stmt->bindParam('size', $this->size);
$this->stmt->bindParam('path', $this->path);
/** Executo o SQL */
return $this->stmt->execute();
}
/** Deleta um determinado registro no banco de dados */
function Delete(int $clientId, $stationId)
{
/** Parametros de entrada */
$this->clientId = $clientId;
$this->stationId = $stationId;
/** Consulta SQL */
$this->sql = 'delete from backup
where client_id = :client_id
and station_id = :station_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('client_id', $this->clientId);
$this->stmt->bindParam('station_id', $this->stationId);
/** Executo o SQL */
return $this->stmt->execute();
}
/** Fecha uma conexão aberta anteriormente com o banco de dados */
function __destruct()
{
$this->connection = null;
}
}