[ Index ] |
PHP Cross Reference of vtigercrm-6.1.0 |
[Summary view] [Print] [Text view]
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 VtigerCRMObject{ 12 13 private $moduleName ; 14 private $moduleId ; 15 private $instance ; 16 17 function VtigerCRMObject($moduleCredential, $isId=false){ 18 19 if($isId){ 20 $this->moduleId = $moduleCredential; 21 $this->moduleName = $this->getObjectTypeName($this->moduleId); 22 }else{ 23 $this->moduleName = $moduleCredential; 24 $this->moduleId = $this->getObjectTypeId($this->moduleName); 25 } 26 $this->instance = null; 27 $this->getInstance(); 28 } 29 30 public function getModuleName(){ 31 return $this->moduleName; 32 } 33 34 public function getModuleId(){ 35 return $this->moduleId; 36 } 37 38 public function getInstance(){ 39 if($this->instance == null){ 40 $this->instance = $this->getModuleClassInstance($this->moduleName); 41 } 42 return $this->instance; 43 } 44 45 public function getObjectId(){ 46 if($this->instance==null){ 47 $this->getInstance(); 48 } 49 return $this->instance->id; 50 } 51 52 public function setObjectId($id){ 53 if($this->instance==null){ 54 $this->getInstance(); 55 } 56 $this->instance->id = $id; 57 } 58 59 private function titleCase($str){ 60 $first = substr($str, 0, 1); 61 return strtoupper($first).substr($str,1); 62 } 63 64 private function getObjectTypeId($objectName){ 65 66 // Use getTabid API 67 $tid = getTabid($objectName); 68 69 if($tid === false) { 70 global $adb; 71 72 $sql = "select * from vtiger_tab where name=?;"; 73 $params = array($objectName); 74 $result = $adb->pquery($sql, $params); 75 $data1 = $adb->fetchByAssoc($result,1,false); 76 77 $tid = $data1["tabid"]; 78 } 79 // END 80 81 return $tid; 82 83 } 84 85 private function getModuleClassInstance($moduleName){ 86 return CRMEntity::getInstance($moduleName); 87 } 88 89 private function getObjectTypeName($moduleId){ 90 91 return getTabModuleName($moduleId); 92 93 } 94 95 private function getTabName(){ 96 if($this->moduleName == 'Events'){ 97 return 'Calendar'; 98 } 99 return $this->moduleName; 100 } 101 102 public function read($id){ 103 global $adb; 104 105 $error = false; 106 $adb->startTransaction(); 107 $this->instance->retrieve_entity_info($id,$this->getTabName()); 108 $error = $adb->hasFailedTransaction(); 109 $adb->completeTransaction(); 110 return !$error; 111 } 112 113 public function create($element){ 114 global $adb; 115 116 $error = false; 117 foreach($element as $k=>$v){ 118 $this->instance->column_fields[$k] = $v; 119 } 120 121 $adb->startTransaction(); 122 $this->instance->Save($this->getTabName()); 123 $error = $adb->hasFailedTransaction(); 124 $adb->completeTransaction(); 125 return !$error; 126 } 127 128 public function update($element){ 129 130 global $adb; 131 $error = false; 132 133 foreach($element as $k=>$v){ 134 $this->instance->column_fields[$k] = $v; 135 } 136 137 $adb->startTransaction(); 138 $this->instance->mode = "edit"; 139 $this->instance->Save($this->getTabName()); 140 $error = $adb->hasFailedTransaction(); 141 $adb->completeTransaction(); 142 return !$error; 143 } 144 145 public function revise($element){ 146 global $adb; 147 $error = false; 148 149 $error = $this->read($this->getObjectId()); 150 if($error == false){ 151 return $error; 152 } 153 154 foreach($element as $k=>$v){ 155 $this->instance->column_fields[$k] = $v; 156 } 157 158 //added to fix the issue of utf8 characters 159 foreach($this->instance->column_fields as $key=>$value){ 160 $this->instance->column_fields[$key] = decode_html($value); 161 } 162 163 $adb->startTransaction(); 164 $this->instance->mode = "edit"; 165 $this->instance->Save($this->getTabName()); 166 $error = $adb->hasFailedTransaction(); 167 $adb->completeTransaction(); 168 return !$error; 169 } 170 171 public function delete($id){ 172 global $adb; 173 $error = false; 174 $adb->startTransaction(); 175 DeleteEntity($this->getTabName(), $this->getTabName(), $this->instance, $id,$returnid); 176 $error = $adb->hasFailedTransaction(); 177 $adb->completeTransaction(); 178 return !$error; 179 } 180 181 public function getFields(){ 182 return $this->instance->column_fields; 183 } 184 185 function exists($id){ 186 global $adb; 187 188 $exists = false; 189 $sql = "select * from vtiger_crmentity where crmid=? and deleted=0"; 190 $result = $adb->pquery($sql , array($id)); 191 if($result != null && isset($result)){ 192 if($adb->num_rows($result)>0){ 193 $exists = true; 194 } 195 } 196 return $exists; 197 } 198 199 function getSEType($id){ 200 global $adb; 201 202 $seType = null; 203 $sql = "select * from vtiger_crmentity where crmid=? and deleted=0"; 204 $result = $adb->pquery($sql , array($id)); 205 if($result != null && isset($result)){ 206 if($adb->num_rows($result)>0){ 207 $seType = $adb->query_result($result,0,"setype"); 208 } 209 } 210 return $seType; 211 } 212 213 } 214 215 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:08:37 2014 | Cross-referenced by PHPXref 0.7.1 |