Next4Me
 All Data Structures Files Functions Variables
application/models/regions.php
Go to the documentation of this file.
00001 <?php
00002 
00012 class Regions  extends Zend_Db_Table_Abstract {
00013     //put your code here
00014     protected $_name="Regions"; 
00015     protected $_primary="IdRegion"; 
00016     
00017     //==== Start addEditRegion =========================================================================
00029     function addEditRegion($entity){
00030             $resultId = 0;
00031             $page="regions.php";
00032             $method="addEditRegion";
00033             $result=json_encode($entity);
00034             $message="";
00035             $type="1";
00036             $this->ErrorCode = new ErrorCode;
00037             $this->Log = new Log;
00038 
00039         try{
00040         if ($entity['IdRegion']=="0"){
00041                 $this->insert($entity);
00042                 $k=$this->getAdapter()->lastInsertId();
00043                 $resultCode=$k;
00044             }else{
00045                 $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
00046                                                 ->from("Regions","*")
00047                                                 ->where("IdRegion=?",$entity['IdRegion'])
00048                                                 );
00049                 if($sql!=null){
00050                     $k=$this->update(array(
00051                         "Value"=>$entity['Value'],
00052                         "IdParent" => $entity['IdParent'], 
00053                         "Type" => $entity['Type'],
00054                     ),$this->getAdapter()->quoteInto('IdRegion=?',$entity['IdRegion']));
00055                     $k=$entity['IdRegion'];
00056                     $resultCode=$k;
00057                 }else{
00058                     $resultId = 3086;
00059                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00060                     $resultCode=$r['Message'];
00061                     $message=$r['Message'];
00062                     $type=3;
00063                 }
00064             }
00065             
00066             
00067             }
00068             catch(Exception $e){
00069                 $resultCode=$e->getMessage();
00070                 $resultId=101;       
00071                 $type=3;
00072             }
00073                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00074                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00075          return $response;
00076             
00077     }
00078     
00079     //==== End addEditRegion =========================================================================
00080     
00081     //==== Start getRegionById =========================================================================
00091         function getRegionById($Entity){
00092             $resultId = 0;
00093             $page="regions.php";
00094             $method="getRegionById";
00095             $result=json_encode($entity);
00096             $message="";
00097             $type="1";
00098             $this->ErrorCode = new ErrorCode;
00099             $this->Log = new Log;
00100 
00101             try{ 
00102         
00103             $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
00104                                                 ->from("Regions","*")
00105                                                 ->where("IdRegion=?",$Entity)
00106                                                 );
00107             if($sql!=null){
00108                 $result = array("IdRegion"=>$sql->IdRegion,"Value"=>$sql->Value,"IdParent"=>$sql->IdParent, "Type"=>$sql->Type);    
00109                 $resultCode=$result;
00110             }else{
00111                     $resultId = 3087;
00112                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00113                     $resultCode=$r['Message'];
00114                     $message=$r['Message'];
00115                     $type=3;
00116             }
00117             }
00118             catch(Exception $e){
00119                 $resultCode=$e->getMessage();
00120                 $resultId=101;       
00121                 $type=3;
00122             }
00123                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00124                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00125          return $response;
00126             
00127         }
00128     //==== End getRegionById =========================================================================
00129     
00130     //==== Start getRegionByType =========================================================================
00139         function getRegionByType($Entity){
00140             $resultId = 0;
00141             $page="regions.php";
00142             $method="getRegionByType";
00143             $result=json_encode($entity);
00144             $message="";
00145             $type="1";
00146             $this->ErrorCode = new ErrorCode;
00147             $this->Log = new Log;
00148 
00149             try{
00150             $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00151                                                 ->from("Regions","*")
00152                                                 ->where("Type=?",$Entity)
00153                                                 );
00154             if($rows!=null){
00155             foreach($rows as $row){
00156                 $result[] = array("IdRegion"=>$row->IdRegion,"Value"=>$row->Value,"IdParent"=>$row->IdParent, "Type"=>$row->Type);    
00157             }
00158                 $resultCode=$result;
00159             }else{
00160                 $resultId = 3088;
00161                 $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00162                 $resultCode=$r['Message'];
00163                 $message=$r['Message'];
00164                 $type=3;
00165             }
00166             }
00167             catch(Exception $e){
00168                 $resultCode=$e->getMessage();
00169                 $resultId=101;       
00170                 $type=3;
00171             }
00172                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00173                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00174          return $response;
00175             
00176         }
00177     //==== End getRegionByType =========================================================================
00178     
00179     //==== Start getRegionByParent =========================================================================
00189         function getRegionByParent($Entity){
00190             $resultId = 0;
00191             $page="regions.php";
00192             $method="getRegionByParent";
00193             $result=json_encode($entity);
00194             $message="";
00195             $type="1";
00196             $this->ErrorCode = new ErrorCode;
00197             $this->Log = new Log;
00198 
00199             try{
00200                 $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00201                                                     ->from("Regions","*")
00202                                                     ->where("IdParent=?",$Entity)
00203                                                     );
00204                 if($rows!=null){
00205                     foreach($rows as $row){
00206                         $result[] = array("IdRegion"=>$row->IdRegion,"Value"=>$row->Value,"IdParent"=>$row->IdParent, "Type"=>$row->Type);    
00207                     }
00208                     $resultCode=$result;    
00209                 }else{
00210                     $resultId = 3089;
00211                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00212                     $resultCode=$r['Message'];
00213                     $message=$r['Message'];
00214                     $type=3;
00215                 }
00216             }
00217             catch(Exception $e){
00218                 $resultCode=$e->getMessage();
00219                 $resultId=101;       
00220                 $type=3;
00221             }
00222                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00223                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00224             return $response;
00225         }
00226     
00227     //==== End getRegionByParent =========================================================================
00228     
00229     //==== Start getRegionRecursiveByParentId =========================================================================
00237         function getRegionRecursiveByParentId($parent_id=0,$array_by_parent=array(),$array_by_id=array()){
00238                 if(empty($array_by_id) && empty($array_by_parent))
00239                 {
00240                         $array_by_parent = $array_by_id = array();
00241                 
00242                         $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00243                                     ->from("Regions","*")
00244                                     ->order(array('IdParent','IdRegion')));
00245                         
00246                         foreach($rows as $row){         
00247                                 $array_by_parent[$row['IdParent']][]=$row->toArray();
00248                                 $array_by_id[$row['IdRegion']]=$row->toArray();
00249                         }                       
00250                         
00251                 }
00252                 
00253                 $array_de_returnat = array();
00254                 
00255                 if(!empty($array_by_parent[$parent_id]))
00256                 {
00257                         foreach ($array_by_parent[$parent_id] as $key=>$value)
00258                         {
00259                                 $count=count($array_de_returnat);
00260                                 $array_de_returnat[$count] = $value;
00261                                 $array_de_returnat[$count]['childs'] =$this->getRegionRecursiveByParentId($value['IdRegion'],$array_by_parent,$array_by_id);
00262                                 
00263                         }
00264                 }
00265                 
00266           return $array_de_returnat;    
00267     }
00268     
00269     //==== End getRegionRecursiveByParentId =========================================================================
00270     
00271     //==== Start deleteRegion =========================================================================
00279     function deleteRegion($entity){
00280             $resultId = 0;
00281             $page="regions.php";
00282             $method="deleteRegion";
00283             $result=json_encode($entity);
00284             $message="";
00285             $type="1";
00286             $this->ErrorCode = new ErrorCode;
00287             $this->Log = new Log;
00288 
00289         try{
00290             $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
00291                                                 ->from("Regions","*")
00292                                                 ->where("IdRegion=?",$Entity)
00293                                                 );
00294             if($sql!=null){
00295                 $this->delete($this->getAdapter()->quoteInto("IdRegion=?",$entity));
00296                 $resultCode="Date sterse";    
00297             }else{
00298                 $resultId = 3090;
00299                 $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00300                 $resultCode=$r['Message'];
00301                 $message=$r['Message'];
00302                 $type=3;
00303             }
00304             }
00305             catch(Exception $e){                
00306                 $resultCode=$e->getMessage();
00307                 $resultId=101;       
00308                 $type=3;
00309             }
00310                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00311                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00312             return $response;
00313     }
00314     //==== End deleteRegion =========================================================================
00315 }
00316 
00317 ?>