Class Vtecrm_Field provides API to work with a Module field, which are the basic elements that
store and display the module record data.
The example given below describes the way of creating new field for the module created earlier:
include_once('vtlib/Vtecrm/Block.php');
include_once('vtlib/Vtecrm/Field.php');
include_once('vtlib/Vtecrm/Module.php');
$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');
$blockInstance=Vtecrm_Block::getInstance('LBL_InstalledBase_INFORMATION',$moduleInstance);
$fieldInstance = new Vtecrm_Field();
$fieldInstance->name = 'installedbase_name';
$fieldInstance->table = 'vte_installedbase';
$fieldInstance->label = 'InstalledBase Name';
$fieldInstance->columntype = 'VARCHAR(255)';
$fieldInstance->uitype = 1;
$fieldInstance->typeofdata = 'V~M';
$fieldInstance->quickcreate = 0;
$blockInstance->addField($fieldInstance);
NOTE: The fieldInstance name is a mandatory value to be set before saving / adding to block.
Other values (if not set) are defaulted as explained below:
$fieldInstance->table //Module's basetable
$fieldInstance->column //$fieldInstance->name in lowercase [The table will be altered by adding the column if not present]
$fieldInstance->columntype //VARCHAR(255)
$fieldInstance->uitype //1
$fieldInstance->typeofdata //V~O [V stand for varchar / D stand for date / … O stand for optional / M stand for mandatory ]
$fieldInstance->label //$fieldInstance->name [Mapping entry should be present in module language file as well]
NOTE: Uitype is the graphical representation of the field. At the end of the manual you can find the list of the existent uitypes (Appendix – Uitypes List).
Entity Identifier
One of the mandatory field should be set as entity identifier of module once it is created. This field will be used for showing the details in 'Last Viewed Entries' etc...
include_once('vtlib/Vtecrm/Field.php');
include_once('vtlib/Vtecrm/Module.php');
$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');
$fieldInstance=Vtecrm_Field::getInstance('installedbasename',$moduleInstance);
$moduleInstance->setEntityIdentifier($fieldInstance);
NOTE: The Entity Identifier must run before the step 3
Set Picklist Values
If the field is of Picklist type (uitype 15, 16, 33, 55, 111) then you can configure the initial values using the following API:
include_once('vtlib/Vtecrm/Block.php');
include_once('vtlib/Vtecrm/Field.php');
include_once('vtlib/Vtecrm/Module.php');
$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');
$blockInstance=Vtecrm_Block::getInstance('LBL_InstalledBase_INFORMATION',$moduleInstance);
$fieldInstance = new Vtecrm_Field();
$fieldInstance->table = 'vte_installedbase';
$fieldInstance->column = 'installedbasetype';
$fieldInstance->name = 'installedbasetype';
$fieldInstance->label = 'Type';
$fieldInstance->columntype = 'VARCHAR(100)';
$fieldInstance->uitype = 15;
$fieldInstance->typeofdata = 'V~M';
$blockInstance->addField($fieldInstance);
$fieldInstance->setPicklistValues(Array('-- Nessuno -- ','In corso di evasione','Evasa','Fatturata'));
Set Related Module
If the field is of Popup select type (uitype=10), you can configure the related modules which could be selected via Popup using the following API:
include_once('vtlib/Vtecrm/Module.php');
include_once('vtlib/Vtecrm/Block.php');
include_once('vtlib/Vtecrm/Field.php');
$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');
$blockInstance=Vtecrm_Block::getInstance('LBL_InstalledBase_INFORMATION',$moduleInstance);
$fieldInstance = new Vtecrm_Field();
$fieldInstance->name = 'account_id';
$fieldInstance->table = 'vte_installedbase';
$fieldInstance->label= 'Account Id';
$fieldInstance->column = 'accountid';
$fieldInstance->uitype = 10;
$fieldInstance->columntype = 'I(19)';
$fieldInstance->typeofdata = 'I~O';
$fieldInstance->displaytype= 1;
$fieldInstance->quickcreate = 0;
$blockInstance->addField($fieldInstance);
$fieldInstance->setRelatedModules(Array('Accounts'));
If you want is possible create more than one related. In this situation, you can see a picklist where you find all the related modules.
include_once('vtlib/Vtecrm/Module.php');
include_once('vtlib/Vtecrm/Block.php');
include_once('vtlib/Vtecrm/Field.php');
$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');
$blockInstance=Vtecrm_Block::getInstance('LBL_InstalledBase_INFORMATION',$moduleInstance);
$fieldInstance = new Vtecrm_Field();
$fieldInstance->name = 'accoun t_id';
$fieldInstance->table = 'vte_installedbase';
$fieldInstance->label= 'Account Id';
$fieldInstance->column = 'accountid';
$fieldInstance->uitype = 10;
$fieldInstance->columntype = 'I(19)';
$fieldInstance->typeofdata = 'I~O';
$fieldInstance->displaytype= 1;
$fieldInstance->quickcreate = 0;
$blockInstance->addField($fieldInstance);
$fieldInstance->setRelatedModules(Array('Accounts','Contacts'));
To unset the related module you can use the following API.
$fieldInstance->setRelatedModules(Array('OtherModule2'));
Set Help Information
Providing help information for module field will be useful to educate users.
include_once('vtlib/Vtecrm/Module.php');
include_once('vtlib/Vtecrm/Block.php');
include_once('vtlib/Vtecrm/Field.php');
$moduleInstance=Vtecrm_Module::getInstance('InstalledBase');
$blockInstance=Vtecrm_Block::getInstance('LBL_InstalledBase_INFORMATION',$moduleInstance);
…
$fieldInstance->helpinfo = 'Relate to an existing account';
…
$fieldInstance->setRelatedModules(Array('Accounts'));
You can provide set the help text for an existing field using the following API:
$fieldInstance->setHelpInfo('HELP CONTENT');
NOTE: HELP CONTENT can be plain or rich text.
When a field has help information, helpicon will be shown beside the field label.
NOTE: Given below is the snippet of code that should be added to EditView.php of existing module to enable Help Icon support.
// ...
// Gather the help information associated with fields
$smarty->assign('FIELDHELPINFO', vtlib_getFieldHelpInfo($currentModule));
// END
// ...
if($focus->mode == 'edit') $smarty->display('salesEditView.tpl');
else $smarty->display('CreateView.tpl');