[ 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 include_once ('vtlib/Vtiger/Utils.php'); 11 include_once ('vtlib/Vtiger/FieldBasic.php'); 12 require_once 'includes/runtime/Cache.php'; 13 14 /** 15 * Provides APIs to control vtiger CRM Field 16 * @package vtlib 17 */ 18 class Vtiger_Field extends Vtiger_FieldBasic { 19 20 /** 21 * Get unique picklist id to use 22 * @access private 23 */ 24 function __getPicklistUniqueId() { 25 global $adb; 26 return $adb->getUniqueID('vtiger_picklist'); 27 } 28 29 /** 30 * Set values for picklist field (for all the roles) 31 * @param Array List of values to add. 32 * 33 * @internal Creates picklist base if it does not exists 34 */ 35 function setPicklistValues($values) { 36 global $adb,$default_charset; 37 38 // Non-Role based picklist values 39 if($this->uitype == '16') { 40 $this->setNoRolePicklistValues($values); 41 return; 42 } 43 44 $picklist_table = 'vtiger_'.$this->name; 45 $picklist_idcol = $this->name.'id'; 46 if(!Vtiger_Utils::CheckTable($picklist_table)) { 47 Vtiger_Utils::CreateTable( 48 $picklist_table, 49 "($picklist_idcol INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 50 $this->name VARCHAR(200) NOT NULL, 51 presence INT (1) NOT NULL DEFAULT 1, 52 picklist_valueid INT NOT NULL DEFAULT 0, 53 sortorderid INT DEFAULT 0)", 54 true); 55 $new_picklistid = $this->__getPicklistUniqueId(); 56 $adb->pquery("INSERT INTO vtiger_picklist (picklistid,name) VALUES(?,?)",Array($new_picklistid, $this->name)); 57 self::log("Creating table $picklist_table ... DONE"); 58 } else { 59 $picklistResult = $adb->pquery("SELECT picklistid FROM vtiger_picklist WHERE name=?", Array($this->name)); 60 $new_picklistid = $adb->query_result($picklistResult, 0, 'picklistid'); 61 } 62 63 $specialNameSpacedPicklists = array( 64 'opportunity_type'=>'opptypeid', 65 'duration_minutes'=>'minutesid', 66 'recurringtype'=>'recurringeventid' 67 ); 68 69 // Fix Table ID column names 70 $fieldName = (string)$this->name; 71 if(in_array($fieldName.'_id', $adb->getColumnNames($picklist_table))) { 72 $picklist_idcol = $fieldName.'_id'; 73 } elseif(array_key_exists($fieldName, $specialNameSpacedPicklists)) { 74 $picklist_idcol = $specialNameSpacedPicklists[$fieldName]; 75 } 76 // END 77 78 // Add value to picklist now 79 $sortid = 0; // TODO To be set per role 80 foreach($values as $value) { 81 $new_picklistvalueid = getUniquePicklistID(); 82 $presence = 1; // 0 - readonly, Refer function in include/ComboUtil.php 83 $new_id = $adb->getUniqueID($picklist_table); 84 ++$sortid; 85 86 $adb->pquery("INSERT INTO $picklist_table($picklist_idcol, $this->name, presence, picklist_valueid,sortorderid) VALUES(?,?,?,?,?)", 87 Array($new_id, $value, $presence, $new_picklistvalueid,$sortid)); 88 89 90 // Associate picklist values to all the role 91 $adb->pquery("INSERT INTO vtiger_role2picklist(roleid, picklistvalueid, picklistid, sortid) SELECT roleid, 92 $new_picklistvalueid, $new_picklistid, $sortid FROM vtiger_role", array()); 93 } 94 } 95 96 /** 97 * Set values for picklist field (non-role based) 98 * @param Array List of values to add 99 * 100 * @internal Creates picklist base if it does not exists 101 * @access private 102 */ 103 function setNoRolePicklistValues($values) { 104 global $adb; 105 $pickListName_ids = array('recurring_frequency','payment_duration'); 106 $picklist_table = 'vtiger_'.$this->name; 107 $picklist_idcol = $this->name.'id'; 108 if(in_array($this->name, $pickListName_ids)){ 109 $picklist_idcol = $this->name.'_id'; 110 } 111 if(!Vtiger_Utils::CheckTable($picklist_table)) { 112 Vtiger_Utils::CreateTable( 113 $picklist_table, 114 "($picklist_idcol INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 115 $this->name VARCHAR(200) NOT NULL, 116 sortorderid INT(11), 117 presence INT (11) NOT NULL DEFAULT 1)", 118 true); 119 self::log("Creating table $picklist_table ... DONE"); 120 } 121 122 // Add value to picklist now 123 $sortid = 1; 124 foreach($values as $value) { 125 $presence = 1; // 0 - readonly, Refer function in include/ComboUtil.php 126 $new_id = $adb->getUniqueId($picklist_table); 127 $adb->pquery("INSERT INTO $picklist_table($picklist_idcol, $this->name, sortorderid, presence) VALUES(?,?,?,?)", 128 Array($new_id, $value, $sortid, $presence)); 129 130 $sortid = $sortid+1; 131 } 132 } 133 134 /** 135 * Set relation between field and modules (UIType 10) 136 * @param Array List of module names 137 * 138 * @internal Creates table vtiger_fieldmodulerel if it does not exists 139 */ 140 function setRelatedModules($moduleNames) { 141 142 // We need to create core table to capture the relation between the field and modules. 143 if(!Vtiger_Utils::CheckTable('vtiger_fieldmodulerel')) { 144 Vtiger_Utils::CreateTable( 145 'vtiger_fieldmodulerel', 146 '(fieldid INT NOT NULL, module VARCHAR(100) NOT NULL, relmodule VARCHAR(100) NOT NULL, status VARCHAR(10), sequence INT)', 147 true 148 ); 149 } 150 // END 151 152 global $adb; 153 foreach($moduleNames as $relmodule) { 154 $checkres = $adb->pquery('SELECT * FROM vtiger_fieldmodulerel WHERE fieldid=? AND module=? AND relmodule=?', 155 Array($this->id, $this->getModuleName(), $relmodule)); 156 157 // If relation already exist continue 158 if($adb->num_rows($checkres)) continue; 159 160 $adb->pquery('INSERT INTO vtiger_fieldmodulerel(fieldid, module, relmodule) VALUES(?,?,?)', 161 Array($this->id, $this->getModuleName(), $relmodule)); 162 163 self::log("Setting $this->name relation with $relmodule ... DONE"); 164 } 165 return true; 166 } 167 168 /** 169 * Remove relation between the field and modules (UIType 10) 170 * @param Array List of module names 171 */ 172 function unsetRelatedModules($moduleNames) { 173 global $adb; 174 foreach($moduleNames as $relmodule) { 175 $adb->pquery('DELETE FROM vtiger_fieldmodulerel WHERE fieldid=? AND module=? AND relmodule = ?', 176 Array($this->id, $this->getModuleName(), $relmodule)); 177 178 Vtiger_Utils::Log("Unsetting $this->name relation with $relmodule ... DONE"); 179 } 180 return true; 181 } 182 183 /** 184 * Get Vtiger_Field instance by fieldid or fieldname 185 * @param mixed fieldid or fieldname 186 * @param Vtiger_Module Instance of the module if fieldname is used 187 */ 188 static function getInstance($value, $moduleInstance=false) { 189 global $adb; 190 $instance = false; 191 $data = Vtiger_Functions::getModuleFieldInfo($moduleInstance->id, $value); 192 if ($data) { 193 $instance = new self(); 194 $instance->initialize($data, $moduleInstance); 195 } 196 return $instance; 197 } 198 199 /** 200 * Get Vtiger_Field instances related to block 201 * @param Vtiger_Block Instnace of block to use 202 * @param Vtiger_Module Instance of module to which block is associated 203 */ 204 static function getAllForBlock($blockInstance, $moduleInstance=false) { 205 $cache = Vtiger_Cache::getInstance(); 206 if($cache->getBlockFields($blockInstance->id,$moduleInstance->id)){ 207 return $cache->getBlockFields($blockInstance->id,$moduleInstance->id); 208 } else { 209 global $adb; 210 $instances = false; 211 $query = false; 212 $queryParams = false; 213 if($moduleInstance) { 214 $query = "SELECT * FROM vtiger_field WHERE block=? AND tabid=? ORDER BY sequence"; 215 $queryParams = Array($blockInstance->id, $moduleInstance->id); 216 } else { 217 $query = "SELECT * FROM vtiger_field WHERE block=? ORDER BY sequence"; 218 $queryParams = Array($blockInstance->id); 219 } 220 $result = $adb->pquery($query, $queryParams); 221 for($index = 0; $index < $adb->num_rows($result); ++$index) { 222 $instance = new self(); 223 $instance->initialize($adb->fetch_array($result), $moduleInstance, $blockInstance); 224 $instances[] = $instance; 225 } 226 $cache->setBlockFields($blockInstance->id,$moduleInstance->id,$instances); 227 return $instances; 228 } 229 } 230 231 /** 232 * Get Vtiger_Field instances related to module 233 * @param Vtiger_Module Instance of module to use 234 */ 235 static function getAllForModule($moduleInstance) { 236 global $adb; 237 $instances = false; 238 239 $query = "SELECT * FROM vtiger_field WHERE tabid=? ORDER BY sequence"; 240 $queryParams = Array($moduleInstance->id); 241 242 $result = $adb->pquery($query, $queryParams); 243 for($index = 0; $index < $adb->num_rows($result); ++$index) { 244 $instance = new self(); 245 $instance->initialize($adb->fetch_array($result), $moduleInstance); 246 $instances[] = $instance; 247 } 248 return $instances; 249 } 250 251 /** 252 * Delete fields associated with the module 253 * @param Vtiger_Module Instance of module 254 * @access private 255 */ 256 static function deleteForModule($moduleInstance) { 257 global $adb; 258 $adb->pquery("DELETE FROM vtiger_field WHERE tabid=?", Array($moduleInstance->id)); 259 self::log("Deleting fields of the module ... DONE"); 260 } 261 } 262 ?>
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 |