[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/include/Webservices/ -> EntityMeta.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  abstract class EntityMeta{
  12      
  13      public static $RETRIEVE = "DetailView";
  14      public static $CREATE = "Save";
  15      public static $UPDATE = "EditView";
  16      public static $DELETE = "Delete";
  17      
  18      protected $webserviceObject;
  19      protected $objectName;
  20      protected $objectId;
  21      protected $user;
  22      protected $baseTable;
  23      protected $tableList;
  24      protected $tableIndexList;
  25      protected $defaultTableList;
  26      protected $idColumn;
  27      
  28      protected $userAccessibleColumns;
  29      protected $columnTableMapping;
  30      protected $fieldColumnMapping;
  31      protected $mandatoryFields;
  32      protected $referenceFieldDetails;
  33      protected $emailFields;
  34      protected $ownerFields;
  35      protected $moduleFields = null;
  36      
  37  	protected function EntityMeta($webserviceObject,$user){
  38          $this->webserviceObject = $webserviceObject;
  39          $this->objectName = $this->webserviceObject->getEntityName();
  40          $this->objectId = $this->webserviceObject->getEntityId();
  41          
  42          $this->user = $user;
  43      }
  44      
  45  	public function getEmailFields(){
  46          if($this->emailFields === null){
  47              $this->emailFields =  array();
  48              $moduleFields = $this->getModuleFields();
  49              foreach ($moduleFields as $fieldName=>$webserviceField) {
  50                  if(strcasecmp($webserviceField->getFieldType(),'e') === 0){
  51                      array_push($this->emailFields, $fieldName);
  52                  }
  53              }
  54          }
  55          
  56          return $this->emailFields;
  57      }
  58      
  59  	public function getFieldColumnMapping(){
  60          if($this->fieldColumnMapping === null){
  61              $this->fieldColumnMapping =  array();
  62              
  63              $moduleFields = $this->getModuleFields();
  64              foreach ($moduleFields as $fieldName=>$webserviceField) {
  65                  $this->fieldColumnMapping[$fieldName] = $webserviceField->getColumnName();
  66              }
  67              $this->fieldColumnMapping['id'] = $this->idColumn;
  68          }
  69          return $this->fieldColumnMapping;
  70      }
  71      
  72  	public function getMandatoryFields(){
  73          if($this->mandatoryFields === null){
  74              $this->mandatoryFields =  array();
  75              
  76              $moduleFields = $this->getModuleFields();
  77              foreach ($moduleFields as $fieldName=>$webserviceField) {
  78                  if($webserviceField->isMandatory() === true){
  79                      array_push($this->mandatoryFields,$fieldName);
  80                  }
  81              }
  82          }
  83          return $this->mandatoryFields;
  84      }
  85      
  86  	public function getReferenceFieldDetails(){
  87          if($this->referenceFieldDetails === null){
  88              $this->referenceFieldDetails =  array();
  89              
  90              $moduleFields = $this->getModuleFields();
  91              foreach ($moduleFields as $fieldName=>$webserviceField) {
  92                  if(strcasecmp($webserviceField->getFieldDataType(),'reference') === 0){
  93                      $this->referenceFieldDetails[$fieldName] = $webserviceField->getReferenceList();
  94                  }
  95              }
  96          }
  97          return $this->referenceFieldDetails;
  98      }
  99      
 100  	public function getOwnerFields(){
 101          if($this->ownerFields === null){
 102              $this->ownerFields =  array();
 103              
 104              $moduleFields = $this->getModuleFields();
 105              foreach ($moduleFields as $fieldName=>$webserviceField) {
 106                  if(strcasecmp($webserviceField->getFieldDataType(),'owner') === 0){
 107                      array_push($this->ownerFields, $fieldName);
 108                  }
 109              }
 110          }
 111          return $this->ownerFields;
 112      }
 113      
 114  	public function getObectIndexColumn(){
 115          return $this->idColumn;
 116      }
 117      
 118  	public function getUserAccessibleColumns(){
 119          if($this->userAccessibleColumns === null){
 120              $this->userAccessibleColumns =  array();
 121              
 122              $moduleFields = $this->getModuleFields();
 123              foreach ($moduleFields as $fieldName=>$webserviceField) {
 124                  array_push($this->userAccessibleColumns,$webserviceField->getColumnName());
 125              }
 126              array_push($this->userAccessibleColumns,$this->idColumn);
 127          }
 128          return $this->userAccessibleColumns;
 129      }
 130  
 131  	public function getFieldByColumnName($column){
 132          $fields = $this->getModuleFields();
 133          foreach ($fields as $fieldName=>$webserviceField) {
 134              if($column == $webserviceField->getColumnName()) {
 135                  return $webserviceField;
 136              }
 137          }
 138          return null;
 139      }
 140      
 141  	public function getColumnTableMapping(){
 142          if($this->columnTableMapping === null){
 143              $this->columnTableMapping =  array();
 144              
 145              $moduleFields = $this->getModuleFields();
 146              foreach ($moduleFields as $fieldName=>$webserviceField) {
 147                  $this->columnTableMapping[$webserviceField->getColumnName()] = $webserviceField->getTableName();
 148              }
 149              $this->columnTableMapping[$this->idColumn] = $this->baseTable;
 150          }
 151          return $this->columnTableMapping;
 152      }
 153      
 154  	function getUser(){
 155          return $this->user;
 156      }
 157      
 158  	function hasMandatoryFields($row){
 159          
 160          $mandatoryFields = $this->getMandatoryFields();
 161          $hasMandatory = true;
 162          foreach($mandatoryFields as $ind=>$field){
 163              // dont use empty API as '0'(zero) is a valid value.
 164              if( !isset($row[$field]) || $row[$field] === "" || $row[$field] === null ){
 165                  throw new WebServiceException(WebServiceErrorCode::$MANDFIELDSMISSING,
 166                          "$field does not have a value");
 167              }
 168          }
 169          return $hasMandatory;
 170          
 171      }
 172  	public function isUpdateMandatoryFields($element){
 173          if(!is_array($element)){
 174              throw new WebServiceException(WebServiceErrorCode::$MANDFIELDSMISSING,
 175                              "Mandatory field does not have a value");
 176          }
 177          $mandatoryFields = $this->getMandatoryFields();
 178          $updateFields = array_keys($element);
 179          $hasMandatory = true;
 180          $updateMandatoryFields = array_intersect($updateFields, $mandatoryFields);
 181          if(!empty($updateMandatoryFields)){
 182              foreach($updateMandatoryFields as $ind=>$field){
 183                  // dont use empty API as '0'(zero) is a valid value.
 184                  if( !isset($element[$field]) || $element[$field] === "" || $element[$field] === null ){
 185                      throw new WebServiceException(WebServiceErrorCode::$MANDFIELDSMISSING,
 186                              "$field does not have a value");
 187                  }
 188              }
 189          }
 190          return $hasMandatory;
 191      }
 192      
 193  	public function getModuleFields(){
 194          return $this->moduleFields;
 195      }
 196  
 197  	public function getFieldNameListByType($type) { 
 198          $type = strtolower($type); 
 199          $typeList = array(); 
 200          $moduleFields = $this->getModuleFields(); 
 201          foreach ($moduleFields as $fieldName=>$webserviceField) { 
 202              if(strcmp($webserviceField->getFieldDataType(),$type) === 0){ 
 203                  array_push($typeList, $fieldName); 
 204              } 
 205          } 
 206          return $typeList; 
 207      }
 208  
 209  	public function getFieldListByType($type) {
 210          $type = strtolower($type);
 211          $typeList = array();
 212          $moduleFields = $this->getModuleFields();
 213          foreach ($moduleFields as $fieldName=>$webserviceField) {
 214              if(strcmp($webserviceField->getFieldDataType(),$type) === 0){
 215                  array_push($typeList, $webserviceField);
 216              }
 217          }
 218          return $typeList;
 219      }
 220      
 221  	public function getIdColumn(){
 222          return $this->idColumn;
 223      }
 224  
 225  	public function getEntityBaseTable() {
 226          return $this->baseTable;
 227      }
 228  
 229  	public function getEntityTableIndexList() {
 230          return $this->tableIndexList;
 231      }
 232  
 233  	public function getEntityDefaultTableList() {
 234          return $this->defaultTableList;
 235      }
 236  
 237  	public function getEntityTableList() {
 238          return $this->tableList;
 239      }
 240  
 241  	public function getEntityAccessControlQuery(){
 242          $accessControlQuery = '';
 243          return $accessControlQuery;
 244      }
 245  
 246  	public function getEntityDeletedQuery(){
 247          if($this->getEntityName() == 'Leads') {
 248              return "vtiger_crmentity.deleted=0 and vtiger_leaddetails.converted=0";
 249          }
 250          if($this->getEntityName() != "Users"){
 251              return "vtiger_crmentity.deleted=0";
 252          }
 253          // not sure whether inactive users should be considered deleted or not.
 254          return "vtiger_users.status='Active'";
 255      }
 256  
 257      abstract function hasPermission($operation,$webserviceId);
 258      abstract function hasAssignPrivilege($ownerWebserviceId);
 259      abstract function hasDeleteAccess();
 260      abstract function hasAccess();
 261      abstract function hasReadAccess();
 262      abstract function hasWriteAccess();
 263      abstract function getEntityName();
 264      abstract function getEntityId();
 265      abstract function exists($recordId);
 266      abstract function getObjectEntityName($webserviceId);
 267      abstract public function getNameFields();
 268      abstract public function getName($webserviceId);
 269      abstract public function isModuleEntity();
 270  }
 271  ?>


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