| Conditions | 62 |
| Paths | > 20000 |
| Total Lines | 211 |
| Code Lines | 140 |
| Lines | 0 |
| Ratio | 0 % |
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:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 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'])){ |
||
|
|
|||
| 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'); |
||
| 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); |
||
| 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); |
||
| 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 | } |
||
| 273 |
This check looks for calls to
isset(...)orempty()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.