<?php

class Model_DbTable_Cities extends Zend_Db_Table
{
    protected $_name = 'ef_cities';
    
   public function insertData($data)
    {
       
       try{
           $id = $this->insert($data);
           return $id;
       }catch(Exception $e){
          return  false;
       }
       
    }
    
    public function updateData($data,$id)
    {
       
       try{
           $this->update($data,"City_id ='".$id."'");
           return $id;
       }catch(Exception $e){
          return  false;
       }
       
    }
   
   
   public function getRow($id)
    {
       return $data = $this->fetchRow("City_id ='".$id."'");
       
    }  
     
   public function getAll($searchSQL=null)
    {
       $select = $this->select();
            $select->from(array('T' => $this->_name));
             $select->joinLeft(array("C"=>"countries"), "T.CountryID = C.id",array("id","nicename")); 
             $select->joinLeft(array("P"=>"provinces"), "T.ProvinceID = P.province_id",array("province_id","Province"));
             if($searchSQL !=null){
               $select->where("T.City LIKE '%$searchSQL%' OR C.nicename LIKE '%$searchSQL%' OR P.Province LIKE '%$searchSQL%'"); 
             }
            $select->setIntegrityCheck(false);
            return $this->fetchAll($select);
    }  
    
    public function getAllData()
    {
       $select = $this->select();
            $select->from(array('T' => $this->_name));
            
            $select->setIntegrityCheck(false);
            return $this->fetchAll($select);
    } 
}