[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/Webservices/ -> VtigerWebserviceObject.php (source)

   1  <?php
   2  /*+***********************************************************************************
   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.0
   4   * ("License"); You may not use this file except in compliance with the License
   5   * The Original Code is:  vtiger CRM Open Source
   6   * The Initial Developer of the Original Code is vtiger.
   7   * Portions created by vtiger are Copyright (C) vtiger.
   8   * All Rights Reserved.
   9   *************************************************************************************/
  10  
  11  class VtigerWebserviceObject{
  12      
  13      private $id;
  14      private $name;
  15      private $handlerPath;
  16      private $handlerClass;
  17      
  18  	private function VtigerWebserviceObject($entityId,$entityName,$handler_path,$handler_class){
  19          $this->id = $entityId;
  20          $this->name = $entityName;
  21          // Quick Fix to override default Actor class & path (good to update DB itself)
  22          if ($entityName == 'CompanyDetails') {
  23              $handler_path = 'include/Webservices/Custom/VtigerCompanyDetails.php';
  24              $handler_class= 'VtigerCompanyDetails';
  25          }
  26          // END
  27          $this->handlerPath = $handler_path;
  28          $this->handlerClass = $handler_class;
  29      }
  30      
  31      // Cache variables to enable result re-use
  32      private static $_fromNameCache = array();
  33          
  34  	static function fromName($adb,$entityName){
  35          
  36          $rowData = false;
  37          
  38          // If the information not available in cache?
  39          if(!isset(self::$_fromNameCache[$entityName])) {
  40              $cacheLength = count(self::$_fromNameCache);
  41              
  42              $result = null;
  43              if ($cacheLength == 0) {
  44                  $result = $adb->pquery("select * from vtiger_ws_entity where name=?",array($entityName));
  45              } else {
  46                  // Could repeat more number of times...so let us pull rest of details into cache.
  47                  $result = $adb->pquery("select * from vtiger_ws_entity", array());
  48              }
  49              
  50              if($result){
  51                  $rowCount = $adb->num_rows($result);
  52                  while ($rowCount > 0) {
  53                      $rowData = $adb->query_result_rowdata($result,$rowCount-1);
  54                      self::$_fromNameCache[$rowData['name']] = $rowData;
  55                      --$rowCount;
  56                  }
  57              }
  58          }
  59          
  60          $rowData = self::$_fromNameCache[$entityName];
  61          
  62          if($rowData) {
  63              return new VtigerWebserviceObject($rowData['id'],$rowData['name'],
  64                          $rowData['handler_path'],$rowData['handler_class']);
  65          }
  66          throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED,"Permission to perform the operation is denied for name");
  67      }
  68  
  69      // Cache variables to enable result re-use
  70      private static $_fromIdCache = array();    
  71      
  72  	static function fromId($adb,$entityId){        
  73          $rowData = false;
  74          
  75          // If the information not available in cache?
  76          if(!isset(self::$_fromIdCache[$entityId])) {
  77              $result = $adb->pquery("select * from vtiger_ws_entity where id=?",array($entityId));
  78              if($result){
  79                  $rowCount = $adb->num_rows($result);
  80                  if($rowCount === 1){
  81                      $rowData = $adb->query_result_rowdata($result,0);
  82                      self::$_fromIdCache[$entityId] = $rowData;
  83                  }
  84              }
  85          }
  86          
  87          $rowData = self::$_fromIdCache[$entityId];
  88          
  89          if($rowData) {
  90              return new VtigerWebserviceObject($rowData['id'],$rowData['name'],
  91                      $rowData['handler_path'],$rowData['handler_class']);
  92          }
  93          
  94          throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED,"Permission to perform the operation is denied for id");
  95      }
  96      
  97  	static function fromQuery($adb,$query){
  98          $moduleRegex = "/[fF][rR][Oo][Mm]\s+([^\s;]+)/";
  99          $matches = array();
 100          $found = preg_match($moduleRegex,$query,$matches);
 101          if($found === 1){
 102              return VtigerWebserviceObject::fromName($adb,trim($matches[1]));
 103          }
 104          throw new WebServiceException(WebServiceErrorCode::$ACCESSDENIED,"Permission to perform the operation is denied for query");
 105      }
 106      
 107  	public function getEntityName(){
 108          return $this->name;
 109      }
 110      
 111  	public function getEntityId(){
 112          return $this->id;
 113      }
 114      
 115  	public function getHandlerPath(){
 116          return $this->handlerPath;
 117      }
 118      
 119  	public function getHandlerClass(){
 120          return $this->handlerClass;
 121      }
 122      
 123  }
 124  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1