Example #1
0
 public function filterAddressToInsertRegional($data)
 {
     $cityModel = new Model_City();
     $stateModel = new Model_State();
     $dbTable_City = new DbTable_City();
     $neighborhoodModel = new Model_Neighborhood();
     $filter = array('getAllStates' => null, 'getAllCities' => null, 'getAllNeighborhoods' => null);
     switch ($data['indice']) {
         case 'StateId':
             $filter['allStateId'] = $data['dados'];
             $filter['getAllStates'] = $stateModel->getAll();
             break;
         case 'CityId':
             $filter['allCityId'] = $data['dados'];
             $city = $dbTable_City->getById($data['dados'][0]['CityId']);
             $stateId = $city->getStateId();
             $filter['allStateId'] = array(0 => array('StateId' => $stateId));
             $localData['uf'] = $city->getUf();
             break;
         case 'NeighborhoodId':
             $filter['allNeighborhoodId'] = $data['dados'];
             $neighborhood = $neighborhoodModel->getNeighborhoodById($data['dados'][0]['NeighborhoodId']);
             $cityId = $neighborhood->getCityId();
             $state = $stateModel->getStateByUf($neighborhood->getUf());
             $filter['allCityId'] = array(0 => array('CityId' => $cityId));
             $filter['allStateId'] = array(0 => array('StateId' => $state->getId()));
             $localData['uf'] = $neighborhood->getUf();
             $localData['city_id'] = $cityId;
             break;
         default:
             break;
     }
     $filter['getAllStates'] = $stateModel->getAll();
     if (isset($localData['uf'])) {
         $filter['getAllCities'] = $cityModel->getAllCityByUf($localData['uf']);
     }
     if (isset($localData['city_id'])) {
         $filter['getAllNeighborhoods'] = $neighborhoodModel->getAllNeighborhoodByCityId($localData['city_id']);
     }
     return $filter;
 }