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

SugarWidgetField::SugarWidgetField()   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 1
Bugs 1 Features 1
Metric Value
cc 2
eloc 7
c 1
b 1
f 1
nc 2
nop 1
dl 0
loc 10
ccs 0
cts 7
cp 0
crap 6
rs 9.4285
1
<?php
2 1
if(!defined('sugarEntry') || !sugarEntry)
3
	die('Not A Valid Entry Point');
4
/*********************************************************************************
5
 * SugarCRM Community Edition is a customer relationship management program developed by
6
 * SugarCRM, Inc. Copyright (C) 2004-2013 SugarCRM Inc.
7
8
 * SuiteCRM is an extension to SugarCRM Community Edition developed by Salesagility Ltd.
9
 * Copyright (C) 2011 - 2014 Salesagility Ltd.
10
 *
11
 * This program is free software; you can redistribute it and/or modify it under
12
 * the terms of the GNU Affero General Public License version 3 as published by the
13
 * Free Software Foundation with the addition of the following permission added
14
 * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
15
 * IN WHICH THE COPYRIGHT IS OWNED BY SUGARCRM, SUGARCRM DISCLAIMS THE WARRANTY
16
 * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
17
 *
18
 * This program is distributed in the hope that it will be useful, but WITHOUT
19
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
20
 * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
21
 * details.
22
 *
23
 * You should have received a copy of the GNU Affero General Public License along with
24
 * this program; if not, see http://www.gnu.org/licenses or write to the Free
25
 * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26
 * 02110-1301 USA.
27
 *
28
 * You can contact SugarCRM, Inc. headquarters at 10050 North Wolfe Road,
29
 * SW2-130, Cupertino, CA 95014, USA. or at email address [email protected].
30
 *
31
 * The interactive user interfaces in modified source and object code versions
32
 * of this program must display Appropriate Legal Notices, as required under
33
 * Section 5 of the GNU Affero General Public License version 3.
34
 *
35
 * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
36
 * these Appropriate Legal Notices must retain the display of the "Powered by
37
 * SugarCRM" logo and "Supercharged by SuiteCRM" logo. If the display of the logos is not
38
 * reasonably feasible for  technical reasons, the Appropriate Legal Notices must
39
 * display the words  "Powered by SugarCRM" and "Supercharged by SuiteCRM".
40
 ********************************************************************************/
