[ 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 /** 12 * A wrapper around CRMEntity instances 13 */ 14 class VTEntityData{ 15 private $isNew = false; 16 17 /** 18 * Get an entity data object. 19 * 20 * @param $adb Pear database instance. 21 * @param $entityId The id of the entity to load. 22 * @return The new entity data object. 23 */ 24 static function fromEntityId($adb, $entityId, $moduleName=''){ 25 $obj = new VTEntityData(); 26 $obj->entityId = $entityId; 27 if(empty($moduleName)) { 28 $result = $adb->pquery("select setype from vtiger_crmentity where crmid=?", array($entityId)); 29 $setype = $adb->query_result($result,0,"setype"); 30 31 if($setype == 'Calendar') { 32 $setype = vtws_getCalendarEntityType($entityId); 33 } 34 35 $obj->moduleName = $setype; 36 } else { 37 $setype = $moduleName; 38 $obj->moduleName = $setype; 39 } 40 41 require_once ('data/CRMEntity.php'); 42 $focus = CRMEntity::getInstance($setype); 43 44 $focus->retrieve_entity_info($entityId, $setype); 45 $focus->id = $entityId; 46 $obj->isNew = false; 47 $obj->focus = $focus; 48 return $obj; 49 } 50 51 /** 52 * Get an entity data object. 53 * @param $adb Pear database instance. 54 * @param $userId The id of the entity to load. 55 * @return The new entity data object. 56 */ 57 static function fromUserId($adb,$userId){ 58 $obj = new VTEntityData(); 59 $obj->entityId = $userId; 60 61 $obj->moduleName = 'Users'; 62 63 require_once ('data/CRMEntity.php'); 64 $focus = CRMEntity::getInstance($obj->moduleName); 65 66 $focus->retrieve_entity_info($userId, $obj->moduleName); 67 $focus->id = $userId; 68 $obj->isNew = false; 69 $obj->focus = $focus; 70 return $obj; 71 } 72 73 74 /** 75 * Get an entity data object from a crmentity object 76 * 77 * @param $crmEntity The CRMEntity instance. 78 * @return The new entity data object. 79 */ 80 static function fromCRMEntity($crmEntity){ 81 $obj = new VTEntityData(); 82 $obj->focus = $crmEntity; 83 $obj->isNew = !(isset($crmEntity->id) && $crmEntity->id != null); 84 return $obj; 85 } 86 87 /** 88 * Get the data from the entity object as an array. 89 * 90 * @return An array representation of the module data. 91 */ 92 function getData(){ 93 return $this->focus->column_fields; 94 } 95 96 /** 97 * Get the entity id. 98 * 99 * @return The entity id. 100 */ 101 function getId(){ 102 return $this->focus->id; 103 } 104 105 /** 106 * Get the name of the module represented by the entity data object. 107 * 108 * @return The module name. 109 */ 110 function getModuleName(){ 111 $className = get_class($this->focus); 112 $importModuleMapping = Array( 113 "ImportLead"=>"Leads", 114 "ImportAccount"=>"Accounts", 115 "ImportContact"=>"Contacts", 116 "ImportOpportunity"=>"Potentials", 117 "ImportProduct"=>"Products", 118 "ImportTicket"=>"HelpDesk", 119 "ImportVendors"=>"Vendors" 120 ); 121 $moduleName = $className; 122 if(array_key_exists($className, $importModuleMapping)){ 123 $moduleName = $importModuleMapping[$className]; 124 } 125 126 if($className == 'Activity') { 127 $id = $this->getId(); 128 if($id != null || $id != '') { 129 $moduleName = vtws_getCalendarEntityType($id); 130 } 131 } 132 return $moduleName; 133 } 134 135 function get($fieldName){ 136 return $this->focus->column_fields[$fieldName]; 137 } 138 139 function set($fieldName, $value){ 140 $data = $this->focus->column_fields[$fieldName] = $value; 141 } 142 143 /** 144 * Check whether the object is stored on the database. 145 * 146 * @return True if the object is saved false otherwiser. 147 */ 148 function isSaved(){ 149 return isset($this->focus->id); 150 } 151 152 153 /** 154 * Check wether the obkect is new. 155 * 156 * @return True if the object is new, false otherwise. 157 */ 158 function isNew(){ 159 return $this->isNew; 160 } 161 } 162 163 ?>
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 |