Passed
Push — scrutinizer-code-quality ( 09f5a1...c4c5fb )
by Adam
56:05 queued 14:08
created

VarDefHandler::VarDefHandler()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 2 Features 1
Metric Value
cc 2
eloc 7
c 2
b 2
f 1
nc 2
nop 2
dl 0
loc 10
ccs 0
cts 10
cp 0
crap 6
rs 9.4285
1
<?php
2
/*********************************************************************************
3
 * SugarCRM Community Edition is a customer relationship management program developed by
4
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
5
6
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
7
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
8
 *
9
 * This program is free software; you can redistribute it and/or modify it under
10
 * the terms of the GNU Affero General Public License version 3 as published by the
11
 * Free Software Foundation with the addition of the following permission added
12
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
13
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
14
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
15
 *
16
 * This program is distributed in the hope that it will be useful, but WITHOUT
17
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
19
 * details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License along with
22
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
23
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24
 * 02110-1301 USA.
25
 *
26
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
27
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
28
 *
29
 * The interactive user interfaces in modified source and object code versions
30
 * of this program must display Appropriate Legal Notices, as required under
31
 * Section 5 of the GNU Affero General Public License version 3.
32
 *
33
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
34
 * these Appropriate Legal Notices must retain the display of the "Powered by
35
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
36
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
37
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
38
 ********************************************************************************/
39
40
41
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
42
43
/**
44
 * Vardef Handler Object
45
 * @api
46
 */
47
class VarDefHandler {
48
49
	var $meta_array_name;
50
	var $target_meta_array = false;
51
	var $start_none = false;
52
	var $extra_array = array();					//used to add custom items
53
	var $options_array = array();
54
	var $module_object;
55
	var $start_none_lbl = null;
56
57
58
    function __construct($module, $meta_array_name=null)
59
    {
60
        $this->meta_array_name = $meta_array_name;
61
		$this->module_object = $module;
62
		if($meta_array_name!=null){
63
			global $vardef_meta_array;
64
			include("include/VarDefHandler/vardef_meta_arrays.php");
65
			$this->target_meta_array = $vardef_meta_array[$meta_array_name];
66
		}
67
68
	//end function setup
69
	}
70
71
	/**
72
	 * @deprecated deprecated since version 7.6, PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code, use __construct instead
73
	 */
74
	function VarDefHandler($module, $meta_array_name=null){
75
		$deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
76
		if(isset($GLOBALS['log'])) {
77
			$GLOBALS['log']->deprecated($deprecatedMessage);
78
		}
79
		else {
80
			trigger_error($deprecatedMessage, E_USER_DEPRECATED);
81
		}
82
		self::__construct($module, $meta_array_name);
83
	}
84
85
	function get_vardef_array($use_singular=false, $remove_dups = false, $use_field_name = false, $use_field_label = false){
86
		global $dictionary;
87
		global $current_language;
88
		global $app_strings;
89
		global $app_list_strings;
90
91
		$temp_module_strings = return_module_language($current_language, $this->module_object->module_dir);
92
93
		$base_array = $this->module_object->field_defs;
94
		//$base_array = $dictionary[$this->module_object->object_name]['fields'];
95
96
		///Inclue empty none set or not
97
		if($this->start_none==true){
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
98
			if(!empty($this->start_none_lbl)){
99
				$this->options_array[''] = $this->start_none_lbl;
100
			} else {
101
				$this->options_array[''] = $app_strings['LBL_NONE'];
102
			}
103
		}
104
105
	///used for special one off items added to filter array	 ex. would be href link for alert templates
106
		if(!empty($this->extra_array)){
107
108
			foreach($this->extra_array as $key => $value){
109
				$this->options_array[$key] = $value;
110
			}
111
		}
112
	/////////end special one off//////////////////////////////////
113
114
115
		foreach($base_array as $key => $value_array){
116
			$compare_results = $this->compare_type($value_array);
117
118
			if($compare_results == true){
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
119
                 if($value_array['type'] == 'link' && !$use_field_label){
120
					 $relName = $value_array['name'];
121
					 $this->module_object->load_relationship($relName);
122
					 if(!empty($app_list_strings['moduleList'][$this->module_object->$relName->getRelatedModuleName()])){
123
						 $label_name = $app_list_strings['moduleList'][$this->module_object->$relName->getRelatedModuleName()];
124
					 }else{
125
                    	$label_name = $this->module_object->$relName->getRelatedModuleName();
126
					 }
127
                }
128
				else if(!empty($value_array['vname'])){
129
					$label_name = $value_array['vname'];
130
				} else {
131
					$label_name = $value_array['name'];
132
				}
133
134
135
				$label_name = get_label($label_name, $temp_module_strings);
136
137
				if(!empty($value_array['table'])){
138
					//Custom Field
139
					$column_table = $value_array['table'];
140
				} else {
141
					//Non-Custom Field
142
					$column_table = $this->module_object->table_name;
143
				}
144
145
                if($value_array['type'] == 'link'){
146
                	if($use_field_name){
147
                		$index = $value_array['name'];
148
149
                	}else{
150
                		$index = $this->module_object->$key->getRelatedModuleName();
151
                	}
152
                }else{
153
					$index = $key;
154
                }
155
156
				$value = trim($label_name, ':');
157
				if($remove_dups){
158
					if(!in_array($value, $this->options_array))
159
						$this->options_array[$index] = $value;
160
				}
161
				else
162
					$this->options_array[$index] = $value;
163
164
			//end if field is included
165
			}
166
167
		//end foreach
168
		}
169
		if($use_singular == true){
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
170
			return convert_module_to_singular($this->options_array);
171
		} else {
172
			return $this->options_array;
173
		}
174
175
	//end get_vardef_array
176
	}
177
178
179
	function compare_type($value_array){
180
181
		//Filter nothing?
182
		if(!is_array($this->target_meta_array)){
183
			return true;
184
		}
185
186
		////////Use the $target_meta_array;
187
		if(isset($this->target_meta_array['inc_override'])){
188
			foreach($this->target_meta_array['inc_override'] as $attribute => $value){
189
190
					foreach($value as $actual_value){
191
						if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return true;
192
					}
193
					if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return true;
194
195
			}
196
		}
197
		if(isset($this->target_meta_array['ex_override'])){
198
			foreach($this->target_meta_array['ex_override'] as $attribute => $value){
199
200
201
					foreach($value as $actual_value){
202
					if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;
203
204
						if(isset($value_array[$attribute]) && $value_array[$attribute] == $value) return false;
205
					}
206
207
			//end foreach inclusion array
208
			}
209
		}
210
211
		if(isset($this->target_meta_array['inclusion'])){
212
			foreach($this->target_meta_array['inclusion'] as $attribute => $value){
213
214
				if($attribute=="type"){
215
					foreach($value as $actual_value){
216
					if(isset($value_array[$attribute]) && $value_array[$attribute] != $actual_value) return false;
217
					}
218
				} else {
219
					if(isset($value_array[$attribute]) && $value_array[$attribute] != $value) return false;
220
				}
221
			//end foreach inclusion array
222
			}
223
		}
224
225
		if(isset($this->target_meta_array['exclusion'])){
226
			foreach($this->target_meta_array['exclusion'] as $attribute => $value){
227
228
				foreach($value as $actual_value){
229
					if(isset($value_array[$attribute]) && $value_array[$attribute] == $actual_value) return false;
230
				}
231
232
			//end foreach inclusion array
233
			}
234
		}
235
236
237
		return true;
238
239
	//end function compare_type
240
	}
241
242
//end class VarDefHandler
243
}
244
245
246
?>
247