本文整理汇总了PHP中Country::findByCode方法的典型用法代码示例。如果您正苦于以下问题:PHP Country::findByCode方法的具体用法?PHP Country::findByCode怎么用?PHP Country::findByCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Country
的用法示例。
在下文中一共展示了Country::findByCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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
function doModel()
{
switch ($this->action) {
case 'comments':
//calling the comments settings view
$this->doView('settings/comments.php');
break;
case 'comments_post':
// updating comment
osc_csrf_check();
$iUpdated = 0;
$enabledComments = Params::getParam('enabled_comments');
$enabledComments = $enabledComments != '' ? true : false;
$moderateComments = Params::getParam('moderate_comments');
$moderateComments = $moderateComments != '' ? true : false;
$numModerateComments = Params::getParam('num_moderate_comments');
$commentsPerPage = Params::getParam('comments_per_page');
$notifyNewComment = Params::getParam('notify_new_comment');
$notifyNewComment = $notifyNewComment != '' ? true : false;
$notifyNewCommentUser = Params::getParam('notify_new_comment_user');
$notifyNewCommentUser = $notifyNewCommentUser != '' ? true : false;
$regUserPostComments = Params::getParam('reg_user_post_comments');
$regUserPostComments = $regUserPostComments != '' ? true : false;
$msg = '';
if (!osc_validate_int(Params::getParam("num_moderate_comments"))) {
$msg .= _m("Number of moderate comments must only contain numeric characters") . "<br/>";
}
if (!osc_validate_int(Params::getParam("comments_per_page"))) {
$msg .= _m("Comments per page must only contain numeric characters") . "<br/>";
}
if ($msg != '') {
osc_add_flash_error_message($msg, 'admin');
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=comments');
}
$iUpdated += Preference::newInstance()->update(array('s_value' => $enabledComments), array('s_name' => 'enabled_comments'));
if ($moderateComments) {
$iUpdated += Preference::newInstance()->update(array('s_value' => $numModerateComments), array('s_name' => 'moderate_comments'));
} else {
$iUpdated += Preference::newInstance()->update(array('s_value' => '-1'), array('s_name' => 'moderate_comments'));
}
$iUpdated += Preference::newInstance()->update(array('s_value' => $notifyNewComment), array('s_name' => 'notify_new_comment'));
$iUpdated += Preference::newInstance()->update(array('s_value' => $notifyNewCommentUser), array('s_name' => 'notify_new_comment_user'));
$iUpdated += Preference::newInstance()->update(array('s_value' => $commentsPerPage), array('s_name' => 'comments_per_page'));
$iUpdated += Preference::newInstance()->update(array('s_value' => $regUserPostComments), array('s_name' => 'reg_user_post_comments'));
if ($iUpdated > 0) {
osc_add_flash_ok_message(_m("Comment settings have been updated"), 'admin');
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=comments');
break;
case 'locations':
// calling the locations settings view
$location_action = Params::getParam('type');
$mCountries = new Country();
switch ($location_action) {
case 'add_country':
// add country
osc_csrf_check();
$countryCode = strtoupper(Params::getParam('c_country'));
$countryName = Params::getParam('country');
$exists = $mCountries->findByCode($countryCode);
if (isset($exists['s_name'])) {
osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $countryName), 'admin');
} else {
if (Params::getParam('c_manual') == 1) {
$mCountries->insert(array('pk_c_code' => $countryCode, 's_name' => $countryName));
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
} else {
if (!osc_validate_min($countryCode, 1) || !osc_validate_min($countryName, 1)) {
osc_add_flash_error_message(_m('Country code and name should have at least two characters'), 'admin');
} else {
$data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=country&term=' . urlencode($countryCode));
if ($data_sql != '') {
$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");
} else {
$mCountries->insert(array('pk_c_code' => $countryCode, 's_name' => $countryName));
}
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
}
}
}
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case 'edit_country':
// edit country
osc_csrf_check();
if (!osc_validate_min(Params::getParam('e_country'), 1)) {
osc_add_flash_error_message(_m('Country name cannot be blank'), 'admin');
} else {
$ok = $mCountries->update(array('s_name' => Params::getParam('e_country')), array('pk_c_code' => Params::getParam('country_code')));
if ($ok) {
osc_add_flash_ok_message(_m('Country has been edited'), 'admin');
} else {
osc_add_flash_error_message(_m('There were some problems editing the country'), 'admin');
}
}
//.........这里部分代码省略.........
示例3: addslashes
}
//echo $pageaction;
switch ($pageaction) {
case "reservation":
$solutation = $_POST['solutation'];
$first_name = addslashes($_POST['f-name']);
$last_name = addslashes($_POST['l-name']);
$fullname = $first_name . " " . $last_name;
$contact_no = addslashes($_POST['contact-no']);
$company_name = addslashes($_POST['company-name']);
$email = addslashes($_POST['email']);
$email_confirm = addslashes($_POST['email-c']);
$country_code = $_POST['country'];
//echo $country_code;
$oCountry = new Country();
$countryAll = $oCountry->findByCode($country_code);
$country = $countryAll->country_name;
$event_name = addslashes($_POST['event-name']);
$purpose = $_POST['purpose'];
$arrival_date = $_POST['a-date'];
$departure_date = $_POST['d-date'];
$person = addslashes($_POST['person']);
if (isset($_POST['event-s'])) {
$event_size = $_POST['event-s'];
}
//echo $event_size;
if (isset($_POST['event-type'])) {
$event_type = $_POST['event-type'];
}
//echo $event_type;
//echo "ennd";
示例4: 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 ) );*/
}
示例5: doModel
function doModel()
{
// calling the locations settings view
$location_action = Params::getParam('type');
$mCountries = new Country();
switch ($location_action) {
case('add_country'): // add country
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();
$countryCode = strtoupper(Params::getParam('c_country'));
$countryName = Params::getParam('country');
$exists = $mCountries->findByCode($countryCode);
if(isset($exists['s_name'])) {
osc_add_flash_error_message(sprintf(_m('%s already was in the database'), $countryName), 'admin');
} else {
if(Params::getParam('c_manual')==1) {
$mCountries->insert(array('pk_c_code' => $countryCode,
's_name' => $countryName));
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
} else {
if(!osc_validate_min($countryCode, 1) || !osc_validate_min($countryName, 1)) {
osc_add_flash_error_message(_m('Country code and name should have at least two characters'), 'admin');
} else {
$data_sql = osc_file_get_contents('http://geo.osclass.org/newgeo.download.php?action=country&term=' . urlencode($countryCode) );
if($data_sql!='') {
$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");
} else {
$mCountries->insert(array('pk_c_code' => $countryCode,
's_name' => $countryName));
}
osc_add_flash_ok_message(sprintf(_m('%s has been added as a new country'), $countryName), 'admin');
}
}
}
osc_calculate_location_slug(osc_subdomain_type());
$this->redirectTo(osc_admin_base_url(true) . '?page=settings&action=locations');
break;
case('edit_country'): // edit country
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(!osc_validate_min(Params::getParam('e_country'), 1)) {
osc_add_flash_error_message(_m('Country name cannot be blank'), 'admin');
} else {
$name = Params::getParam('e_country');
$slug = Params::getParam('e_country_slug');
if($slug=='') {
$slug_tmp = $slug = osc_sanitizeString($name);
} else {
$exists = $mCountries->findBySlug($slug);
if(isset($exists['s_slug']) && $exists['pk_c_code']!=Params::getParam('country_code')) {
$slug_tmp = $slug = osc_sanitizeString($name);
} else {
$slug_tmp = $slug = osc_sanitizeString($slug);
}
}
$slug_unique = 1;
while(true) {
$location_slug = $mCountries->findBySlug($slug);
if(isset($location_slug['s_slug']) && $location_slug['pk_c_code']!=Params::getParam('country_code')) {
$slug = $slug_tmp . '-' . $slug_unique;
$slug_unique++;
} else {
break;
}
}
$ok = $mCountries->update(array('s_name'=> $name, 's_slug' => $slug), array('pk_c_code' => Params::getParam('country_code')));
if( $ok ) {
osc_add_flash_ok_message(_m('Country has been edited'), 'admin');
} else {
osc_add_flash_error_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
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();
$countryIds = Params::getParam('id');
if(is_array($countryIds)) {
$locations = 0;
$del_locations = 0;
//.........这里部分代码省略.........