<?php require_once '../core/generics/Param.php'; require_once '../core/generics/datacenter/Country.php'; require_once '../core/generics/Controller.php'; require_once '../core/generics/GenericDao.php'; $json = new JsonResponse(); $dao = new GenericDao(Connection::connect()); $controller = new Controller($dao); $country_id = $_REQUEST['country']; $object = new Country($_POST['name']); $object->setId($country_id); if (isset($_POST['reexport']) && $_POST['reexport'] == true) { $object->setReexport(); } if ($controller->editCountry($object)) { print_r($json->response(true, "País editado com sucesso!")->serialize()); } else { print_r($json->response(false, "O país não foi editado!")->serialize()); }
if(RequestsPatterns::postParamsSetted('name', 'type')){ if(RequestsPatterns::postParamsSent('name', 'type')){ $name = $_POST['name']; $typeCountry = $_POST['type']; $country = new Country($name); $dao = new GenericDao(Connection::connect()); $controller = new Controller($dao); $message = "País inserido com sucesso"; $message_error = "Falha na inserção do país"; try{ if($typeCountry == 'origin'){ if(isset($_POST['reexport']) && $_POST['reexport'] == true){ $country->setReexport(); } if($controller->createNewOriginCountry($country)){ $countryToCache = $controller->getCountryByName($country,$typeCountry); cacheCountry($countryToCache, $typeCountry); print_r($json->response (true, $message)->serialize ()); }else print_r($json->response (true, $message_error)->serialize ()); }else{ if($controller->createNewDestinyCountry($country)){ $countryToCache = $controller->getCountryByName($country,$typeCountry); cacheCountry($countryToCache, $typeCountry); print_r($json->response (true, $message)->serialize ()); }else print_r($json->response (true, $message_error)->serialize ()); }
private function buildObject($type, $object) { if (isset($object['name'])) { $name = utf8_encode($object['name']); } $id = $object['id']; switch ($type) { case "area": return new Area($object['name'], $object['id']); break; case "subarea": return new SubArea($object['name'], $object['id']); break; case "estados": return new State($object['id'], $object['uf'], $object['nome']); break; case "city": return new City($object['nome'], $object['id']); break; case "activities": return new Activity($object['name'], $object['id']); break; case "publication_type": return new PublicationType($object['name'], $object['id']); break; case "groups": return new Group($name, $id); break; case "subgroup": return new Subgroup($name, $id); break; case "variety": return new Variety($name, $id); break; case "coffetype": return new CoffeType($name, $id); break; case "country": $country = new Country($name, $id); if (isset($object['reexport']) && $object['reexport'] == 1) { $country->setReexport(); } return $country; break; case "font": return new Font($name, $id); break; } }