"; foreach($values as $value){ $checked = in_array($value, $selected)? " checked=checked ": " "; echo "
$value
"; } echo ""; } function displaySelect($name,$values, $selected ='', $attr=''){ echo ""; } function displayTextBoxes($values, $attr=''){ echo "
"; foreach($values as $value){ $postvalue = !empty($_POST[$value])? $_POST[$value]: ''; echo "
$value
"; } echo "
"; } function printValue($value, $depth=0){ echo "
";
 		print_r($value);
 		echo "
"; } function display(){ $do = !empty($_REQUEST['do'])?$_REQUEST['do']:''; echo "
"; echo "

I want to learn about "; $this->displaySelect('do', array('Nothing', 'Modules','Fields', 'Field Attributes', 'Relationships'), $do, 'onchange="toggleLearn(this.value)"'); echo "

"; $modules = !empty($_REQUEST['modules'])?$_REQUEST['modules']:array(); if(empty($modules) && !empty($_REQUEST['module']) && $_REQUEST['module'] != 'Home'){ $modules = array( $_REQUEST['module']); } $this->displayCheckBoxes('modules[]', VardefBrowser::getModules(), $modules, ' id="_modules" '); $attributes = !empty($_REQUEST['attributes'])?$_REQUEST['attributes']:array(); $allAttributes = array_keys(VardefBrowser::findFieldAttributes()); sort($allAttributes); $this->displayCheckBoxes('attributes[]', $allAttributes, $attributes, ' id="_attributes" '); $this->displayTextBoxes($allAttributes, ' id="_fields" '); echo "
"; echo << function toggleLearn(value){ document.getElementById('_modules').style.display = 'None'; document.getElementById('_attributes').style.display = 'None'; document.getElementById('_fields').style.display = 'None'; if(value == 'Modules' || value == 'Relationships'){ document.getElementById('_modules').style.display = ''; } if(value == 'Fields'){ document.getElementById('_modules').style.display = ''; document.getElementById('_fields').style.display = ''; } if(value == 'Field Attributes'){ document.getElementById('_modules').style.display = ''; document.getElementById('_attributes').style.display = ''; } } toggleLearn('$do'); EOQ; echo "
"; switch ($do){ case 'Modules': $this->printValue(VardefBrowser::findVardefs( $modules)); break; case 'Field Attributes': $this->printValue(VardefBrowser::findFieldAttributes($attributes, $modules)); break; case 'Fields': $searchFor = array(); foreach($allAttributes as $at){ if(!empty($_POST[$at])){ $searchFor[$at] = $_POST[$at]; } } $this->printValue(VardefBrowser::findFieldsWithAttributes($searchFor, $modules)); break; default: echo <<

All you ever wanted to know about Vardefs in 30 minutes

All you ever wanted to know about Vardef Fields and Relationships in 30 minutes

All you ever wanted to know about Vardef Fields in 30 minutes

Something about Vardefs in 30 minutes

What you need to know

Vardefs are where we define information about the fields for a module. 
 					
It also specifies 75% of the information on relationships. 
 					
There are also special attributes that can enable additional functionality for a module. 
 					
It's broken down into:
	fields: The fields of a module (most of these are stored in the database)
	
	indices: The indicies on the database
	
	relationships: The relationships for this module
	
	templates: the functionality/fields this module inherits from SugarObjects(located in include/SugarObjects). 
		In a vardef these are specified by the third argument in VardefManager::createVardef
		For Example - VardefManager::createVardef('Contacts','Contact', array('default', 'assignable','team_security','person'));
		would add the fields for team security to contacts and make it an object that can be assigned to users.
		The 'person' value would indicate that that Contacts subclasses Person and gains all the fields/attributes that 'Person' 
		would get. Since person extends basic it would also gain all the fields/attributes of basic as well.
					  
					 
		The SugarObjects that a module can extend are 'basic', 'company', 'file', 'issue', 'person'. 
		These are the same objects you can build off of in ModuleBuilder. 
		Adding a new SugarObject to include/SugarObjects/templates is the way 
		to add modules to ModuleBuilder
					 
		Besides extending base objects, a module can also implement functionality defined in SugarObjects. 
		You can currenty implement 'assignable' and 'team_security'. 
		
		
	attributes:
		[table] (string) (required) The database table where this module stores it's data - any custom fields will be stored in a new table 
			with '_cstm' appended to the table name. The field id_c in the custom table will be the same value as id in the primary table
			allowing us to join the two tables together. 
		
		[comment] (string) (optional) is a description of the module
		
		[unified_search] (bool)(optional) is global search (the search in the upper right corner on the screen) available for this module
		
		[unified_search_default_enabled] (bool)(optional) is this module available by default in global search
		
		[optimistic_locking] (bool) (optional) optimistic locking is the concept that on save if the record modifiy time (date_modified)
			 is newer than the the modify time of the record when it was loaded to edit (this time is stored in the session). 
		
		[favorites] (bool) (optional) should favorites be enabled for this module. Favorites are indicated by the stars next to a record 
			on lists and deail views. It makes it easier for users to indicate what is important to them right now. It also allows them to filter
			by favorites.  
			
		[duplicate_merge] (bool) (optional) is systematic merging allowed between records of this module or not. This option is available from 
			the menu on list views. A user needs to select 2 records on the list view using the checkboxes, and then they can select merge from the actions
			menu.
			
		[audited] (bool) (optional) auditing allows for the tracking of any changes to specified fields. In order to enable auditing you need to enable
			it at both the module level and the field level. It will create an audit table for the module with the '_audit' appended to the table name.
			
		[custom_fields] (bool) (automatic)  if the module has custom fields this will be set to true
		
			
		
		
		
					 
					 

					  
					
					
					
