public static function updateFabricante() { $FabricanteTO = new FabricanteTO(); $FabricanteDao = new FabricanteDao(); $FabricanteTO->nome_fabricante = isset($_POST['nome_fabricante']) ? $_POST['nome_fabricante'] : ''; $FabricanteTO->id = isset($_POST['id']) ? $_POST['id'] : ''; $validator = new DataValidator(); $validator->set_msg('O nome do Fabricante é obrigatório')->set('nome_fabricante', $FabricanteTO->nome_fabricante)->is_required(); $validator->set_msg('O codigo do Fabricante é obrigatório')->set('id', $FabricanteTO->id)->is_required(); if (!$validator->validate()) { Flight::response()->status(406)->header('Content-Type', 'application/json')->write(json_encode($validator->get_errors()))->send(); return; } $empreendimentosAssociados = $_POST['empreendimentos']; if ($FabricanteDao->updateFabricante($FabricanteTO)) { if (!$FabricanteDao->removeEmpreendimentos($FabricanteTO->id)) { Flight::halt(500, 'Erro ao remover empreendimentos associados'); } else { foreach ($empreendimentosAssociados as $key => $empreendimento) { if (!$FabricanteDao->associarEmpreendimento($FabricanteTO->id, $empreendimento['id'])) { Flight::halt(500, 'Erro ao associar empreendimento'); } } } Flight::halt(200, ''); } else { Flight::halt(500, 'Erro ao atualizar dados'); } }
public static function requestUpdateFabricante() { try { $fabricante = $_POST['fabricante']; $id_empreendimento = $_POST['id_empreendimento']; $ReferenciaIntegracaoDao = new ReferenciaIntegracaoDao(); $ReferenciaIntegracaoTO = new ReferenciaIntegracaoTO(); $ReferenciaIntegracaoTO->sistema_integrado = 'PrestaShop'; $ReferenciaIntegracaoTO->tabela = 'tbl_fabricante'; $ReferenciaIntegracaoTO->id_item_referencia = $fabricante['id']; $ReferenciaIntegracaoTO->tipo = 'fabricante'; $ReferenciaIntegracaoTO->id_empreendimento = $id_empreendimento; $referencia = $ReferenciaIntegracaoDao->refExists($ReferenciaIntegracaoTO, true); if ($referencia) { $FabricanteTO = new FabricanteTO(); $FabricanteDao = new FabricanteDao(); $ReferenciaIntegracaoDao = new ReferenciaIntegracaoDao(); $FabricanteTO->id = $referencia['id_item']; $FabricanteTO->nome_fabricante = $fabricante['name']; $FabricanteTO->id_empreendimento = $id_empreendimento; if (!$FabricanteDao->updateFabricante($FabricanteTO)) { throw new Exception('Erro ao atualizar fabricante', 1); } } else { self::requestSaveFabricante(); return; //throw new Exception('Não existe uma referencia para p fabricante #'.$fabricante['id'], 1); } } catch (Exception $e) { $log = new KLogger("logs/logErrorPrestaShop.txt", KLogger::DEBUG); $log->LogError($e->getMessage() . ' - line:' . $e->getLine()); $log->LogDebug(json_encode($_POST)); $log->LogJunp(); Flight::halt(500, $e->getMessage()); } }