Next4Me
 All Data Structures Files Functions Variables
application/models/ContextFactors.php
Go to the documentation of this file.
00001 <?php 
00015 class ContextFactors   extends Zend_Db_Table_Abstract {
00016         //put your code here
00017         protected $_name="ContextFactors"; 
00018         protected $_primary="IdContextFactor"; 
00019 
00020 
00021         //==== Start AddEditContextFactors =========================================================================
00037         function AddEditContextFactors($entity) {
00038                         // function implementation
00039             $resultId = 0;
00040             $page="ContextFactors.php";
00041             $method="AddEditContextFactors";
00042             $result=json_encode($entity);
00043             $message="";
00044             $type="1";
00045             $this->ErrorCode = new ErrorCode;
00046             $this->Log = new Log;
00047 
00048             try{
00049                 if ($entity['IdContextFactor']=="0"){
00050                     $k=$this->insert($entity);
00051                     $k=$this->getAdapter()->lastInsertId();
00052                     $resultCode=$k;    
00053                 }else{
00054                         $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
00055                     ->from("ContextFactors","*")
00056                     ->where("IdContextFactor=?",$entity['IdContextFactor'])
00057                     );
00058                 if($rows!=null){
00059                     $IdContextCondition=$rows->IdContextCondition;
00060                     if($IdContextCondition==$entity['IdContextCondition']){
00061                         $this->update(array(
00062                             "IdContextCondition"=>$entity['IdContextCondition'], 
00063                             "IdTplContextFactors"=>$entity['IdTplContextFactors'],
00064                             "Description" => $entity['Description'], 
00065                             "Type" => $entity['Type'],
00066                             "Function" => $entity['Function'],
00067                             "Value" => $entity['Value'],
00068                         ),$this->getAdapter()->quoteInto('IdContextFactor=?',$entity['IdContextFactor']));
00069                         $k=$entity['IdContextFactor'];
00070                         $resultCode=$k;
00071                      }else{
00072                         $resultId = 5003;
00073                         $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00074                         $resultCode=$r['Message'];
00075                         $message=$r['Message'];
00076                         $type=3;
00077                     }    
00078                 }else{
00079                     $resultId = 3013;
00080                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00081                     $resultCode=$r['Message'];
00082                     $message=$r['Message'];
00083                     $type=3;
00084                 }
00085                 }
00086             }
00087             catch(Exception $e){
00088                 $resultCode=$e->getMessage();
00089                 $resultId=101;       
00090                 $type=3;
00091             }
00092                 $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00093                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00094          return $response;
00095         }
00096         //============ End AddEditContextFactors ==============================================================
00097 
00098 
00099         //==== Start DeleteContextFactors =========================================================================
00108         function DeleteContextFactors($entity) {
00109                         // function implementation
00110             $resultId = 0;
00111             $page="ContextFactors.php";
00112             $method="DeleteContextFactors";
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("ContextFactors","*")
00122                             ->where("IdContextFactor=?",$entity['IdContextFactor'])
00123                     );
00124                 if($rows==null){
00125                     $resultId = 3014;
00126                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00127                     $resultCode=$r['Message'];
00128                     $message=$r['Message'];
00129                     $type=3;
00130                 }else{
00131                 $k=$this->delete($this->getAdapter()->quoteInto("IdContextFactor=?",$entity['IdContextFactor']));
00132                  $resultCode="Date sterse";    
00133                 }
00134             }
00135             catch(Exception $e){
00136                 $resultCode=$e->getMessage();
00137                 $resultId=101;       
00138                 $type=3;
00139             }
00140                 $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00141                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00142             return $response;
00143         }
00144         //============ End DeleteContextFactors ==============================================================
00145 
00146 
00147         //==== Start GetContextFactors =========================================================================
00157         function GetContextFactors($entity) {
00158                         // function implementation
00159             $resultId = 0;
00160             $page="ContextFactors.php";
00161             $method="GetContextFactors";
00162             $result=json_encode($entity);
00163             $message="";
00164             $type="1";
00165             $this->ErrorCode = new ErrorCode;
00166             $this->Log = new Log;
00167 
00168             try{
00169                 $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00170                             ->from("ContextFactors","*")
00171                             ->where("IdContextFactor=?",$entity['IdContextFactor'])
00172                             ->orWhere("0=?", $entity['IdContextFactor'])
00173                     );
00174             if(count($rows)!=0){
00175                 foreach($rows as $row){
00176 
00177                     $resultCode[]=array("IdContextFactor"=>$row->IdContextFactor,
00178                         "IdContextCondition"=>$row->IdContextCondition, 
00179                         "IdTplContextFactors"=>$row->IdTplContextFactors,
00180                         "Description"=>$row->Description,
00181                         "Type"=>$row->Type,
00182                         "Function"=>$row->Function,
00183                         "Value"=>$row->Value);
00184                 }
00185             }else{
00186                 $resultId = 3015;
00187                 $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00188                 $resultCode=$r['Message'];
00189                 $message=$r['Message'];
00190                 $type=3;
00191             }
00192             }
00193             catch(Exception $e){
00194                 $resultCode=$e->getMessage();
00195                 $resultId=101;       
00196                 $type=3;
00197             }
00198                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00199                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00200          return $response;
00201         }
00202         //============ End GetContextFactors ==============================================================
00203 
00204 }
00205 
00206 
00207 ?>