EOQ; } echo "
Help Text
"; //$this->printValue(VardefBrowser::findFieldsWithAttributes(array('type'=>'id'), $modules)); } } class VardefBrowser{ function __construct(){ } static function getModules(){ $modules = array(); foreach($GLOBALS['beanList'] as $module=>$object){ $object = BeanFactory::getObjectName($module); VardefManager::loadVardef($module, $object); if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue; $modules[] = $module; } sort($modules); return $modules; } static function findFieldsWithAttributes($attributes, $modules=null){ $fields = array(); if(empty($modules))$modules = VardefBrowser::getModules(); foreach($modules as $module){ if(!empty($GLOBALS['beanList'][$module])){ $object = $GLOBALS['beanList'][$module]; if($object == 'aCase')$object = 'Case'; VardefManager::loadVardef($module, $object); if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue; foreach($GLOBALS['dictionary'][$object]['fields'] as $name=>$def){ $match = true; foreach($attributes as $k=>$v){ $alt = false; if($k == 'type'){ $alt = 'dbType'; } if($v == 'true' && !empty($def[$k])){ continue; } if((empty($def[$k]) || $def[$k] != $v) && (empty($alt) || empty($def[$alt]) || $def[$alt] != $v )){ $match = false; } } if($match){ $fields[$module][$object][$name] = $def; } } } } return $fields; } static function findVardefs($modules=null){ $defs = array(); if(empty($modules))$modules = VardefBrowser::getModules(); foreach($modules as $module){ if(!empty($GLOBALS['beanList'][$module])){ $object = $GLOBALS['beanList'][$module]; if($object == 'aCase')$object = 'Case'; VardefManager::loadVardef($module, $object); if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue; $defs[$module][$object] = $GLOBALS['dictionary'][$object]; } } return $defs; } static function findFieldAttributes($attributes=array(), $modules=null, $byModule=false, $byType=false){ $fields = array(); if(empty($modules))$modules = VardefBrowser::getModules(); foreach($modules as $module){ if(!empty($GLOBALS['beanList'][$module])){ $object = $GLOBALS['beanList'][$module]; if($object == 'aCase')$object = 'Case'; VardefManager::loadVardef($module, $object); if(empty($GLOBALS['dictionary'][$object]['fields'] ))continue; foreach($GLOBALS['dictionary'][$object]['fields'] as $name=>$def){ $fieldAttributes = (!empty($attributes))? $attributes:array_keys($def); foreach($fieldAttributes as $k){ if(isset($def[$k])){ $v = var_export($def[$k], true); $key = is_array($def[$k])?null:$def[$k]; if($k == 'type'){ if(isset($def['dbType'])){ $v = var_export($def['dbType'], true); } } if($byModule){ $fields[$module][$object][$def['type']][$k][$key] = $v; }else{ if($byType){ $fields[$def['type']][$k][$key] = $v; }else{ if(!is_array($def[$k])){ if(isset($fields[$k][$key])){ $fields[$k][$key]['refs']++; }else{ $fields[$k][$key] = array('attribute'=>$v, 'refs'=>1); } }else{ $fields[$k]['_array'][] = $def[$k]; } } } } } } } } return $fields; } }