Пример #1
0
    function display()
    {
        $do = !empty($_REQUEST['do']) ? $_REQUEST['do'] : '';
        echo "<form method='post'>";
        echo "<div><h2>I want to learn about ";
        $this->displaySelect('do', array('Nothing', 'Modules', 'Fields', 'Field Attributes', 'Relationships'), $do, 'onchange="toggleLearn(this.value)"');
        echo "<input type='submit' value='Learn' class='button'></h2></div>";
        $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 "</form>";
        echo <<<EOQ
 \t\t<script>
 \t\t\tfunction toggleLearn(value){
 \t\t\t\tdocument.getElementById('_modules').style.display = 'None';\t
 \t\t\t\tdocument.getElementById('_attributes').style.display = 'None';\t
 \t\t\t\tdocument.getElementById('_fields').style.display = 'None';\t
 \t\t\t\tif(value == 'Modules' || value == 'Relationships'){
 \t\t\t\t\tdocument.getElementById('_modules').style.display = '';\t
 \t\t\t\t}
 \t\t\t\tif(value == 'Fields'){
 \t\t\t\t\tdocument.getElementById('_modules').style.display = '';
 \t\t\t\t\tdocument.getElementById('_fields').style.display = '';
 \t\t\t\t}\t
 \t\t\t\tif(value == 'Field Attributes'){
 \t\t\t\t\tdocument.getElementById('_modules').style.display = '';
 \t\t\t\t\tdocument.getElementById('_attributes').style.display = '';
 \t\t\t\t}\t
 \t\t\t}
 \t\t\ttoggleLearn('{$do}');
 \t\t\t
 \t\t</script>
 \t\t
EOQ;
        echo "<div width='100%'></div><div><div style='float:left'>";
        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 <<<EOQ
 \t\t\t\t<div style='border:1px solid;width:100%;text-align:center;-moz-border-radius: 5px;border-radius: 5px;'>
 \t\t\t\t\t<h2 style='text-decoration: line-through'>All you ever wanted to know about Vardefs in 30 minutes</h2>
 \t\t\t\t\t<h2 style='text-decoration: line-through'>All you ever wanted to know about Vardef Fields and Relationships in 30 minutes</h1>
 \t\t\t\t\t<h2 style='text-decoration: line-through'>All you ever wanted to know about Vardef Fields in 30 minutes</h2>
 \t\t\t\t\t<h2 >Something about Vardefs in 30 minutes</h2>
 \t\t\t\t</div>
 \t\t\t\t
 \t\t\t\t<div style='border:1px solid;width:100%;-moz-border-radius: 5px;border-radius: 5px;'>
 \t\t\t\t\t<h4>What you need to know</h4>
 \t\t\t\t\t<pre>
Vardefs are where we define information about the fields for a module. 
 \t\t\t\t\t
It also specifies 75% of the information on relationships. 
 \t\t\t\t\t
There are also special attributes that can enable additional functionality for a module. 
 \t\t\t\t\t
It's broken down into:
\t<b>fields:</b> The fields of a module (most of these are stored in the database)
\t
\t<b>indices:</b> The indicies on the database
\t
\t<b>relationships:</b> The relationships for this module
\t
\t<b>templates:</b> the functionality/fields this module inherits from SugarObjects(located in include/SugarObjects). 
\t\tIn a vardef these are specified by the third argument in VardefManager::createVardef
\t\tFor Example - <b>VardefManager::createVardef('Contacts','Contact', array('default', 'assignable','team_security','person'));</b>
\t\twould add the fields for team security to contacts and make it an object that can be assigned to users.
\t\tThe 'person' value would indicate that that Contacts subclasses Person and gains all the fields/attributes that 'Person' 
\t\twould get. Since person extends basic it would also gain all the fields/attributes of basic as well.
\t\t\t\t\t  
\t\t\t\t\t 
\t\tThe SugarObjects that a module can extend are <b>'basic', 'company', 'file', 'issue', 'person'</b>. 
\t\tThese are the same objects you can build off of in ModuleBuilder. 
\t\tAdding a new SugarObject to include/SugarObjects/templates is the way 
\t\tto add modules to ModuleBuilder
\t\t\t\t\t 
\t\tBesides extending base objects, a module can also implement functionality defined in SugarObjects. 
\t\tYou can currenty implement <b>'assignable' and 'team_security'</b>. 
\t\t
\t\t
\t<b>attributes:</b>
\t\t<b>[table] (string) (required)</b> The database table where this module stores it's data - any custom fields will be stored in a new table 
\t\t\twith '_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
\t\t\tallowing us to join the two tables together. 
\t\t
\t\t<b>[comment] (string) (optional)</b> is a description of the module
\t\t
\t\t<b>[unified_search] (bool)(optional)</b> is global search (the search in the upper right corner on the screen) available for this module
\t\t
\t\t<b>[unified_search_default_enabled] (bool)(optional)</b> is this module available by default in global search
\t\t
\t\t<b>[optimistic_locking] (bool) (optional)</b> optimistic locking is the concept that on save if the record modifiy time (date_modified)
\t\t\t is newer than the the modify time of the record when it was loaded to edit (this time is stored in the session). 
\t\t
\t\t<b>[favorites] (bool) (optional)</b> should favorites be enabled for this module. Favorites are indicated by the stars next to a record 
\t\t\ton 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
\t\t\tby favorites.  
\t\t\t
\t\t<b>[duplicate_merge] (bool) (optional)</b> is systematic merging allowed between records of this module or not. This option is available from 
\t\t\tthe 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
\t\t\tmenu.
\t\t\t
\t\t<b>[audited] (bool) (optional)</b> auditing allows for the tracking of any changes to specified fields. In order to enable auditing you need to enable
\t\t\tit 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.
\t\t\t
\t\t<b>[custom_fields] (bool) (automatic) </b> if the module has custom fields this will be set to true
\t\t
\t\t\t
\t\t
\t\t
\t\t
\t\t\t\t\t 
\t\t\t\t\t 

\t\t\t\t\t  
\t\t\t\t\t
\t\t\t\t\t
\t\t\t\t\t</pre>
 \t\t\t\t</div>
 \t\t\t\t
 \t\t\t\t<div>
 \t\t\t\t
 \t\t\t\t</div>
 \t\t\t\t
EOQ;
        }
        echo "</div><div style='float:right'>Help Text</div></div>";
        //$this->printValue(VardefBrowser::findFieldsWithAttributes(array('type'=>'id'), $modules));
    }
Пример #2
0
 public function testfindFieldsWithAttributes()
 {
     //check with emptty attributes array
     $attributes = array();
     $fields1 = VardefBrowser::findFieldsWithAttributes($attributes);
     $this->assertTrue(is_array($fields1));
     //check with a very common attribute
     $attributes = array('id');
     $fields2 = VardefBrowser::findFieldsWithAttributes($attributes);
     $this->assertTrue(is_array($fields2));
     //check with a very specific attribute
     $attributes = array('category');
     $fields3 = VardefBrowser::findFieldsWithAttributes($attributes);
     $this->assertTrue(is_array($fields3));
     //check that all three arrays returned, are not same.
     $this->assertNotSame($fields1, $fields2);
     $this->assertNotSame($fields1, $fields3);
     $this->assertNotSame($fields2, $fields3);
 }