本文整理汇总了PHP中VardefManager类的典型用法代码示例。如果您正苦于以下问题:PHP VardefManager类的具体用法?PHP VardefManager怎么用?PHP VardefManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了VardefManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createRelationship
/**
* Create a relationship
*
* Params should be passed in as this:
*
* array(
* 'relationship_type' => 'one-to-many',
* 'lhs_module' => 'Accounts',
* 'rhs_module' => 'Accounts',
* )
*
* @static
* @param array $relationship_def
* @return ActivitiesRelationship|bool|ManyToManyRelationship|ManyToOneRelationship|OneToManyRelationship|OneToOneRelationship
*/
public static function createRelationship(array $relationship_def)
{
if (!self::checkRequiredFields($relationship_def)) {
return false;
}
$relationships = new DeployedRelationships($relationship_def['lhs_module']);
if (!isset($relationship_def['view_module'])) {
$relationship_def['view_module'] = $relationship_def['lhs_module'];
}
$REQUEST_Backup = $_REQUEST;
$_REQUEST = $relationship_def;
$relationship = $relationships->addFromPost();
$relationships->save();
$relationships->build();
LanguageManager::clearLanguageCache($relationship_def['lhs_module']);
SugarRelationshipFactory::rebuildCache();
// rebuild the dictionary to make sure that it has the new relationship in it
SugarTestHelper::setUp('dictionary');
// reset the link fields since we added one
VardefManager::$linkFields = array();
$_REQUEST = $REQUEST_Backup;
unset($REQUEST_Backup);
self::$_relsAdded[] = $relationship->getDefinition();
return $relationship;
}
示例2: repairDictionary
protected function repairDictionary()
{
$this->df->buildCache($this->modulename);
VardefManager::clearVardef();
VardefManager::refreshVardefs($this->modulename, $this->objectname);
$this->seed->field_defs = $GLOBALS['dictionary'][$this->objectname]['fields'];
}
示例3: setUp
public function setUp()
{
global $beanList, $beanFiles, $dictionary;
//Add entries to simulate custom module
$beanList['Bug44030_TestPerson'] = 'Bug44030_TestPerson';
$beanFiles['Bug44030_TestPerson'] = 'modules/Bug44030_TestPerson/Bug44030_TestPerson.php';
VardefManager::loadVardef('Contacts', 'Contact');
$dictionary['Bug44030_TestPerson'] = $dictionary['Contact'];
//Copy over custom SearchFields.php file
if (!file_exists('custom/modules/Bug44030_TestPerson/metadata')) {
mkdir_recursive('custom/modules/Bug44030_TestPerson/metadata');
}
if ($fh = @fopen('custom/modules/Bug44030_TestPerson/metadata/SearchFields.php', 'w+')) {
$string = <<<EOQ
<?php
\$searchFields['Bug44030_TestPerson']['email'] = array(
'query_type' => 'default',
'operator' => 'subquery',
'subquery' => 'SELECT eabr.bean_id FROM email_addr_bean_rel eabr JOIN email_addresses ea ON (ea.id = eabr.email_address_id) WHERE eabr.deleted=0 AND ea.email_address LIKE',
'db_field' => array('id',),
'vname' =>'LBL_ANY_EMAIL',
);
?>
EOQ;
fputs($fh, $string);
fclose($fh);
}
//Remove the cached unified_search_modules.php file
$this->unified_search_modules_file = $GLOBALS['sugar_config']['cache_dir'] . 'modules/unified_search_modules.php';
if (file_exists($this->unified_search_modules_file)) {
copy($this->unified_search_modules_file, $this->unified_search_modules_file . '.bak');
unlink($this->unified_search_modules_file);
}
}
示例4: setUp
public function setUp()
{
global $dictionary;
$this->_view = 'editview';
VardefManager::loadVardef('Contacts', 'Contact');
$this->def = $dictionary['Contact']['fields']['email1'];
}
示例5: createRelationship
private function createRelationship($lhs_module, $rhs_module = null, $relationship_type = 'one-to-many')
{
$rhs_module = $rhs_module == null ? $lhs_module : $rhs_module;
// Adding relation between products and users
$this->relationships = new DeployedRelationships($lhs_module);
$definition = array('lhs_module' => $lhs_module, 'relationship_type' => $relationship_type, 'rhs_module' => $rhs_module, 'lhs_label' => $lhs_module, 'rhs_label' => $rhs_module, 'rhs_subpanel' => 'default');
$this->relationship = RelationshipFactory::newRelationship($definition);
$this->relationships->add($this->relationship);
$this->relationships->save();
$this->relationships->build();
LanguageManager::clearLanguageCache($lhs_module);
// Updating $dictionary by created relation
global $dictionary;
$moduleInstaller = new ModuleInstaller();
$moduleInstaller->silent = true;
$moduleInstaller->rebuild_tabledictionary();
require 'modules/TableDictionary.php';
// Updating vardefs
VardefManager::$linkFields = array();
VardefManager::clearVardef();
VardefManager::refreshVardefs($lhs_module, BeanFactory::getObjectName($lhs_module));
if ($lhs_module != $rhs_module) {
VardefManager::refreshVardefs($rhs_module, BeanFactory::getObjectName($rhs_module));
}
SugarRelationshipFactory::rebuildCache();
}
示例6: tearDown
public function tearDown()
{
global $dictionary, $bean_list;
$dictionary = $this->old_dictionary;
$bean_list = $this->old_bean_list;
VardefManager::clearVardef('Accounts', 'Account');
VardefManager::refreshVardefs('Accounts', 'Account');
}
示例7: __construct
/**
* @param $linkName String name of a link field in the module's vardefs
* @param $bean SugarBean focus bean for this link (one half of a relationship)
* @param $linkDef Array Optional vardef for the link in case it can't be found in the passed in bean for the global dictionary
* @return void
*
*/
function __construct($linkName, $bean, $linkDef = false)
{
$this->focus = $bean;
//Try to load the link vardef from the beans field defs. Otherwise start searching
if (empty($bean->field_defs) || empty($bean->field_defs[$linkName]) || empty($bean->field_defs[$linkName]['relationship'])) {
if (empty($linkDef)) {
//Assume $linkName is really relationship_name, and find the link name with the vardef manager
$this->def = VardefManager::getLinkFieldForRelationship($bean->module_dir, $bean->object_name, $linkName);
} else {
$this->def = $linkDef;
}
//Check if multiple links were found for a given relationship
if (is_array($this->def) && !isset($this->def['name'])) {
//More than one link found, we need to figure out if we are currently on the LHS or RHS
//default to lhs for now
if (isset($this->def[0]['side']) && $this->def[0]['side'] == 'left') {
$this->def = $this->def[0];
} else {
if (isset($this->def[1]['side']) && $this->def[1]['side'] == 'left') {
$this->def = $this->def[1];
} else {
$this->def = $this->def[0];
}
}
}
if (empty($this->def['name'])) {
$GLOBALS['log']->fatal("failed to find link for {$linkName}");
return false;
}
$this->name = $this->def['name'];
} else {
//Linkdef was found in the bean (this is the normal expectation)
$this->def = $bean->field_defs[$linkName];
$this->name = $linkName;
}
//Instantiate the relationship for this link.
$this->relationship = SugarRelationshipFactory::getInstance()->getRelationship($this->def['relationship']);
// Fix to restore functionality from Link.php that needs to be rewritten but for now this will do.
$this->relationship_fields = !empty($this->def['rel_fields']) ? $this->def['rel_fields'] : array();
if (!$this->loadedSuccesfully()) {
global $app_strings;
$GLOBALS['log']->error(string_format($app_strings['ERR_DATABSE_RELATIONSHIP_QUERY'], array($this->name, $this->def['relationship'])));
}
//Following behavior is tied to a property(ignore_role) value in the vardef. It alters the values of 2 properties, ignore_role_filter and add_distinct.
//the property values can be altered again before any requests are made.
if (!empty($this->def) && is_array($this->def)) {
if (isset($this->def['ignore_role'])) {
if ($this->def['ignore_role']) {
$this->ignore_role_filter = true;
$this->add_distinct = true;
}
}
if (!empty($this->def['primary_only'])) {
$this->relationship->primaryOnly = true;
}
}
}
示例8: __construct
/**
* The constructor
* @param string $subpanelName
* @param string $loadedModule - Accounts
* @param string $client - base
*/
public function __construct($subpanelName, $loadedModule, $client = 'base')
{
$GLOBALS['log']->debug(get_class($this) . "->__construct({$subpanelName} , {$loadedModule})");
$this->mdc = new MetaDataConverter();
$this->loadedModule = $loadedModule;
$this->setViewClient($client);
$linkName = $this->linkName = $this->getLinkName($subpanelName, $loadedModule);
// get the link and the related module name as the module we need the subpanel from
$bean = BeanFactory::getBean($loadedModule);
// Get the linkdef, but make sure to tell VardefManager to use name instead by passing true
$linkDef = VardefManager::getLinkFieldForRelationship($bean->module_dir, $bean->object_name, $subpanelName, true);
if ($bean->load_relationship($linkName)) {
$link = $bean->{$linkName};
} else {
$link = new Link2($linkName, $bean);
}
$this->_moduleName = $link->getRelatedModuleName();
$this->bean = BeanFactory::getBean($this->_moduleName);
$subpanelFixed = true;
if (empty($this->bean)) {
$subpanelFixed = $this->fixUpSubpanel();
}
if (empty($linkDef['name']) && (!$subpanelFixed && isModuleBWC($this->loadedModule))) {
$GLOBALS['log']->error("Cannot find a link for {$subpanelName} on {$loadedModule}");
return true;
}
// Handle validation up front that will throw exceptions
if (empty($this->bean) && !$subpanelFixed) {
throw new Exception("No valid parent bean found for {$this->linkName} on {$this->loadedModule}");
}
$this->setUpSubpanelViewDefFileInfo();
include $this->loadedSubpanelFileName;
// Prepare to load the history file. This will be available in cases when
// a layout is restored.
$this->historyPathname = 'custom/history/modules/' . $this->_moduleName . '/clients/' . $this->getViewClient() . '/views/' . $this->sidecarSubpanelName . '/' . self::HISTORYFILENAME;
$this->_history = new History($this->historyPathname);
if (file_exists($this->historyPathname)) {
// load in the subpanelDefOverride from the history file
$GLOBALS['log']->debug(get_class($this) . ": loading from history");
require $this->historyPathname;
}
$this->_viewdefs = !empty($viewdefs) ? $this->getNewViewDefs($viewdefs) : array();
$this->_fielddefs = $this->bean->field_defs;
$this->_mergeFielddefs($this->_fielddefs, $this->_viewdefs);
$this->_language = '';
// don't attempt to access the template_instance property if our subpanel represents a collection, as it won't be there - the sub-sub-panels get this value instead
if (isset($this->_viewdefs['type']) && $this->_viewdefs['type'] != 'collection') {
$this->_language = $this->bean->module_dir;
}
// Make sure the paneldefs are proper if there are any
$this->_paneldefs = isset($this->_viewdefs['panels']) ? $this->_viewdefs['panels'] : array();
}
示例9: testSaveUsersVardefs
public function testSaveUsersVardefs()
{
global $dictionary;
$dynamicField = new DynamicField('Users');
VardefManager::loadVardef('Users', 'User');
$dynamicField->saveToVardef('Users', $dictionary['User']['fields']);
//Test that we have refreshed the Employees vardef
$this->assertTrue(file_exists('cache/modules/Employees/Employeevardefs.php'), 'cache/modules/Employees/Emloyeevardefs.php file not created');
//Test that status is not set to be required
$this->assertFalse($dictionary['Employee']['fields']['status']['required'], 'status field set to required');
//Test that the studio attribute is set to false for status field
$this->assertFalse($dictionary['Employee']['fields']['status']['studio'], 'status field studio not set to false');
}
示例10: __construct
/**
* @param $linkName String name of a link field in the module's vardefs
* @param $bean SugarBean focus bean for this link (one half of a relationship)
* @param $linkDef Array Optional vardef for the link in case it can't be found in the passed in bean for the global dictionary
* @return void
*
*/
function __construct($linkName, $bean, $linkDef = false)
{
$this->focus = $bean;
//Try to load the link vardef from the beans field defs. Otherwise start searching
if (empty($bean->field_defs) || empty($bean->field_defs[$linkName]) || empty($bean->field_defs[$linkName]['relationship'])) {
if (empty($linkDef)) {
//Assume $linkName is really relationship_name, and find the link name with the vardef manager
$this->def = VardefManager::getLinkFieldForRelationship($bean->module_dir, $bean->object_name, $linkName);
} else {
$this->def = $linkDef;
}
//Check if multiple links were found for a given relationship
if (is_array($this->def) && !isset($this->def['name'])) {
//More than one link found, we need to figure out if we are currently on the LHS or RHS
//default to lhs for now
if (isset($this->def[0]['side']) && $this->def[0]['side'] == 'left') {
$this->def = $this->def[0];
} else {
if (isset($this->def[1]['side']) && $this->def[1]['side'] == 'left') {
$this->def = $this->def[1];
} else {
$this->def = $this->def[0];
}
}
}
if (empty($this->def['name'])) {
$GLOBALS['log']->fatal("failed to find link for {$linkName}");
return false;
}
$this->name = $this->def['name'];
} else {
//Linkdef was found in the bean (this is the normal expectation)
$this->def = $bean->field_defs[$linkName];
$this->name = $linkName;
}
//Instantiate the relationship for this link.
$this->relationship = SugarRelationshipFactory::getInstance()->getRelationship($this->def['relationship']);
if (!$this->loadedSuccesfully()) {
$GLOBALS['log']->fatal("{$this->name} for {$this->def['relationship']} failed to load\n");
}
//Following behavior is tied to a property(ignore_role) value in the vardef. It alters the values of 2 properties, ignore_role_filter and add_distinct.
//the property values can be altered again before any requests are made.
if (!empty($this->def) && is_array($this->def)) {
if (array_key_exists('ignore_role', $this->def)) {
if ($this->def['ignore_role']) {
$this->ignore_role_filter = true;
$this->add_distinct = true;
}
}
}
}
示例11: setUp
public function setUp()
{
$beanList = array();
$beanFiles = array();
require 'include/modules.php';
$GLOBALS['beanList'] = $beanList;
$GLOBALS['beanFiles'] = $beanFiles;
$GLOBALS['current_user'] = SugarTestUserUtilities::createAnonymousUser();
$GLOBALS['current_user']->status = 'Active';
$GLOBALS['current_user']->is_admin = 1;
$GLOBALS['current_user']->save();
$this->field = get_widget('varchar');
$this->field->id = 'Accountstest_custom_c';
$this->field->name = 'test_custom_c';
$this->field->vanme = 'LBL_TEST_CUSTOM_C';
$this->field->comments = NULL;
$this->field->help = NULL;
$this->field->custom_module = 'Accounts';
$this->field->type = 'varchar';
$this->field->label = 'LBL_TEST_CUSTOM_C';
$this->field->len = 255;
$this->field->required = 0;
$this->field->default_value = NULL;
$this->field->date_modified = '2009-09-14 02:23:23';
$this->field->deleted = 0;
$this->field->audited = 0;
$this->field->massupdate = 0;
$this->field->duplicate_merge = 0;
$this->field->reportable = 1;
$this->field->importable = 'true';
$this->field->ext1 = NULL;
$this->field->ext2 = NULL;
$this->field->ext3 = NULL;
$this->field->ext4 = NULL;
$this->df = new DynamicField('Accounts');
$this->mod = new Account();
$this->df->setup($this->mod);
$this->df->addFieldObject($this->field);
$this->df->buildCache('Accounts');
VardefManager::clearVardef();
VardefManager::refreshVardefs('Accounts', 'Account');
$this->mod->field_defs = $GLOBALS['dictionary']['Account']['fields'];
$this->_contact = SugarTestContactUtilities::createContact();
$this->_account = SugarTestAccountUtilities::createAccount();
$this->_contact->load_relationship('accounts');
$this->_contact->accounts->add($this->_account->id);
$this->_account->test_custom_c = 'Custom Field';
$this->_account->save();
$GLOBALS['db']->commit();
// Making sure we commit any changes
}
示例12: getLinkedDefForModuleByRelationship
/**
* Find the link entry for a particular relationship and module.
*
* @param $module
* @return array|bool
*/
public function getLinkedDefForModuleByRelationship($module)
{
$results = VardefManager::getLinkFieldForRelationship($module, BeanFactory::getObjectName($module), $this->name);
//Only a single link was found
if (isset($results['name'])) {
return $results;
} else {
if (is_array($results)) {
$GLOBALS['log']->error("Warning: Multiple links found for relationship {$this->name} within module {$module}");
return $this->getMostAppropriateLinkedDefinition($results);
} else {
return FALSE;
}
}
}
示例13: __construct
public function __construct($def)
{
global $dictionary;
$this->def = $def;
$this->name = $def['name'];
$this->selfReferencing = $def['lhs_module'] == $def['rhs_module'];
$lhsModule = $def['lhs_module'];
$rhsModule = $def['rhs_module'];
if ($this->selfReferencing) {
$links = VardefManager::getLinkFieldForRelationship($lhsModule, BeanFactory::getObjectName($lhsModule), $this->name);
if (empty($links)) {
$GLOBALS['log']->fatal("No Links found for relationship {$this->name}");
} else {
if (!isset($links[0]) && !isset($links['name'])) {
$GLOBALS['log']->fatal("Bad link found for relationship {$this->name}");
} else {
if (!isset($links[1]) && isset($links['name'])) {
$this->lhsLinkDef = $this->rhsLinkDef = $links;
} else {
if (!empty($links[0]) && !empty($links[1])) {
if (!empty($links[0]['side']) && $links[0]['side'] == "right" || !empty($links[0]['link_type']) && $links[0]['link_type'] == "one") {
//$links[0] is the RHS
$this->lhsLinkDef = $links[1];
$this->rhsLinkDef = $links[0];
} else {
//$links[0] is the LHS
$this->lhsLinkDef = $links[0];
$this->rhsLinkDef = $links[1];
}
}
}
}
}
} else {
$this->lhsLinkDef = VardefManager::getLinkFieldForRelationship($lhsModule, BeanFactory::getObjectName($lhsModule), $this->name);
$this->rhsLinkDef = VardefManager::getLinkFieldForRelationship($rhsModule, BeanFactory::getObjectName($rhsModule), $this->name);
if (!isset($this->lhsLinkDef['name']) && isset($this->lhsLinkDef[0])) {
$this->lhsLinkDef = $this->lhsLinkDef[0];
}
if (!isset($this->rhsLinkDef['name']) && isset($this->rhsLinkDef[0])) {
$this->rhsLinkDef = $this->rhsLinkDef[0];
}
}
$this->lhsLink = $this->lhsLinkDef['name'];
$this->rhsLink = $this->rhsLinkDef['name'];
}
示例14: createCustom
public function createCustom()
{
//create new varchar widget and associate with Accounts
$this->custField = get_widget('varchar');
$this->custField->id = 'Accounts' . $this->custFieldName;
$this->custField->name = $this->custFieldName;
$this->custField->type = 'varchar';
$this->custField->label = 'LBL_' . strtoupper($this->custFieldName);
$this->custField->vname = 'LBL_' . strtoupper($this->custFieldName);
$this->custField->len = 255;
$this->custField->custom_module = 'Accounts';
$this->custField->required = 0;
$this->custField->default = 'goofy';
$this->acc = new Account();
$this->df = new DynamicField('Accounts');
$this->df->setup($this->acc);
$this->df->addFieldObject($this->custField);
$this->df->buildCache('Accounts');
$this->custField->save($this->df);
VardefManager::clearVardef();
VardefManager::refreshVardefs('Accounts', 'Account');
//Now create the meta files to make this a Calculated Field.
$fn = $this->custFieldName;
$extensionContent = <<<EOQ
<?php
\$dictionary['Account']['fields']['{$fn}']['duplicate_merge_dom_value']=0;
\$dictionary['Account']['fields']['{$fn}']['calculated']='true';
\$dictionary['Account']['fields']['{$fn}']['formula']='related(\$assigned_user_link,"name")';
\$dictionary['Account']['fields']['{$fn}']['enforced']='true';
\$dictionary['Account']['fields']['{$fn}']['dependency']='';
\$dictionary['Account']['fields']['{$fn}']['type']='varchar';
\$dictionary['Account']['fields']['{$fn}']['name']='{$fn}';
EOQ;
//create custom field file
$this->custFileDirPath = create_custom_directory($this->custFileDirPath);
$fileLoc = $this->custFileDirPath . 'sugarfield_' . $this->custFieldName . '.php';
file_put_contents($fileLoc, $extensionContent);
//run repair and clear to make sure the meta gets picked up
$_REQUEST['repair_silent'] = 1;
$rc = new RepairAndClear();
$rc->repairAndClearAll(array("clearAll", "rebuildExtensions"), array("Accounts"), false, false);
$fn = $this->custFieldName;
}
示例15: tearDown
public function tearDown()
{
$GLOBALS['db']->dropTableName($this->_tablename . '_cstm');
$GLOBALS['db']->query("DELETE FROM fields_meta_data WHERE id in ('Accountsbug34993_test_c', 'Accountsbug34993_test2_c')");
if (isset($this->_old_installing)) {
$GLOBALS['installing'] = $this->_old_installing;
} else {
unset($GLOBALS['installing']);
}
if (file_exists('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test_c.php')) {
unlink('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test_c.php');
}
if (file_exists('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test2_c.php')) {
unlink('custom/Extension/modules/Accounts/Ext/Vardefs/sugarfield_bug34993_test2_c.php');
}
VardefManager::clearVardef('Accounts', 'Account');
VardefManager::refreshVardefs('Accounts', 'Account');
}