ModelsDelete.php 1.55 KB
<?php

class ModelsDelete extends ModelsConn {

    private $tabela;
    private $termos;
    private $values;
    private $result;
    private $msg;
    private $query;
    private $conn;
    
    public function exeDelete($tabela, $termos, $parseString) {
        $this->tabela = (string) $tabela;
        $this->termos = (string) $termos;
        
        parse_str($parseString, $this->values);
        
        $this->getInstrucao();
        $this->executarInstrucao();
    }
    
    public function getResult() {
        return $this->result;
    }
    
    public function getMsg() {
        return $this->msg;
    }
    
    public function getRowCount() {
        return $this->query->rowCount();
    }
    
    private function conexao() {
        $this->conn = parent::getConn();
        $this->query = $this->conn->prepare($this->query);
    }
    
    private function getInstrucao() {
        $this->query = "DELETE FROM {$this->tabela} {$this->termos}";
    }
    
    private function executarInstrucao() {
        $this->conexao();
        try {
            $this->query->execute($this->values);
            $this->result = true;
            $this->msg = "<div class=\"alert alert-success\" role=\"alert\">
                              Usuário apagado com sucesso!
                          </div>";
        } catch (Exception $e) {
            $this->result = null;
            $this->msg = "<div class=\"alert alert-danger\" role=\"alert\">
                              Erro ao Apagar</b> {$e->getMessage()}
                          </div>";
        }
    }
}