[ 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 require_once 'data/VTEntityDelta.php'; 11 require_once 'includes/runtime/Cache.php'; 12 13 class VTWorkflowEntity{ 14 function __construct($user, $id){ 15 try { 16 $this->moduleName = null; 17 $this->id = $id; 18 $this->user = $user; 19 $data = vtws_retrieve($id, $user); 20 foreach($data as $key => $value){ 21 if(is_string($value)){ 22 $data[$key] = html_entity_decode($value, ENT_QUOTES, 'utf-8'); 23 } 24 } 25 $this->data = $data; 26 VTEntityCache::setCachedEntity($id, $this); 27 }catch(Exception $ex) { 28 } 29 } 30 /** 31 * Get the data from the entity object as an array. 32 * 33 * @return An array representation of the module data. 34 */ 35 function getData(){ 36 return $this->data; 37 } 38 39 /** 40 * Get the entity id. 41 * 42 * @return The entity id. 43 */ 44 function getId(){ 45 return $this->data['id']; 46 } 47 48 /** 49 * Get the name of the module represented by the entity data object. 50 * 51 * @return The module name. 52 */ 53 function getModuleName(){ 54 $cache = Vtiger_Cache::getInstance(); 55 56 if($this->moduleName==null){ 57 global $adb; 58 $wsId = $this->data['id']; 59 $parts = explode('x', $wsId); 60 if($cache->getModuleName($parts[0])){ 61 $this->moduleName=$cache->getModuleName($parts[0]); 62 } else { 63 $result = $adb->pquery('select name from vtiger_ws_entity where id=?', 64 array($parts[0])); 65 $rowData = $adb->raw_query_result_rowdata($result, 0); 66 $this->moduleName = $rowData['name']; 67 $cache->setModuleName($parts[0], $this->moduleName); 68 } 69 } 70 return $this->moduleName; 71 } 72 73 function get($fieldName){ 74 return $this->data[$fieldName]; 75 } 76 77 function set($fieldName, $value){ 78 79 $this->data[$fieldName] = $value; 80 } 81 82 function save(){ 83 vtws_update($this->data,$this->user); 84 } 85 86 function isNew() { 87 $wsId = $this->data['id']; 88 $parts = explode('x', $wsId); 89 $recordId = $parts[1]; 90 $entityDelta = new VTEntityDelta(); 91 $oldEntity = $entityDelta->getOldEntity($this->moduleName, $recordId); 92 if($oldEntity == null) { 93 return true; 94 } else { 95 return false; 96 } 97 } 98 99 } 100 101 class VTEntityCache{ 102 function __construct($user){ 103 $this->user = $user; 104 $this->cache = array(); 105 } 106 107 static $_vtWorflow_entity_cache = array(); 108 function forId($id){ 109 if($this->cache[$id]==null){ 110 $entity = VTEntityCache::getCachedEntity($id); 111 if(!$entity) { 112 $data = new VTWorkflowEntity($this->user, $id); 113 $this->cache[$id] = $data; 114 } else { 115 return $entity; 116 } 117 } 118 return $this->cache[$id]; 119 } 120 121 public static function getCachedEntity($id) { 122 return self::$_vtWorflow_entity_cache[$id]; 123 } 124 125 public static function setCachedEntity($id, $entity) { 126 self::$_vtWorflow_entity_cache[$id] = $entity; 127 } 128 } 129 ?>
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 |