Skip to content

Commit

Permalink
feat: insert Cliente changes in DB
Browse files Browse the repository at this point in the history
  • Loading branch information
elfiservice committed Apr 18, 2018
1 parent 1bff48b commit e714fd1
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 22 deletions.
11 changes: 3 additions & 8 deletions classes/controller/CRUDAbstractCtrl.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ abstract class CRUDAbstractCtrl {
//put your code here

/**
* Fazer INSERT no BD na tabela = logs
* @param Log $obj = passar uma Instancia deste tipo para inserir no BD
* Fazer INSERT no BD
* @param Object $obj = passar uma Instancia de um Objeto para inserir no BD
* @return boolean = TRUE se Sucesso ao inserir dados no BD e FALSE se houver algum problema na INSERÇÃO ou se o OBJETO não foi passado corretamente
*/
public function inserirBD($obj, $dao) {
Expand All @@ -22,16 +22,11 @@ public function inserirBD($obj, $dao) {
$campo = str_replace("\0{$nomeDaClasse}\0", "", $campo);
$campoArr[$campo] = $campo;
}
// var_dump($campoArr);
//unset($campoArr['id']);
$arrObj = array_values((array) $obj);

//unset($arrObj[0]);
$arrObj = array_values((array) $obj);

$campoArr = implode(', ', array_keys($campoArr));
$valores = " '" . implode("','", array_values($arrObj)) . "' ";
//var_dump($campoArr,$valores);
//$logDao = new LogDAO();

if ($dao->insert($campoArr, $valores)) {
return TRUE;
Expand Down
9 changes: 6 additions & 3 deletions classes/controller/ClienteCtrl.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,13 @@ public function atualizarCliente(Array $dados, Array $dadosClienteAntigoObj) {
//checa qualis Dados Mudarão para salvar no Log do sistema
$stringDadosAlterados = $this->registrarAlteracao($arrayFilha, $dadosClienteAntigoObj);

//ToDo: Salvar Dados Alterados em uma tabela de Historico Clientes.

if ($this->atualizarBD($arrayFilha[0][0])) {
LogCtrl::inserirLog($dados['id_colab_logado'], "Cliente Cod <b>{$dados['id']}</b> <b><span>Alterado</span></b> no Sistema:<br>{$stringDadosAlterados}", "tec");
$idColab = $dados['id'];
$alteracaoCliente = "<b><span>Alterado</span></b> no Sistema:<br>{$stringDadosAlterados}";
LogCtrl::inserirLog($dados['id_colab_logado'], "Cliente Cod <b>{$idColab}</b> {$alteracaoCliente}", "tec");

$this->historicoClienteCtrl->inserirBD(new HistoricoClientes("", $idColab, $alteracaoCliente, date('Y-m-d H:i:s')));

$this->result = array("<b>OK!</b> Cliente <b>Atualizado</b> com sucesso.", WS_ACCEPT);
return TRUE;
} else {
Expand Down
29 changes: 20 additions & 9 deletions classes/controller/HistoricoClientesCtrl.class.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

/**
* Description of HistoricoClientes
*
Expand All @@ -15,12 +9,29 @@ class HistoricoClientesCtrl extends CRUDAbstractCtrl {

private $clienteDao;

public function HistoricoClientes() {
public function HistoricoClientesCtrl() {
$this->clienteDao = new HistoricoClientesDAO();
}

public function inserirBD($obj) {
return parent::inserirBD($obj, $this->clienteDao);
public function inserirBD($obj, $dao = null) {
$daoResult = $this->clienteDao;
if($dao) {
$daoResult = $dao;
}
return parent::inserirBD($obj, $daoResult);
}

//--------------------------------------------------
//----------------PRIVATES---------------------
//--------------------------------------------------
private function montarObjeto($arrayDados) {
$arrayObj = array();
foreach ($arrayDados as $dado) {
extract($dado);
$arrayObj[] = new HistoricoClientes($id, $id_cliente, $alteracao, $data);
}

return $arrayObj;
}

}
2 changes: 0 additions & 2 deletions classes/model/HistoricoClientes.class.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<?php
echo 'aqui';

/**
* HistoricoClientes.class [ MODEL ]
* Modelar dados da Tablea historico_clientes
Expand Down

0 comments on commit e714fd1

Please sign in to comment.