GroupedTabStructure   A
last analyzed

Complexity

Total Complexity 18

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%
Metric Value
dl 0
loc 107
ccs 0
cts 75
cp 0
rs 10
wmc 18
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
F get_tab_structure() 0 92 18
1
<?php
2
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
/*********************************************************************************
4
 * SugarCRM Community Edition is a customer relationship management program developed by
5
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
6
7
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
8
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
9
 *
10
 * This program is free software; you can redistribute it and/or modify it under
11
 * the terms of the GNU Affero General Public License version 3 as published by the
12
 * Free Software Foundation with the addition of the following permission added
13
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
14
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
15
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
16
 *
17
 * This program is distributed in the hope that it will be useful, but WITHOUT
18
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
20
 * details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License along with
23
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
24
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25
 * 02110-1301 USA.
26
 *
27
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
28
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
29
 *
30
 * The interactive user interfaces in modified source and object code versions
31
 * of this program must display Appropriate Legal Notices, as required under
32
 * Section 5 of the GNU Affero General Public License version 3.
33
 *
34
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
35
 * these Appropriate Legal Notices must retain the display of the "Powered by
36
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
37
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
38
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
39
 ********************************************************************************/
40
41
42
class GroupedTabStructure
43
{
44
	/** 
45
     * Prepare the tabs structure.
46
     * Uses 'Other' tab functionality.
47
     * If $modList is not specified, $modListHeader is used as default.
48
     * 
49
     * @param   array   optional list of modules considered valid
50
     * @param   array   optional array to temporarily union into the root of the tab structure 
51
    * @param bool  if  we set this param true, the other group tab will be returned no matter  $sugar_config['other_group_tab_displayed'] is true or false
52
     * @param bool  We use label value as return array key by default. But we can set this param true, that we can use the label name as return array key.
53
     * 
54
     * @return  array   the complete tab-group structure
55
	 */
56
    function get_tab_structure($modList = '', $patch = '', $ignoreSugarConfig=false, $labelAsKey=false)
57
    {
58
    	global $modListHeader, $app_strings, $app_list_strings, $modInvisListActivities;
59
        
60
        /* Use default if not provided */
61
        if(!$modList)
62
        {
63
        	$modList =& $modListHeader;
64
        }
65
66
        require 'include/tabConfig.php';
67
68
        /* Apply patch, use a reference if we can */
69
        if($patch)
70
        {
71
        	$tabStructure = $GLOBALS['tabStructure'];
72
        	
73
            foreach($patch as $mainTab => $subModules)
0 ignored issues
show
Bug introduced by
The expression $patch of type string is not traversable.
Loading history...
74
            {
75
                $tabStructure[$mainTab]['modules'] = array_merge($tabStructure[$mainTab]['modules'], $subModules);
76
            }
77
        }
78
        else
79
        {
80
        	$tabStructure =& $GLOBALS['tabStructure'];
81
        }
82
        
83
        $retStruct = array();
84
        $mlhUsed = array();
85
		//the invisible list should be merged if activities is set to be hidden
86
        if(in_array('Activities', $modList)){
87
        	$modList = array_merge($modList,$modInvisListActivities);
88
		}
89
		
90
		//Add any iFrame tabs to the 'other' group.
91
		$moduleExtraMenu = array();
92
		if(!should_hide_iframes()) {
93
			$iFrame = new iFrame();
94
			$frames = $iFrame->lookup_frames('tab');	
95
	        foreach($frames as $key => $values){
96
	        	$moduleExtraMenu[$key] = $values;
97
	        }
98
		} else if(isset($modList['iFrames'])) {
99
		    unset($modList['iFrames']);
100
		}
101
				
102
        $modList = array_merge($modList,$moduleExtraMenu);
103
                
104
        /* Only return modules which exists in the modList */
105
        foreach($tabStructure as $mainTab => $subModules)
106
        {
107
            //Ensure even empty groups are returned
108
        	if($labelAsKey){
109
                $retStruct[$subModules['label']]['modules'] = array();
110
            }else{
111
                $retStruct[$app_strings[$subModules['label']]]['modules']= array();
112
            }
113
114
            foreach($subModules['modules'] as $key => $subModule)
115
            {
116
               /* Perform a case-insensitive in_array check
117
                * and mark whichever module matched as used.
118
                */ 
119
                foreach($modList as $module)
120
                {
121
                    if(is_string($module) && strcasecmp($subModule, $module) === 0)
122
                    {
123
                    	if($labelAsKey){
124
                    		$retStruct[$subModules['label']]['modules'][$module] = $app_list_strings['moduleList'][$module];
125
                    	}else{
126
                    		$retStruct[$app_strings[$subModules['label']]]['modules'][$module] = $app_list_strings['moduleList'][$module];
127
                    	}                        
128
                        $mlhUsed[$module] = true;
129
                        break;
130
                    }
131
                }
132
            }
133
			//remove the group tabs if it has no sub modules under it	        
134
            if($labelAsKey){
135
                    if (empty($retStruct[$subModules['label']]['modules'])){
136
                    unset($retStruct[$subModules['label']]);
137
                    }
138
                    }else{
139
                    if (empty($retStruct[$app_strings[$subModules['label']]]['modules'])){
140
                    unset($retStruct[$app_strings[$subModules['label']]]);
141
                    }
142
			}
143
        }
144
        
145
//        _pp($retStruct);
146
        return $retStruct;
147
    }
148
}
149
150
?>
151