Login   Register  
PHP Classes
elePHPant
Icontem

File: geozonesearch.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Virgilio lino  >  geozonedb  >  geozonesearch.php  >  Download  
File: geozonesearch.php
Role: Class source
Content type: text/plain
Description: class for interface to use on your application
Class: geozonedb
Get world geographic data from GeoNames into MySQL
Author: By
Last change:
Date: 3 years ago
Size: 2,724 bytes
 

Contents

Class file image Download
<?php
require_once('includes/engine.php');
class 
geozoneSearch {
  private 
$country;
  private 
$search;
  private 
$result;
  private static 
$that
 
//private 
  
private function __construct() {


  }

  private function 
init() {
    if (!isset(
self::$that)) {
      
$c __CLASS__;
      
self::$that = new $c();
    }
    return 
self::$that;
  }

  
//singleton constructors

  
public static function setCountry($country) {
    
$that=self::init();
    
//the country code i receive will be in: NNN_TT   where NNN is the iso code and TT the ISO 1 
    
$that->country=substr($country,-2);
    return 
$that;
  }
  
  public static function  
search($community,$myISAMFullSearch=true) {
    
$that=self::init();
    
$that->search=str_replace(array('(',')'),'',$community);
    
$ret=false;
    if(
strlen($that->search)>0) {
      if(
$myISAMFullSearch) {
    
$that->search=rawurldecode($that->search);
    
$words=explode(" ",$that->search);
    
$srString="'";
    foreach(
$words as $w) {
      
$w=trim($w);
      if(
$w)$srString.=" +$w* ";
    }
    
    
$srString.="'";
    
$countries=xQuery("SELECT zone_ID, Name, StateName, ProvinceName,  CommunityName FROM ".$that->country." WHERE MATCH (Name, StateName, ProvinceName, CommunityName) AGAINST (".$srString." IN BOOLEAN MODE) LIMIT 50");
      } else {
    
$countries=xQuery("SELECT zone_ID, Name, StateName, ProvinceName,  CommunityName FROM ".$that->country." WHERE Name like '".$that->search."%' or StateName like '".$that->search."%' or ProvinceName like '".$that->search."%' or CommunityName like '".$that->search."%' LIMIT 50");
      }
      
$countries->MoveFirst();
      
$ret'{"Communities":[';
      while(!
$countries->EOF) {
    if(
$countries->fields[4]!='')$c=$countries->fields[4];
    
$ret.= '{"zone_ID":"'.$countries->fields[0].'","Community":"'.trim($countries->fields[4].' '.$countries->fields[3].' '.$countries->fields[2]).'('.trim($countries->fields[1]).')"}';
    
$countries->MoveNext();
    if(!
$countries->EOF)$ret.= ",";
      }
      
$ret.= ']}';
    }
    
$that->result=$ret;
    return 
$that;
  }

  
//eof singleton constructors
  
public static function getCountries() {
    
$countries=xQuery("SELECT ISONumeric, ISO, Country FROM country");
    
$values=false
    if(
$countries) {
      
$countries->MoveFirst();
      
$values[]=array('id'=>'0_0','text'=>'Click to select a State');
      while(!
$countries->EOF) {
    
$values[]=array('id'=>$countries->fields[0]."_".$countries->fields[1],'text'=>$countries->fields[2]);
    
$countries->MoveNext();
      }
    }
    return 
$values;
    
  }

  public function 
getCountry() {
  
    return 
$this->country;
  }

  public function 
getSearch() {
    return 
$this->search;
  }

  public function 
getResult() {
    return 
$this->result;
  }


}