/** * Delete a country with its regions, cities,.. * * @access public * @since 2.4 * @param $pk * @return int number of failed deletions or 0 in case of none */ function deleteByPrimaryKey($pk) { $mRegions = Region::NewInstance(); $aRegions = $mRegions->findByCountry($pk); $result = 0; foreach ($aRegions as $region) { $result += $mRegions->deleteByPrimaryKey($region['pk_i_id']); } Item::newInstance()->deleteByCountry($pk); CountryStats::newInstance()->delete(array('fk_c_country_code' => $pk)); User::newInstance()->update(array('fk_c_country_code' => null, 's_country' => ''), array('fk_c_country_code' => $pk)); if (!$this->delete(array('pk_c_code' => $pk))) { $result++; } return $result; }
/** * Delete a country with its regions, cities,.. * * @access public * @since 2.4 * @param $pk * @return boolean */ function deleteByPrimaryKey($pk) { $mRegions = Region::NewInstance(); $aRegions = $mRegions->findByCountry($pk); $mCities = City::newInstance(); $mCityAreas = CityArea::newInstance(); $result = true; foreach ($aRegions as $region) { $aCities = $mCities->findByRegion($region['pk_i_id']); foreach ($aCities as $city) { $aCityAreas = $mCityAreas->findByCity($city['pk_i_id']); foreach ($aCityAreas as $cityArea) { if (!$mCityAreas->delete(array('pk_i_id' => $cityArea['pk_i_id']))) { $result = false; } } if (!$mCities->delete(array('pk_i_id' => $city['pk_i_id']))) { $result = false; } } if (!$mRegions->delete(array('pk_i_id' => $region['pk_i_id']))) { $result = false; } } if (!$this->delete(array('pk_c_code' => $pk))) { $result = false; } return $result; }