Test Failed
Push — CI ( 0f01dd...c95a04 )
by Adam
55:13
created

ProjectTaskViewList::display()   F

Complexity

Conditions 62
Paths > 20000

Size

Total Lines 211
Code Lines 140

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 211
rs 2
cc 62
eloc 140
nc 429496.7295
nop 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
if(!defined('sugarEntry') || !sugarEntry) die('Not A Valid Entry Point');
3
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
 * Description: This file is used to override the default Meta-data EditView behavior
45
 * to provide customization specific to the Calls module.
46
 * Portions created by SugarCRM are Copyright (C) SugarCRM, Inc.
47
 * All Rights Reserved.
48
 * Contributor(s): ______________________________________..
49
 ********************************************************************************/
50
51
require_once('include/MVC/View/views/view.list.php');
52
53
class ProjectTaskViewList extends ViewList{
54
 	function ProjectTaskViewList(){
55
 		parent::ViewList();
56
57
 	}
58
59
 	function display(){
60
 		if(!$this->bean->ACLAccess('list')){
61
 			ACLController::displayNoAccess();
62
 			return;
63
 		}
64
        $module = $GLOBALS['module'];
65
 	    $metadataFile = null;
66
        $foundViewDefs = false;
67
        if(file_exists('custom/modules/' . $module. '/metadata/listviewdefs.php')){
68
            $metadataFile = 'custom/modules/' . $module . '/metadata/listviewdefs.php';
69
            $foundViewDefs = true;
70
        }else{
71
            if(file_exists('custom/modules/'.$module.'/metadata/metafiles.php')){
72
                require_once('custom/modules/'.$module.'/metadata/metafiles.php');
73
                if(!empty($metafiles[$module]['listviewdefs'])){
0 ignored issues
show
Bug introduced by
The variable $metafiles seems to never exist, and therefore empty should always return true. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
74
                    $metadataFile = $metafiles[$module]['listviewdefs'];
75
                    $foundViewDefs = true;
76
                }
77
            }elseif(file_exists('modules/'.$module.'/metadata/metafiles.php')){
78
                require_once('modules/'.$module.'/metadata/metafiles.php');
79
                if(!empty($metafiles[$module]['listviewdefs'])){
80
                    $metadataFile = $metafiles[$module]['listviewdefs'];
81
                    $foundViewDefs = true;
82
                }
83
            }
84
        }
85
        if(!$foundViewDefs && file_exists('modules/'.$module.'/metadata/listviewdefs.php')){
86
                $metadataFile = 'modules/'.$module.'/metadata/listviewdefs.php';
87
        }
88
        require_once($metadataFile);
89
90
		$seed = $this->bean;
91
        if(!empty($this->bean->object_name) && isset($_REQUEST[$module.'2_'.strtoupper($this->bean->object_name).'_offset'])) {//if you click the pagination button, it will populate the search criteria here
92
            if(!empty($_REQUEST['current_query_by_page'])) {//The code support multi browser tabs pagination
93
                $blockVariables = array('mass', 'uid', 'massupdate', 'delete', 'merge', 'selectCount', 'request_data', 'current_query_by_page', $module.'2_'.strtoupper($this->bean->object_name).'_ORDER_BY');
94
		        if(isset($_REQUEST['lvso'])){
95
		        	$blockVariables[] = 'lvso';
96
		        }
97
98
                $current_query_by_page = unserialize(base64_decode($_REQUEST['current_query_by_page']));
99
                foreach($current_query_by_page as $search_key=>$search_value) {
100
                    if($search_key != $module.'2_'.strtoupper($this->bean->object_name).'_offset' && !in_array($search_key, $blockVariables)) {
101
                        if (!is_array($search_value)) {
102
                            $_REQUEST[$search_key] = $GLOBALS['db']->quote($search_value);
103
                        }
104
                        else {
105
                            foreach ($search_value as $key=>&$val) {
106
                                $val = $GLOBALS['db']->quote($val);
107
                            }
108
                            $_REQUEST[$search_key] = $search_value;
109
                        }
110
                    }
111
                }
112
            }
113
        }
114
115
        if(!empty($_REQUEST['saved_search_select']) && $_REQUEST['saved_search_select']!='_none') {
116
            if(empty($_REQUEST['button']) && (empty($_REQUEST['clear_query']) || $_REQUEST['clear_query']!='true')) {
117
                $this->saved_search = loadBean('SavedSearch');
0 ignored issues
show
Deprecated Code introduced by
The function loadBean() has been deprecated with message: use SugarModule::loadBean() instead

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
118
                $this->saved_search->retrieveSavedSearch($_REQUEST['saved_search_select']);
119
                $this->saved_search->populateRequest();
120
            }
121
            elseif(!empty($_REQUEST['button'])) { // click the search button, after retrieving from saved_search
122
                $_SESSION['LastSavedView'][$_REQUEST['module']] = '';
123
                unset($_REQUEST['saved_search_select']);
124
                unset($_REQUEST['saved_search_select_name']);
125
            }
126
        }
127
128
		$lv = new ListViewSmarty();
129
		$displayColumns = array();
130
		if(!empty($_REQUEST['displayColumns'])) {
131
		    foreach(explode('|', $_REQUEST['displayColumns']) as $num => $col) {
132
		        if(!empty($listViewDefs[$module][$col]))
133
		            $displayColumns[$col] = $listViewDefs[$module][$col];
134
		    }
135
		}
136
		else {
137
		    foreach($listViewDefs[$module] as $col => $params) {
138
		        if(!empty($params['default']) && $params['default'])
139
		            $displayColumns[$col] = $params;
140
		    }
141
		}
142
143
        $params = array( 'massupdate' => true, 'export' => true);
144
145
		if(!empty($_REQUEST['orderBy'])) {
146
		    $params['orderBy'] = $_REQUEST['orderBy'];
147
		    $params['overrideOrder'] = true;
148
		    if(!empty($_REQUEST['sortOrder'])) $params['sortOrder'] = $_REQUEST['sortOrder'];
149
		}
150
		$lv->displayColumns = $displayColumns;
151
152
		$this->seed = $seed;
153
		$this->module = $module;
154
155
		$searchForm = null;
156
	 	$storeQuery = new StoreQuery();
157
		if(!isset($_REQUEST['query'])){
158
			$storeQuery->loadQuery($this->module);
159
			$storeQuery->populateRequest();
160
		}else{
161
			$storeQuery->saveFromRequest($this->module);
162
		}
163
164
		//search
165
		$view = 'basic_search';
166
		if(!empty($_REQUEST['search_form_view']))
167
			$view = $_REQUEST['search_form_view'];
168
		$headers = true;
169
		if(!empty($_REQUEST['search_form_only']) && $_REQUEST['search_form_only'])
170
			$headers = false;
171
		elseif(!isset($_REQUEST['search_form']) || $_REQUEST['search_form'] != 'false') {
172
        	if(isset($_REQUEST['searchFormTab']) && $_REQUEST['searchFormTab'] == 'advanced_search') {
173
				$view = 'advanced_search';
174
			}else {
175
				$view = 'basic_search';
176
			}
177
		}
178
179
		$use_old_search = true;
180
		if(file_exists('modules/'.$this->module.'/SearchForm.html')){
181
			require_once('include/SearchForm/SearchForm.php');
182
			$searchForm = new SearchForm($this->module, $this->seed);
183
		}else{
184
			$use_old_search = false;
185
			require_once('include/SearchForm/SearchForm2.php');
186
187
188
			if (file_exists('custom/modules/'.$this->module.'/metadata/searchdefs.php'))
189
			{
190
			    require_once('custom/modules/'.$this->module.'/metadata/searchdefs.php');
191
			}
192
			elseif (!empty($metafiles[$this->module]['searchdefs']))
193
			{
194
				require_once($metafiles[$this->module]['searchdefs']);
195
			}
196
			elseif (file_exists('modules/'.$this->module.'/metadata/searchdefs.php'))
197
			{
198
			    require_once('modules/'.$this->module.'/metadata/searchdefs.php');
199
			}
200
201
202
			if(!empty($metafiles[$this->module]['searchfields']))
203
                require($metafiles[$this->module]['searchfields']);
204
			elseif(file_exists('modules/'.$this->module.'/metadata/SearchFields.php'))
205
                require('modules/'.$this->module.'/metadata/SearchFields.php');
206
207
208
			$searchForm = new SearchForm($this->seed, $this->module, $this->action);
209
			$searchForm->setup($searchdefs, $searchFields, 'SearchFormGeneric.tpl', $view, $listViewDefs);
0 ignored issues
show
Unused Code introduced by
The call to SearchForm::setup() has too many arguments starting with $searchdefs.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
210
			$searchForm->lv = $lv;
211
		}
212
213
		if(isset($this->options['show_title']) && $this->options['show_title']) {
214
			$moduleName = isset($this->seed->module_dir) ? $this->seed->module_dir : $GLOBALS['mod_strings']['LBL_MODULE_NAME'];
215
			echo getClassicModuleTitle($moduleName, array($GLOBALS['mod_strings']['LBL_MODULE_TITLE']), FALSE);
216
		}
217
218
		$where = '';
219
		if(isset($_REQUEST['query']))
220
		{
221
			// we have a query
222
	    	if(!empty($_SERVER['HTTP_REFERER']) && preg_match('/action=EditView/', $_SERVER['HTTP_REFERER'])) { // from EditView cancel
223
	       		$searchForm->populateFromArray($storeQuery->query);
224
	    	}
225
	    	else {
226
                $searchForm->populateFromRequest();
227
	    	}
228
			$where_clauses = $searchForm->generateSearchWhere(true, $this->seed->module_dir);
229
			if (count($where_clauses) > 0 )$where = '('. implode(' ) AND ( ', $where_clauses) . ')';
230
			$GLOBALS['log']->info("List View Where Clause: $where");
231
		}
232
		if($use_old_search){
233
			switch($view) {
234
				case 'basic_search':
235
			    	$searchForm->setup();
236
			        $searchForm->displayBasic($headers);
237
			        break;
238
			     case 'advanced_search':
239
			     	$searchForm->setup();
240
			        $searchForm->displayAdvanced($headers);
241
			        break;
242
			     case 'saved_views':
243
			     	echo $searchForm->displaySavedViews($listViewDefs, $lv, $headers);
244
			       break;
245
			}
246
		}else{
247
			echo $searchForm->display($headers);
0 ignored issues
show
Bug introduced by
The method display() does not exist on SearchForm. Did you maybe mean displayTabs()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
248
		}
249
		if(!$headers)
250
			return;
251
         /*
252
         * Bug 50575 - related search columns not inluded in query in a proper way
253
         */
254
         $lv->searchColumns = $searchForm->searchColumns;
255
256
		if(empty($_REQUEST['search_form_only']) || $_REQUEST['search_form_only'] == false){
257
            //Bug 58841 - mass update form was not displayed for non-admin users that should have access
258
            if(ACLController::checkAccess($module, 'massupdate') || ACLController::checkAccess($module, 'export'))
259
            {
260
                $lv->setup($seed, 'include/ListView/ListViewGeneric.tpl', $where, $params);
261
            }
262
            else
263
            {
264
                $lv->setup($seed, 'include/ListView/ListViewNoMassUpdate.tpl', $where, $params);
265
            }
266
267
			echo $lv->display();
268
		}
269
 	}
270
}
271
272
?>
273