Next4Me
 All Data Structures Files Functions Variables
application/models/Contexts.php
Go to the documentation of this file.
00001 <?php 
00017 class Contexts   extends Zend_Db_Table_Abstract {
00018         //put your code here
00019         protected $_name="Contexts"; 
00020         protected $_primary="IdContext"; 
00021 
00022 
00023         //==== Start AddEditContexts =========================================================================
00036         function AddEditContexts($entity) {
00037                         // function implementation
00038             $resultId = 0;
00039             $page="Contexts.php";
00040             $method="AddEditContexts";
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['IdContext']=="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("Contexts","*")
00055                     ->where("IdContext=?",$entity['IdContext'])
00056                     );
00057                 if($rows!=null){
00058                     $this->update(array(
00059                         "IdTplContext"=>$entity['IdTplContext'], 
00060                         "Name" => $entity['Name'], 
00061                         "Description"=>$entity['Description'],
00062                         //"IdUser" => $entity['IdUser'], 
00063                     ),$this->getAdapter()->quoteInto('IdContext=?',$entity['IdContext']));
00064                     $k=$entity['IdContext'];
00065                     $resultCode=$k;
00066                 }else{
00067                     $resultId = 3007;
00068                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00069                     $resultCode=$r['Message'];
00070                     $message=$r['Message'];
00071                     $type=3;                        
00072                 }
00073                }
00074                 
00075             }
00076             catch(Exception $e){
00077                 $resultCode=$e->getMessage();
00078                 $resultId=101;       
00079                 $type=3;
00080             }
00081                 $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00082                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00083          return $response;
00084         }
00085         //============ End AddEditContexts ==============================================================
00086 
00087 
00088         //==== Start DeleteContexts =========================================================================
00098         function DeleteContexts($entity) {
00099                         // function implementation
00100             $resultId = 0;
00101             $page="Contexts.php";
00102             $method="DeleteContexts";
00103             $result=json_encode($entity);
00104             $message="";
00105             $type="1";
00106             $this->ErrorCode = new ErrorCode;
00107             $this->Log = new Log;
00108 
00109             try{
00110                 $rows = $this->fetchRow($this->select()->setIntegrityCheck(false)
00111                             ->from("Contexts","*")
00112                             ->where("IdContext=?",$entity['IdContext'])
00113                     );
00114                 if($rows==null){
00115                     $resultId = 3008;
00116                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00117                     $resultCode=$r['Message'];
00118                     $message=$r['Message'];
00119                     $type=3;
00120                 }else{
00121                     $chld = $this->fetchRow($this->select()->setIntegrityCheck(false)
00122                             ->from("ContextConditions","*")
00123                             ->where("IdContext=?",$entity['IdContext'])
00124                     );
00125                     if($chld==null){
00126                         $k=$this->delete($this->getAdapter()->quoteInto("IdContext=?",$entity['IdContext']));
00127                         $resultCode="Date sterse";
00128                 }else{
00129                     $resultId = 4002;
00130                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00131                     $resultCode=$r['Message'];
00132                     $message=$r['Message'];
00133                     $type=3;                        
00134                     }
00135                 }
00136             }
00137             catch(Exception $e){
00138                 $resultCode=$e->getMessage();
00139                 $resultId=101;       
00140                 $type=3;
00141             }
00142                 $this->Log->save($page,$method,$result,$resultId.'=>'.$resultCode,$type);
00143                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00144             return $response;
00145         }
00146         //============ End DeleteContexts ==============================================================
00147 
00148 
00149         //==== Start GetContexts =========================================================================
00159         function GetContexts($entity) {
00160                         // function implementation
00161             $resultId = 0;
00162             $page="Contexts.php";
00163             $method="GetContexts";
00164             $result=json_encode($entity);
00165             $message="";
00166             $type="1";
00167             $this->ErrorCode = new ErrorCode;
00168             $this->Log = new Log;
00169 
00170             try{
00171                 $rows = $this->fetchAll($this->select()->setIntegrityCheck(false)
00172                             ->from("Contexts","*")
00173                             ->where("IdContext=?",$entity['IdContext'])
00174                             ->orWhere("0=?", $entity['IdContext'])
00175                     );
00176             
00177                 
00178                 if(count($rows)==0){
00179                     $resultId = 3009;
00180                     $r=$this->ErrorCode->GetErrorCode($resultId,Zend_Registry::get('language'));
00181                     $resultCode=$r['Message'];
00182                     $message=$r['Message'];
00183                     $type=3;
00184                 }else{
00185                 foreach($rows as $row){
00186 
00187                     $resultCode[]=array("IdContext"=>$row->IdContext,
00188                         "IdTplContext"=>$row->IdTplContext, 
00189                         "Name"=>$row->Name,
00190                         "Description"=>$row->Description,
00191                         "IdUser"=>$row->IdUser
00192                         );
00193                 }
00194                 
00195                 }
00196                 
00197             }
00198             catch(Exception $e){
00199                 $resultCode=$e->getMessage();
00200                 $resultId=101;       
00201                 $type=3;
00202             }
00203                 $this->Log->save($page,$method,$result,$resultId.'=>'.json_encode($resultCode),$type);
00204                 $response=array("resultId"=>$resultId,"resultCode"=>$resultCode);
00205          return $response;
00206         }
00207         //============ End GetContexts ==============================================================
00208 
00209 }
00210 
00211 
00212 ?>