Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php
/* +**********************************************************************************
* The contents of this file are subject to the vtiger CRM Public License Version 1.0
* ("License"); You may not use this file except in compliance with the License
* The Original Code is: vtiger CRM Open Source
* The Initial Developer of the Original Code is vtiger.
* Portions created by vtiger are Copyright (C) vtiger.
* All Rights Reserved.
* ********************************************************************************** */
/**
* Provides basic API to work with vtiger CRM Fields
* @package vtlib
*/
class Vtiger_FieldBasic {
/** ID of this field instance */
var $id;
var $name;
var $label = false;
var $table = false;
var $column = false;
var $columntype = false;
var $helpinfo = '';
var $summaryfield = 0;
var $masseditable = 1; // Default: Enable massedit for field
var $uitype = 1;
var $typeofdata = 'V~O';
var $displaytype = 1;
var $generatedtype = 1;
var $readonly = 1;
var $presence = 2;
var $defaultvalue = '';
var $maximumlength = 100;
var $sequence = false;
var $quickcreate = 1;
var $quicksequence = false;
var $info_type = 'BAS';
var $block;
/**
* Constructor
*/
function __construct() {
}
/**
* Initialize this instance
* @param Array
* @param Vtiger_Module Instance of module to which this field belongs
* @param Vtiger_Block Instance of block to which this field belongs
* @access private
*/
function initialize($valuemap, $moduleInstance = false, $blockInstance = false) {
$this->id = $valuemap['fieldid'];
$this->name = $valuemap['fieldname'];
$this->label = $valuemap['fieldlabel'];
$this->column = $valuemap['columnname'];
$this->table = $valuemap['tablename'];
$this->uitype = $valuemap['uitype'];
$this->typeofdata = $valuemap['typeofdata'];
$this->helpinfo = $valuemap['helpinfo'];
$this->masseditable = $valuemap['masseditable'];
$this->displaytype = $valuemap['displaytype'];
$this->generatedtype = $valuemap['generatedtype'];
$this->readonly = $valuemap['readonly'];
$this->presence = $valuemap['presence'];
$this->defaultvalue = $valuemap['defaultvalue'];
$this->quickcreate = $valuemap['quickcreate'];
$this->sequence = $valuemap['sequence'];
$this->summaryfield = $valuemap['summaryfield'];
$this->block = $blockInstance ? $blockInstance : Vtiger_Block::getInstance($valuemap['block'], $moduleInstance);
}
/** Cache (Record) the schema changes to improve performance */
static $__cacheSchemaChanges = Array();
/**
* Initialize vtiger schema changes.
* @access private
*/
function __handleVtigerCoreSchemaChanges() {
// Add helpinfo column to the vtiger_field table
if (empty(self::$__cacheSchemaChanges['vtiger_field.helpinfo'])) {
Vtiger_Utils::AddColumn('vtiger_field', 'helpinfo', ' TEXT');
self::$__cacheSchemaChanges['vtiger_field.helpinfo'] = true;
}
if (empty(self::$__cacheSchemaChanges['vtiger_field.summaryfield'])) {
Vtiger_Utils::AddColumn('vtiger_field', 'summaryfield', ' INT(10) NOT NULL DEFAULT 0');
self::$__cacheSchemaChanges['vtiger_field.summaryfield'] = 0;
}
}
/**
* Get unique id for this instance
* @access private
*/
function __getUniqueId() {
global $adb;
return $adb->getUniqueID('vtiger_field');
}
/**
* Get next sequence id to use within a block for this instance
* @access private
*/
function __getNextSequence() {
global $adb;
$result = $adb->pquery("SELECT MAX(sequence) AS max_seq FROM vtiger_field WHERE tabid=? AND block=?", Array($this->getModuleId(), $this->getBlockId()));
$maxseq = 0;
if ($result && $adb->num_rows($result)) {
$maxseq = $adb->query_result($result, 0, 'max_seq');
$maxseq += 1;
}
return $maxseq;
}
/**
* Get next quick create sequence id for this instance
* @access private
*/
function __getNextQuickCreateSequence() {
global $adb;
$result = $adb->pquery("SELECT MAX(quickcreatesequence) AS max_quickcreateseq FROM vtiger_field WHERE tabid=?", Array($this->getModuleId()));
$max_quickcreateseq = 0;
if ($result && $adb->num_rows($result)) {
$max_quickcreateseq = $adb->query_result($result, 0, 'max_quickcreateseq');
$max_quickcreateseq += 1;
}
return $max_quickcreateseq;
}
/**
* Create this field instance
* @param Vtiger_Block Instance of the block to use
* @access private
*/
function __create($blockInstance) {
$this->__handleVtigerCoreSchemaChanges();
global $adb;
$this->block = $blockInstance;
$moduleInstance = $this->getModuleInstance();
$this->id = $this->__getUniqueId();
if (!$this->sequence) {
$this->sequence = $this->__getNextSequence();
}
if ($this->quickcreate != 1) { // If enabled for display
if (!$this->quicksequence) {
$this->quicksequence = $this->__getNextQuickCreateSequence();
}
} else {
$this->quicksequence = null;
}
// Initialize other variables which are not done
if (!$this->table)
$this->table = $moduleInstance->basetable;
if (!$this->column) {
$this->column = strtolower($this->name);
if (!$this->columntype)
$this->columntype = 'VARCHAR(100)';
}
if (!$this->label)
$this->label = $this->name;
$adb->pquery("INSERT INTO vtiger_field (tabid, fieldid, columnname, tablename, generatedtype,
uitype, fieldname, fieldlabel, readonly, presence, defaultvalue, maximumlength, sequence,
block, displaytype, typeofdata, quickcreate, quickcreatesequence, info_type, helpinfo, summaryfield)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Array($this->getModuleId(), $this->id, $this->column, $this->table, intval($this->generatedtype),
$this->uitype, $this->name, $this->label, $this->readonly, $this->presence, $this->defaultvalue,
$this->maximumlength, $this->sequence, $this->getBlockId(), $this->displaytype, $this->typeofdata,
intval($this->quickcreate), intval($this->quicksequence), $this->info_type, $this->helpinfo, intval($this->summaryfield)));
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
// Set the field status for mass-edit (if set)
$adb->pquery('UPDATE vtiger_field SET masseditable=? WHERE fieldid=?', Array($this->masseditable, $this->id));
Vtiger_Profile::initForField($this);
if (!empty($this->columntype)) {
Vtiger_Utils::AddColumn($this->table, $this->column, $this->columntype);
}
self::log("Creating Field $this->name ... DONE");
self::log("Module language mapping for $this->label ... CHECK");
}
/**
* Update this field instance
* @access private
* @internal TODO
*/
function __update() {
self::log("Updating Field $this->name ... DONE");
}
/**
* Delete this field instance
* @access private
*/
function __delete() {
global $adb;
Vtiger_Profile::deleteForField($this);
$adb->pquery("DELETE FROM vtiger_field WHERE fieldid=?", Array($this->id));
self::log("Deleteing Field $this->name ... DONE");
}
/**
* Get block id to which this field instance is associated
*/
function getBlockId() {
return $this->block->id;
}
/**
* Get module id to which this field instance is associated
*/
function getModuleId() {
return $this->block->module->id;
}
/**
* Get module name to which this field instance is associated
*/
function getModuleName() {
return $this->block->module->name;
}
/**
* Get module instance to which this field instance is associated
*/
function getModuleInstance() {
return $this->block->module;
}
/**
* Save this field instance
* @param Vtiger_Block Instance of block to which this field should be added.
*/
function save($blockInstance = false) {
if ($this->id)
$this->__update();
else
$this->__create($blockInstance);
return $this->id;
}
/**
* Delete this field instance
*/
function delete() {
$this->__delete();
}
/**
* Set Help Information for this instance.
* @param String Help text (content)
*/
function setHelpInfo($helptext) {
// Make sure to initialize the core tables first
$this->__handleVtigerCoreSchemaChanges();
global $adb;
$adb->pquery('UPDATE vtiger_field SET helpinfo=? WHERE fieldid=?', Array($helptext, $this->id));
self::log("Updated help information of $this->name ... DONE");
}
/**
* Set Masseditable information for this instance.
* @param Integer Masseditable value
*/
function setMassEditable($value) {
global $adb;
$adb->pquery('UPDATE vtiger_field SET masseditable=? WHERE fieldid=?', Array($value, $this->id));
self::log("Updated masseditable information of $this->name ... DONE");
}
/**
* Set Summaryfield information for this instance.
* @param Integer Summaryfield value
*/
function setSummaryField($value) {
global $adb;
$adb->pquery('UPDATE vtiger_field SET summaryfield=? WHERE fieldid=?', Array($value, $this->id));
self::log("Updated summaryfield information of $this->name ... DONE");
}
/**
* Helper function to log messages
* @param String Message to log
* @param Boolean true appends linebreak, false to avoid it
* @access private
*/
static function log($message, $delim = true) {
Vtiger_Utils::Log($message, $delim);
}
}