Next4Me
 All Data Structures Files Functions Variables
application/models/entity.php
Go to the documentation of this file.
00001 <?php
00012 class Entity extends Zend_Db_Table_Abstract {
00013     //put your code here
00014     protected $_name="EntityTypes"; 
00015     protected $_primary="IdEntityType"; 
00016     
00017     //==== Start addEditEntity =========================================================================
00028     function addEditEntity($entity){
00029             $resultId = 0;
00030             $page="entity.php";
00031             $method="addEditEntity";
00032             $result=json_encode($entity);
00033             $message="";
00034             $type="1";
00035             $this->ErrorCode = new ErrorCode;
00036             $this->Log = new Log;
00037 
00038         try{
00039             if ($entity['IdEntityType']=="0"){
00040                 $k=$this->insert($entity);
00041                 $k=$this->getAdapter()->lastInsertId();
00042                 $resultCode=$k;
00043             }else{
00044                 $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
00045                                                 ->from("EntityTypes","*")
00046                                                 ->where("IdEntityType=?",$Entity['IdEntityType'])
00047                                                 );
00048                 if($rows!=null){
00049                 $this->update(array(
00050                     "Type" => $entity['Type'],
00051                     "IdParent" => $entity['IdParent'], 
00052                 ),$this->getAdapter()->quoteInto('IdEntityType=?',$entity['IdEntityType']));
00053                 $k=$entity['IdEntityType'];
00054                 }else{
00055                     $resultId = 3079;
00056                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00057                     $resultCode=$r['Message'];
00058                     $message=$r['Message'];
00059                     $type=3;
00060                 }
00061             }
00062             
00063             
00064             }
00065             catch(Exception $e){
00066              
00067                 $resultCode=$e->getMessage();
00068                 $resultId=101;       
00069                 $type=3;
00070             
00071             }
00072             $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00073                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00074          return $response;
00075       return $response;    
00076     }
00077     //==== End addEditEntity =========================================================================
00078     
00079     //==== Start getEntityById =========================================================================
00088     function getEntityById($Entity){
00089             $resultId = 0;
00090             $page="entity.php";
00091             $method="getEntityById";
00092             $result=json_encode($entity);
00093             $message="";
00094             $type="1";
00095             $this->ErrorCode = new ErrorCode;
00096             $this->Log = new Log;
00097 
00098         try{
00099             $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
00100                                                 ->from("EntityTypes","*")
00101                                                 ->where("IdEntityType=?",$Entity['IdEntityType'])
00102                                                 );
00103             if($sql!=null){
00104                     $resultCode = array("IdEntityType"=>$sql->IdEntityType,"Type"=>$sql->Type,"IdParent"=>$sql->IdParent);                       
00105                 }else{
00106                     $resultId = 3080;
00107                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00108                     $resultCode=$r['Message'];
00109                     $message=$r['Message'];
00110                     $type=3;
00111                 }
00112                         
00113                 
00114             
00115             
00116         }
00117         catch(Exception $e){
00118                 $resultCode=$e->getMessage();
00119                 $resultId=101;       
00120                 $type=3;
00121             }
00122                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00123                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00124          return $response;
00125                     
00126     }
00127     //==== End getEntityById =========================================================================
00128     
00129     //==== Start getEntityType =========================================================================
00138     function getEntityType($Entity){
00139             $resultId = 0;
00140             $page="entity.php";
00141             $method="getEntityType";
00142             $result=json_encode($entity);
00143             $message="";
00144             $type="1";
00145             $this->ErrorCode = new ErrorCode;
00146             $this->Log = new Log;
00147 
00148         try{
00149             $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
00150                                                 ->from("EntityTypes","*")
00151                                                 ->where("Type=?",$Entity['Type'])
00152                                                 );
00153             if($sql!=null){
00154                     $resultCode = array("IdEntityType"=>$sql->IdEntityType,"Type"=>$sql->Type,"IdParent"=>$sql->IdParent);    
00155                 }else{
00156                     $resultId = 3081;
00157                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00158                     $resultCode=$r['Message'];
00159                     $message=$r['Message'];
00160                     $type=3;
00161                 }
00162             
00163         }
00164         catch(Exception $e){
00165                 $resultCode=$e->getMessage();
00166                 $resultId=101;       
00167                 $type=3;
00168             }
00169                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00170                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00171          return $response;
00172     }
00173     //==== End getEntityType =========================================================================
00174     
00175     //==== Start getEntityByIdParent =========================================================================
00185     function getEntityByIdParent($Entity){
00186             $resultId = 0;
00187             $page="entity.php";
00188             $method="getEntityByIdParent";
00189             $result=json_encode($entity);
00190             $message="";
00191             $type="1";
00192             $this->ErrorCode = new ErrorCode;
00193             $this->Log = new Log;
00194 
00195         try{
00196             $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00197                             ->from("EntityTypes","*")
00198                             ->where("IdParent=?",$Entity['IdParent'])
00199                     );
00200             //$response =array();
00201             if($rows!=null){
00202                 foreach($rows as $row){
00203 
00204                     $resultCode[]=array("IdEntityType"=>$row->IdEntityType, "Type"=>$row->Type, "IdParent"=>$row->IdParent);
00205                     
00206                 }
00207             }else{
00208                 $resultId = 3082;
00209                 $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00210                 $resultCode=$r['Message'];
00211                 $message=$r['Message'];
00212                 $type=3;
00213             }
00214         }
00215         catch(Exception $e){
00216                 $resultCode=$e->getMessage();
00217                 $resultId=101;       
00218                 $type=3;
00219             }
00220                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00221                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00222          return $response;
00223     }        
00224     //==== End getEntityByIdParent =========================================================================
00225     
00226     //==== Start getEntityByParentType =========================================================================
00237     function getEntityByParentType($Entity){
00238             $resultId = 0;
00239             $page="entity.php";
00240             $method="getEntityByParentType";
00241             $result=json_encode($entity);
00242             $message="";
00243             $type="1";
00244             $this->ErrorCode = new ErrorCode;
00245             $this->Log = new Log;
00246 
00247         try{
00248             $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
00249                                                 ->from("EntityTypes","*")
00250                                                 ->where("Type=?",$Entity['Type'])
00251                                                 );
00252             if($sql==null){
00253                 $resultId = 3084;
00254                 $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00255                 $resultCode=$r['Message'];
00256                 $message=$r['Message'];
00257                 $type=3;
00258             }else{
00259             $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00260                             ->from("EntityTypes","*")
00261                             ->where("IdParent=?",$sql->IdEntityType)
00262                     );
00263         
00264             if($rows==null){
00265                 $resultId = 3083;
00266                 $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00267                 $resultCode=$r['Message'];
00268                 $message=$r['Message'];
00269                 $type=3;
00270             }else{
00271                 foreach($rows as $row){
00272                     $resultCode[] = array("IdEntityType"=>$row->IdEntityType,"Type"=>$row->Type,"IdParent"=>$row->IdParent);    
00273                 }
00274                 
00275             }
00276             }
00277             
00278             
00279         }
00280         catch(Exception $e){
00281                 $resultCode=$e->getMessage();
00282                 $resultId=101;       
00283                 $type=3;
00284             }
00285                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00286                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00287          return $response;
00288     }
00289     //==== End getEntityByParentType =========================================================================
00290     
00291     //==== Start getEntityTree =========================================================================
00300     function getEntityTree($parent_id=0,$array_by_parent=array(),$array_by_id=array()){
00301             if(empty($array_by_id) && empty($array_by_parent))
00302             {
00303                     $array_by_parent = $array_by_id = array();
00304 
00305                     $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00306                                 ->from("EntityTypes","*")
00307                                 ->order(array('IdParent','IdEntityType')));
00308                     foreach($rows as $row){             
00309                             $array_by_parent[$row['IdParent']][]=$row->toArray();
00310                             $array_by_id[$row['IdEntityType']]=$row->toArray();
00311                     }                   
00312 
00313             }
00314             $array_de_returnat = array();
00315 
00316             if(!empty($array_by_parent[$parent_id]))
00317             {
00318                     foreach ($array_by_parent[$parent_id] as $key=>$value)
00319                     {
00320                             $count=count($array_de_returnat);
00321                             $array_de_returnat[$count] = $value;
00322                             $array_de_returnat[$count]['childs'] =$this->getEntityTree($value['IdEntityType'],$array_by_parent,$array_by_id);
00323                     }
00324             }
00325         
00326          
00327                 return $array_de_returnat;
00328     }
00329     //==== End getEntityTree =========================================================================
00330     
00331     //==== Start deleteEntity =========================================================================
00340     function deleteEntity($entity){
00341             $resultId = 0;
00342             $page="entity.php";
00343             $method="deleteEntity";
00344             $result=json_encode($entity);
00345             $message="";
00346             $type="1";
00347             $this->ErrorCode = new ErrorCode;
00348             $this->Log = new Log;
00349 
00350         try{
00351             $sql = $this->fetchRow($this->select()->setIntegrityCheck(false)
00352                                                 ->from("EntityTypes","*")
00353                                                 ->where("IdEntityType=?",$Entity['IdEntityType'])
00354                                                 );
00355             if($sql!=null){
00356             $k=$this->delete($this->getAdapter()->quoteInto("IdEntityType=?",$entity['IdEntityType']));
00357              $resultCode="Date sterse";    
00358             }else{
00359                 $resultId = 3085;
00360                 $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00361                 $resultCode=$r['Message'];
00362                 $message=$r['Message'];
00363                 $type=3;
00364             }
00365             
00366         }
00367         catch(Exception $e){
00368                 $resultCode=$e->getMessage();
00369                 $resultId=101;       
00370                 $type=3;
00371             }
00372                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00373                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00374          return $response;
00375     }
00376 
00377     //==== End deleteEntity =========================================================================
00378 }
00379 
00380 ?>