本文整理汇总了PHP中Region::findByName方法的典型用法代码示例。如果您正苦于以下问题:PHP Region::findByName方法的具体用法?PHP Region::findByName怎么用?PHP Region::findByName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Region
的用法示例。
在下文中一共展示了Region::findByName方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Country
function install_location_by_region()
{
$countryParent = Params::getParam('country_c_parent');
$region = Params::getParam('region');
if ($countryParent == '') {
return false;
}
if ($region == '') {
return false;
}
$manager_country = new Country();
$country = $manager_country->findByCode($countryParent);
$aCountry = array();
$aRegion = array();
$aCountry[] = $country['s_name'];
$aRegion[] = $region;
$manager_region = new Region();
$regions_json = osc_file_get_contents('http://geo.osclass.org/geo.download.php?action=region&country=' . urlencode(implode(',', $aCountry)) . '&term=' . urlencode(implode(',', $aRegion)));
$regions = json_decode($regions_json);
if (isset($regions->error)) {
osc_add_flash_error_message(sprintf(_m("%s can't be added"), $region), 'admin');
return false;
}
foreach ($regions as $r) {
$exists = $manager_region->findByName($r->name, $r->country_code);
if (isset($exists['s_name'])) {
osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $exists['s_name']), 'admin');
return false;
}
$manager_region->insert(array("fk_c_country_code" => $r->country_code, "s_name" => $r->name));
}
unset($regions);
unset($regions_json);
$manager_city = new City();
foreach ($country as $c) {
$regions = $manager_region->findByName($region, $country['pk_c_code']);
$cities_json = osc_file_get_contents('http://geo.osclass.org/geo.download.php?action=city&country=' . urlencode($c) . '®ion=' . urlencode($regions['s_name']) . '&term=all');
$cities = json_decode($cities_json);
if (!isset($cities->error)) {
foreach ($cities as $ci) {
$manager_city->insert(array("fk_i_region_id" => $regions['pk_i_id'], "s_name" => $ci->name, "fk_c_country_code" => $ci->country_code));
}
}
unset($cities);
unset($cities_json);
}
osc_add_flash_ok_message(sprintf(_m('%s has been added as a region of %s'), $region, $country['s_name']), 'admin');
}
示例2: doModel
//.........这里部分代码省略.........
osc_add_flash_error_message(_m('There was a problem deleting locations'), 'admin');
}
} else {
osc_add_flash_error_message(_m('No country was selected'), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'add_region':
// add region
osc_csrf_check();
if (!Params::getParam('r_manual')) {
$regionId = Params::getParam('region_id');
$regionName = Params::getParam('region');
if ($regionId != '') {
$data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=region&term=' . urlencode($regionId));
$conn = DBConnectionClass::newInstance();
$c_db = $conn->getOsclassDb();
$comm = new DBCommandClass($c_db);
$comm->query("SET FOREIGN_KEY_CHECKS = 0");
$comm->importSQL($data_sql);
$comm->query("SET FOREIGN_KEY_CHECKS = 1");
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
} else {
osc_add_flash_error_message(sprintf(_m("%s can't be added"), $regionName), 'admin');
}
} else {
$mRegions = new Region();
$regionName = Params::getParam('region');
$countryCode = Params::getParam('country_c_parent');
$country = Country::newInstance()->findByCode($countryCode);
if (!osc_validate_min($regionName, 1)) {
osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
} else {
$exists = $mRegions->findByName($regionName, $countryCode);
if (!isset($exists['s_name'])) {
$data = array('fk_c_country_code' => $countryCode, 's_name' => $regionName);
$mRegions->insert($data);
$id = $mRegions->dao->insertedId();
RegionStats::newInstance()->setNumItems($id, 0);
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
} else {
osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $regionName), 'admin');
}
}
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code=' . @$countryCode . "&country=" . @$country['s_name']);
break;
case 'edit_region':
// edit region
osc_csrf_check();
$mRegions = new Region();
$newRegion = Params::getParam('e_region');
$regionId = Params::getParam('region_id');
if (!osc_validate_min($newRegion, 1)) {
osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
} else {
$exists = $mRegions->findByName($newRegion);
if (!isset($exists['pk_i_id']) || $exists['pk_i_id'] == $regionId) {
if ($regionId != '') {
$aRegion = $mRegions->findByPrimaryKey($regionId);
$country = Country::newInstance()->findByCode($aRegion['fk_c_country_code']);
$mRegions->update(array('s_name' => $newRegion), array('pk_i_id' => $regionId));
ItemLocation::newInstance()->update(array('s_region' => $newRegion), array('fk_i_region_id' => $regionId));
osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newRegion), 'admin');
}
} else {
示例3: insert_google_map
public function insert_google_map($userId)
{
$aItem = Item::newInstance()->findByPrimaryKey($userId);
$address = osc_sanitize_name(strip_tags(trim(Params::getParam('dln_address'))));
$lat = strip_tags(trim(Params::getParam('dln_lat')));
$long = strip_tags(trim(Params::getParam('dln_long')));
// Connect to google geolocation service for get country and city location
$country = $city = '';
if ($lat && $long) {
try {
$response = file_get_contents(sprintf('https://maps.googleapis.com/maps/api/geocode/json?latlng=%s,%s&language=vi_VN', $lat, $long));
$json_resp = json_decode($response);
$country_code = '';
if (isset($json_resp->results[0]->address_components) && is_array($json_resp->results[0]->address_components)) {
foreach ($json_resp->results[0]->address_components as $i => $component) {
if (!empty($component->types) && in_array('country', $component->types)) {
$country = $component->long_name;
$country_code = strtoupper($component->short_name);
}
if (!empty($component->types) && in_array('administrative_area_level_1', $component->types)) {
$city = $component->long_name;
}
}
$country_id = $city_id = $region_id = '';
if ($country && $country_code) {
// Insert new country if not exists
$mCountries = new Country();
$exists = $mCountries->findByCode($country_code);
if (!isset($exists['s_name'])) {
$mCountries->insert(array('pk_c_code' => $country_code, 's_name' => $country));
$country_id = $mCountries->dao->insertedId();
} else {
$country_id = isset($exists['pk_c_code']) ? $exists['pk_c_code'] : '';
}
// Insert Un-register region
$region_name = 'Undefined';
$mRegion = new Region();
$exists = $mRegion->findByName($region_name, $country_code);
if (!isset($exists['s_name'])) {
$data = array('fk_c_country_code' => $country_code, 's_name' => $region_name);
$mRegion->insert($data);
$region_id = $mRegion->dao->insertedId();
RegionStats::newInstance()->setNumItems($region_id, 0);
} else {
$region_id = isset($exists['pk_i_id']) ? $exists['pk_i_id'] : '';
}
if ($city) {
// Insert new city if not exists
$mCity = new City();
$exists = $mCity->findByName($city, $region_id);
if (!isset($exists['s_name'])) {
$mCity->insert(array('fk_i_region_id' => $region_id, 's_name' => $city, 'fk_c_country_code' => $country_code));
$city_id = $mCity->dao->insertedId();
CityStats::newInstance()->setNumItems($city_id, 0);
} else {
$city_id = isset($exists['pk_i_id']) ? $exists['pk_i_id'] : '';
}
}
}
}
} catch (Exception $e) {
var_dump($e->getMessage());
die;
}
}
User::newInstance()->update(array('s_address' => $address, 'd_coord_lat' => $lat, 'd_coord_long' => $long, 's_country' => $country, 's_city' => $city, 'fk_i_region_id' => $region_id, 'fk_c_country_code' => $country_id, 'fk_i_city_id' => $city_id), array('pk_i_id' => $userId));
/*ItemLocation::newInstance()->update(
array(
's_address' => $address,
'd_coord_lat' => $lat,
'd_coord_long' => $long,
's_country' => $country,
's_city' => $city,
), array( 'fk_i_item_id' => $itemId ) );*/
}
示例4: doModel
//.........这里部分代码省略.........
break;
case('add_region'): // add region
if( defined('DEMO') ) {
osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
}
osc_csrf_check();
if( !Params::getParam('r_manual') ) {
$regionId = Params::getParam('region_id');
$regionName = Params::getParam('region');
if($regionId!='') {
$data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=region&term=' . urlencode($regionId) );
$conn = DBConnectionClass::newInstance();
$c_db = $conn->getOsclassDb();
$comm = new DBCommandClass($c_db);
$comm->query("SET FOREIGN_KEY_CHECKS = 0");
$comm->importSQL($data_sql);
$comm->query("SET FOREIGN_KEY_CHECKS = 1");
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
} else {
osc_add_flash_error_message(sprintf(_m("%s can't be added"), $regionName), 'admin');
}
} else {
$mRegions = new Region();
$regionName = Params::getParam('region');
$countryCode = Params::getParam('country_c_parent');
$country = Country::newInstance()->findByCode($countryCode);
if(!osc_validate_min($regionName, 1)) {
osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
} else {
$exists = $mRegions->findByName($regionName, $countryCode);
if(!isset($exists['s_name'])) {
$data = array('fk_c_country_code' => $countryCode
,'s_name' => $regionName);
$mRegions->insert($data);
$id = $mRegions->dao->insertedId();
RegionStats::newInstance()->setNumItems($id, 0);
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
} else {
osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $regionName), 'admin');
}
}
}
osc_calculate_location_slug(osc_subdomain_type());
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations&country_code='.@$countryCode."&country=".@$country['s_name']);
break;
case('edit_region'): // edit region
if( defined('DEMO') ) {
osc_add_flash_warning_message( _m("This action can't be done because it's a demo site"), 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
}
osc_csrf_check();
$mRegions = new Region();
$newRegion = Params::getParam('e_region');
$regionId = Params::getParam('region_id');
if(!osc_validate_min($newRegion, 1)) {
osc_add_flash_error_message(_m('Region name cannot be blank'), 'admin');
} else {
$exists = $mRegions->findByName($newRegion);
if(!isset($exists['pk_i_id']) || $exists['pk_i_id']==$regionId) {
if($regionId != '') {
示例5: doModel
//.........这里部分代码省略.........
osc_add_flash_ok_message(_m('There were some problems editing the country'), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'delete_country':
// delete country
$countryId = Params::getParam('id');
// HAS ITEMS?
$has_items = Item::newInstance()->listWhere('l.fk_c_country_code = \'%s\' LIMIT 1', $countryId);
if (!$has_items) {
$mRegions = new Region();
$mCities = new City();
$aCountries = $mCountries->findByCode($countryId);
$aRegions = $mRegions->listWhere('fk_c_country_code = \'' . $aCountries['pk_c_code'] . '\'');
foreach ($aRegions as $region) {
$mCities->delete(array('fk_i_region_id' => $region['pk_i_id']));
$mRegions->delete(array('pk_i_id' => $region['pk_i_id']));
}
$mCountries->delete(array('pk_c_code' => $aCountries['pk_c_code']));
osc_add_flash_ok_message(sprintf(_m('%s has been deleted'), $aCountries['s_name']), 'admin');
} else {
osc_add_flash_error_message(sprintf(_m('%s can not be deleted, some items are located in it'), $aCountries['s_name']), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'add_region':
// add region
if (!Params::getParam('r_manual')) {
$this->install_location_by_region();
} else {
$mRegions = new Region();
$regionName = Params::getParam('region');
$countryCode = Params::getParam('country_c_parent');
$exists = $mRegions->findByNameAndCode($regionName, $countryCode);
if (!isset($exists['s_name'])) {
$data = array('fk_c_country_code' => $countryCode, 's_name' => $regionName);
$mRegions->insert($data);
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new region'), $regionName), 'admin');
} else {
osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $regionName), 'admin');
}
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'edit_region':
// edit region
$mRegions = new Region();
$newRegion = Params::getParam('e_region');
$regionId = Params::getParam('region_id');
$exists = $mRegions->findByName($newRegion);
if (!$exists['pk_i_id'] || $exists['pk_i_id'] == $regionId) {
if ($regionId != '') {
$mRegions->update(array('s_name' => $newRegion), array('pk_i_id' => $regionId));
osc_add_flash_ok_message(sprintf(_m('%s has been edited'), $newRegion), 'admin');
}
} else {
osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $newRegion), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'delete_region':
// delete region
$mRegion = new Region();
$mCities = new City();
$regionId = Params::getParam('id');
if ($regionId != '') {
示例6: doModel
//.........这里部分代码省略.........
if ($iUpdated > 0) {
osc_add_flash_message(_m('Users\' settings have been updated'), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=users');
break;
case 'locations':
// calling the locations settings view
$location_action = Params::getParam('type');
$mCountries = new Country();
switch ($location_action) {
case 'add_country':
// add country
if (!Params::getParam('c_manual')) {
$this->install_location_by_country();
} else {
$countryCode = Params::getParam('c_country');
$countryName = Params::getParam('country');
$countryLanguage = osc_language();
$exists = $mCountries->findByCode($countryCode);
if (!isset($exists['s_name'])) {
$data = array('pk_c_code' => $countryCode, 'fk_c_locale_code' => $countryLanguage, 's_name' => $countryName);
$mCountries->insert($data);
osc_add_flash_message(sprintf(__('%s has been added as a new country'), $countryName), 'admin');
} else {
osc_add_flash_message(sprintf(__('%s already was in the database'), $countryName), 'admin');
}
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'edit_country':
// edit country
$newCountry = Params::getParam('e_country');
$oldCountry = Params::getParam('country_old');
$exists = $mCountries->findByName($newCountry);
$old_exists = $mCountries->findByName($oldCountry);
if (!isset($exists['pk_c_code']) || $exists['pk_c_code'] == $old_exists['pk_c_code']) {
$mCountries->update(array('s_name' => $newCountry), array('s_name' => $oldCountry));
osc_add_flash_message(sprintf(__('%s has been edited'), $newCountry), 'admin');
} else {
osc_add_flash_message(sprintf(__('%s already was in the database'), $newCountry), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'delete_country':
// delete country
$countryId = Params::getParam('id');
// HAS ITEMS?
$has_items = Item::newInstance()->listWhere('l.fk_c_country_code = \'%s\' LIMIT 1', $countryId);
if (!$has_items) {
$mRegions = new Region();
$mCities = new City();
$aCountries = $mCountries->findByCode($countryId);
$aRegions = $mRegions->listWhere('fk_c_country_code = \'' . $aCountries['pk_c_code'] . '\'');
foreach ($aRegions as $region) {
$mCities->delete(array('fk_i_region_id' => $region['pk_i_id']));
$mRegions->delete(array('pk_i_id' => $region['pk_i_id']));
}
$mCountries->delete(array('pk_c_code' => $aCountries['pk_c_code']));
osc_add_flash_message(sprintf(__('%s has been deleted'), $aCountries['s_name']), 'admin');
} else {
osc_add_flash_message(sprintf(__('%s can not be deleted, some items are located in it'), $aCountries['s_name']), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'add_region':
// add region