41
42
43
44
45
46
47
class SugarWidgetField extends SugarWidget {
48
49 1
	function __construct(&$layout_manager) {
50 1
        parent::__construct($layout_manager);
51 1
    }
52
53
    /**
54
     * @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
55
     */
56
    function SugarWidgetField(&$layout_manager){
57
        $deprecatedMessage = 'PHP4 Style Constructors are deprecated and will be remove in 7.8, please update your code';
58
        if(isset($GLOBALS['log'])) {
59
            $GLOBALS['log']->deprecated($deprecatedMessage);
60
        }
61
        else {
62
            trigger_error($deprecatedMessage, E_USER_DEPRECATED);
63
        }
64
        self::__construct($layout_manager);
65
    }
66
67
68
	function display($layout_def) {
69
		//print $layout_def['start_link_wrapper']."===";
70
		$context = $this->layout_manager->getAttribute('context'); //_ppd($context);
71
		$func_name = 'display'.$context;
72
73
		if (!empty ($context) && method_exists($this, $func_name)) {
74
			return $this-> $func_name ($layout_def);
75
		} else {
76
			return 'display not found:'.$func_name;
77
		}
78
	}
79
80
	function _get_column_alias($layout_def) {
81
		$alias_arr = array ();
82
83
		if (!empty ($layout_def['name']) && $layout_def['name'] == 'count') {
84
			return 'count';
85
		}
86
87
		if (!empty ($layout_def['table_alias'])) {
88
			array_push($alias_arr, $layout_def['table_alias']);
89
		}
90
91
		if (!empty ($layout_def['name'])) {
92
			array_push($alias_arr, $layout_def['name']);
93
		}
94
95
		return $this->getTruncatedColumnAlias(implode("_", $alias_arr));
96
	}
97
98
	function & displayDetailLabel(& $layout_def) {
99
100
		return '';
101
	}
102
103
	function & displayDetail($layout_def) {
104
105
        $layout_def = '';
106
		return $layout_def;
107
	}
108
109
	function displayHeaderCellPlain($layout_def)
110
	{
111
		if (!empty ($layout_def['label'])) {
112
			return $layout_def['label'];
113
		}
114
		if (!empty ($layout_def['vname'])) {
115
			return translate($layout_def['vname'], $this->layout_manager->getAttribute('module_name'));
116
		}
117
		return '';
118
	}
119
120
	function displayHeaderCell($layout_def) {
121
		$module_name = $this->layout_manager->getAttribute('module_name');
122
123
		$this->local_current_module = $_REQUEST['module'];
124
		$this->is_dynamic = true;
125
		// don't show sort links if name isn't defined
126
		if (empty ($layout_def['name']) || (isset ($layout_def['sortable']) && !$layout_def['sortable'])) {
127
			return $this->displayHeaderCellPlain($layout_def);
128
		}
129
130
		$header_cell_text = $this->displayHeaderCellPlain($layout_def);
131
132
		$subpanel_module = $layout_def['subpanel_module'];
133
		$html_var = $subpanel_module . "_CELL";
134
		if (empty ($this->base_URL)) {
135
			$objListView = new ListView();
136
			$this->base_URL = $objListView -> getBaseURL($html_var);
137
			$split_url = explode('&to_pdf=true&action=SubPanelViewer&subpanel=', $this->base_URL);
138
			$this->base_URL = $split_url[0];
139
			$this->base_URL .= '&inline=true&to_pdf=true&action=SubPanelViewer&subpanel=';
140
		}
141
		$sort_by_name = $layout_def['name'];
142
		if (isset ($layout_def['sort_by'])) {
143
			$sort_by_name = $layout_def['sort_by'];
144
		}
145
146
		$objListView = new ListView();
147
		$sort_by = $objListView->getSessionVariableName($html_var, "ORDER_BY").'='.$sort_by_name;
148
149
		$start = (empty ($layout_def['start_link_wrapper'])) ? '' : $layout_def['start_link_wrapper'];
150
		$end = (empty ($layout_def['end_link_wrapper'])) ? '' : $layout_def['end_link_wrapper'];
151
152
		$header_cell = "<a class=\"listViewThLinkS1\" href=\"".$start.$this->base_URL.$subpanel_module.'&'.$sort_by.$end."\">";
153
		$header_cell .= $header_cell_text;
154
155
		$imgArrow = '';
156
157
		if (isset ($layout_def['sort'])) {
158
			$imgArrow = $layout_def['sort'];
159
		}
160
		$arrow_start = $objListView->getArrowUpDownStart($imgArrow);
161
		$arrow_end = $objListView->getArrowUpDownEnd($imgArrow);
162
		$header_cell .= " ".$arrow_start.$arrow_end."</a>";
163
164
		return $header_cell;
165
166
	}
167
168
	function displayList($layout_def) {
169
		return $this->displayListPlain($layout_def);
170
	}
171
172
	function displayListPlain($layout_def) {
173
		$value= $this->_get_list_value($layout_def);
174
		if (isset($layout_def['widget_type']) && $layout_def['widget_type'] =='checkbox') {
175
			if ($value != '' &&  ($value == 'on' || intval($value) == 1 || $value == 'yes'))
176
			{
177
				return "<input name='checkbox_display' class='checkbox' type='checkbox' disabled='true' checked>";
178
			}
179
			return "<input name='checkbox_display' class='checkbox' type='checkbox' disabled='true'>";
180
		}
181
		return $value;
182
	}
183
184
	function _get_list_value(& $layout_def)
185
	{
186
		$key = '';
187
		if ( isset($layout_def['varname']) ) {
188
		    $key = strtoupper($layout_def['varname']);
189
		}
190
		else {
191
			$key = strtoupper($this->_get_column_alias($layout_def));
192
		}
193
194
		if ( isset($layout_def['fields'][$key]) ) {
195
			return $layout_def['fields'][$key];
196
		}
197
198
		return '';
199
	}
200
201
	function & displayEditLabel($layout_def) {
202
		return '';
203
	}
204
205
	function & displayEdit($layout_def) {
206
		return '';
207
	}
208
209
	function & displaySearchLabel($layout_def) {
210
		return '';
211
	}
212
213
	function & displaySearch($layout_def) {
214
		return '';
215
	}
216
217
	function displayInput($layout_def) {
218
		return ' -- Not Implemented --';
219
	}
220
221
    function getVardef($layout_def) {
222
        $myName = $layout_def['column_key'];
223
        $vardef = $this->layout_manager->defs['reporter']->all_fields[$myName];
224
225
        if ( !isset($vardef) ) {
226
            // No vardef, return an empty array
227
            return array();
228
        } else {
229
            return $vardef;
230
        }
231
    }
232
}
233