Next4Me
 All Data Structures Files Functions Variables
application/models/ContextConditions.php
Go to the documentation of this file.
00001 <?php 
00016 class ContextConditions   extends Zend_Db_Table_Abstract {
00017         //put your code here
00018         protected $_name="ContextConditions"; 
00019         protected $_primary="IdContextCondition";  
00020 
00021 
00022         //==== Start AddEditContextConditions =========================================================================
00036         function AddEditContextConditions($entity) {
00037                         // function implementation
00038             $resultId = 0;
00039             $page="ContextConditions.php";
00040             $method="AddEditContextConditions";
00041             $result=json_encode($entity);
00042             $message="";
00043             $type="1";
00044             $this->ErrorCode = new ErrorCode;
00045             $this->Log = new Log;
00046 
00047             try{
00048                 if ($entity['IdContextCondition']=="0"){
00049                     $k=$this->insert($entity);
00050                     $k=$this->getAdapter()->lastInsertId();
00051                     $resultCode=$k;
00052                 }else{
00053                     $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
00054                     ->from("ContextConditions","*")
00055                     ->where("IdContextCondition=?",$entity['IdContextCondition'])
00056                     );
00057                 if($rows!=null){
00058                     $IdContext=$rows->IdContext;
00059                     if($IdContext==$entity['IdContext']){
00060                         $this->update(array(
00061                             "IdContext"=>$entity['IdContext'], 
00062                             "IdTplContextCondition"=>$entity['IdTplContextCondition'],
00063                             "Name" => $entity['Name'], 
00064                             "Description" => $entity['Description'],
00065                         ),$this->getAdapter()->quoteInto('IdContextCondition=?',$entity['IdContextCondition']));
00066                         $k=$entity['IdContextCondition'];
00067                         $resultCode=$k;
00068                         }else{
00069                             $resultId = 5002;
00070                             $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00071                             $resultCode=$r['Message'];
00072                             $message=$r['Message'];
00073                             $type=3;
00074                         }
00075                     }else{
00076                         $resultId = 3010;
00077                         $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00078                         $resultCode=$r['Message'];
00079                         $message=$r['Message'];
00080                         $type=3;
00081                     }    
00082                 }
00083                 
00084                 
00085             }
00086             catch(Exception $e){
00087                 $resultCode=$e->getMessage();
00088                 $resultId=101;       
00089                 $type=3;
00090             }
00091                 $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00092                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00093          return $response;
00094         }
00095         //============ End AddEditContextConditions ==============================================================
00096 
00097 
00098         //==== Start DeleteContextConditions =========================================================================
00108         function DeleteContextConditions($entity) {
00109                         // function implementation
00110             $resultId = 0;
00111             $page="ContextConditions.php";
00112             $method="DeleteContextConditions";
00113             $result=json_encode($entity);
00114             $message="";
00115             $type="1";
00116             $this->ErrorCode = new ErrorCode;
00117             $this->Log = new Log;
00118 
00119             try{
00120                 $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
00121                             ->from("ContextConditions","*")
00122                             ->where("IdContextCondition=?",$entity['IdContextCondition'])
00123                     );
00124                 if($rows==null){
00125                     $resultId = 3011;
00126                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00127                     $resultCode=$r['Message'];
00128                     $message=$r['Message'];
00129                     $type=3;
00130                 }else{
00131                     $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
00132                             ->from("ContextFactors","*")
00133                             ->where("IdContextCondition=?",$entity['IdContextCondition'])
00134                     );
00135                     if($chld==null){
00136                         $k=$this->delete($this->getAdapter()->quoteInto("IdContextCondition=?",$entity['IdContextCondition']));
00137                         $resultCode="Date sterse";    
00138                     }else{
00139                         $resultId = 4003;
00140                         $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00141                         $resultCode=$r['Message'];
00142                         $message=$r['Message'];
00143                         $type=3;
00144                     }
00145                 }
00146             }
00147             catch(Exception $e){
00148                 $resultCode=$e->getMessage();
00149                 $resultId=101;       
00150                 $type=3;
00151             }
00152                 $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00153                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00154             return $response;
00155         }
00156         //============ End DeleteContextConditions ==============================================================
00157 
00158 
00159         //==== Start GetContextConditions =========================================================================
00169         function GetContextConditions($entity) {
00170                         // function implementation
00171             $resultId = 0;
00172             $page="ContextConditions.php";
00173             $method="GetContextConditions";
00174             $result=json_encode($entity);
00175             $message="";
00176             $type="1";
00177             $this->ErrorCode = new ErrorCode;
00178             $this->Log = new Log;
00179 
00180             try{
00181                 $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00182                             ->from("ContextConditions","*")
00183                             ->where("IdContextCondition=?",$entity['IdContextCondition'])
00184                             ->orWhere("0=?", $entity['IdContextCondition'])
00185                     );
00186             
00187                 if(count($rows)!=0){
00188                     foreach($rows as $row){
00189 
00190                         $resultCode[]=array("IdContextCondition"=>$row->IdContextCondition,
00191                             "IdContext"=>$row->IdContext, 
00192                             "IdTplContextCondition"=>$row->IdTplContextCondition,
00193                             "Name"=>$row->Name,
00194                             "Description"=>$row->Description);
00195                     }
00196                     
00197                 }else{
00198                     $resultId = 3012;
00199                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00200                     $resultCode=$r['Message'];
00201                     $message=$r['Message'];
00202                     $type=3;
00203                 }
00204             }
00205             catch(Exception $e){
00206                 $resultCode=$e->getMessage();
00207                 $resultId=101;       
00208                 $type=3;
00209             }
00210                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00211                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00212          return $response;
00213         }
00214         //============ End GetContextConditions ==============================================================
00215 
00216 }
00217 
00218 
00219 ?>