public function insertValues(ExcelInputFile $excelInputFile, $subgroup, $origin, $destiny, $type, $variety, $font, $typeCountry = null, $internationalTrade = false) { $countries = $excelInputFile->getValuesOfColumn(1); $dataToSave = new ArrayObject(); foreach ($countries as $country) { if ($typeCountry == 'origin') { $origin = CacheCountry::getCountries()->getOrigins()->get(utf8_encode($country))->id(); if (is_null($origin)) { $origin = $this->countryMap->getOuthersForOrigin(); } if (!$internationalTrade) { $destiny = 0; } } elseif ($typeCountry == 'destiny') { $destiny = CacheCountry::getCountries()->getDestinies()->get(utf8_encode($country))->id(); if (is_null($destiny)) { $destiny = $this->countryMap->getOthersForDestiny(); } if (!$internationalTrade) { $origin = 0; } } else { $origin = CacheCountry::getCountries()->getOrigins()->get(utf8_encode($country))->id(); } $dataParam = new DataParam($subgroup, $font, $type, $variety, $origin, $destiny); $dataOfCurrentCountry = $this->getValuesWithSimpleFilter($dataParam); $yearsToInsert = $this->insertValuesIfACountryDoesNotHaveItStoredYet($dataOfCurrentCountry, $excelInputFile, $country); if ($yearsToInsert->count() > 0) { $this->getDataToSave($dataToSave, $yearsToInsert, $excelInputFile, $country, $subgroup, $font, $type, $variety, $origin, $destiny); } } return $this->repository->save($dataToSave); }
/** * * @param type $jsonResponse * @return DatacenterController */ function requires($jsonResponse){ require_once 'requires_build.php'; $repository = new DatacenterDao(Connection::connect()); CacheCountry::setCacheBehavior(SessionAdmin::getCacheBehavior()); $cache = CacheCountry::getCountries(); $service = new DatacenterService($repository, $cache);//$countryMap); $statistic = new Statistic(); $grouper = new DataGrouper(); $controller = new DatacenterController($service, $statistic, $jsonResponse, $grouper, $factory); return $controller; }
if ($variety == "none") { $variety = 0; } $destiny = $_POST['destiny']; $origin = $_POST['origin']; $typeCountry = null; if (isset($_POST['typeCountry'])) { $typeCountry = $_POST['typeCountry']; } if (!insertingValuesForInternationalTrade($subgroup)) { $destiny = 0; $origin = 0; } $repository = new DatacenterDao(Connection::connect()); CacheCountry::setCacheBehavior(SessionAdmin::getCacheBehavior()); $cache = CacheCountry::getCountries(); $service = new DatacenterService($repository, $cache); //$countryMap); $statistic = new Statistic(); $grouper = new DataGrouper(); $controller = new DatacenterController($service, $statistic, $jsonResponse, $grouper, $factory); $reader = new Spreadsheet_Excel_Reader($_FILES['Planilha']['tmp_name']); try { $inputFile = new ExcelInputFile($reader); if (insertingValuesForInternationalTrade($subgroup)) { //$typeCountry = 'origin'; $response = $controller->saveValues($inputFile, $subgroup, $font, $origin, $destiny, $coffeType, $variety, $typeCountry, true); } else { $response = $controller->saveValues($inputFile, $subgroup, $font, $origin, $destiny, $coffeType, $variety, $typeCountry); } print_r($response);
private function destinyCountries() { //$countries = array("EUA", "França", "Franca", "Alemanha", "Canadá", "Canada", "Itália", "Italia", "Japão", "Japao", "Outros"); $countries = CacheCountry::getCountries()->getDestinies()->keys(); foreach ($countries as $i => $country) { $countries[$i] = utf8_decode($country); } return $countries; }