| Conditions | 44 |
| Paths | > 20000 |
| Total Lines | 278 |
| Code Lines | 152 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 1980 |
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 |
||
| 197 | function display($showContainer = true, $forceTabless = false) |
||
| 198 | { |
||
| 199 | global $layout_edit_mode, $sugar_version, $sugar_config, $current_user, $app_strings; |
||
| 200 | if(isset($layout_edit_mode) && $layout_edit_mode){ |
||
| 201 | return; |
||
| 202 | } |
||
| 203 | |||
| 204 | global $modListHeader; |
||
| 205 | |||
| 206 | ob_start(); |
||
| 207 | echo '<script type="text/javascript" src="'. getJSPath('include/SubPanel/SubPanelTiles.js') . '"></script>'; |
||
| 208 | ?> |
||
| 209 | <script> |
||
| 210 | if(document.DetailView != null && |
||
| 211 | document.DetailView.elements != null && |
||
| 212 | document.DetailView.elements.layout_def_key != null && |
||
| 213 | typeof document.DetailView.elements['layout_def_key'] != 'undefined'){ |
||
| 214 | document.DetailView.elements['layout_def_key'].value = '<?php echo $this->layout_def_key; ?>'; |
||
| 215 | } |
||
| 216 | </script> |
||
| 217 | <?php |
||
| 218 | |||
| 219 | $tabs = array(); |
||
| 220 | $default_div_display = 'inline'; |
||
| 221 | if(!empty($sugar_config['hide_subpanels_on_login'])){ |
||
| 222 | if(!isset($_SESSION['visited_details'][$this->focus->module_dir])){ |
||
| 223 | setcookie($this->focus->module_dir . '_divs', '',0,null,null,false,true); |
||
| 224 | unset($_COOKIE[$this->focus->module_dir . '_divs']); |
||
| 225 | $_SESSION['visited_details'][$this->focus->module_dir] = true; |
||
| 226 | |||
| 227 | } |
||
| 228 | $default_div_display = 'none'; |
||
| 229 | } |
||
| 230 | $div_cookies = get_sub_cookies($this->focus->module_dir . '_divs'); |
||
| 231 | |||
| 232 | |||
| 233 | //Display the group header. this section is executed only if the tabbed interface is being used. |
||
| 234 | $current_key = ''; |
||
| 235 | if (! empty($this->show_tabs)) |
||
| 236 | { |
||
| 237 | require_once('include/tabs.php'); |
||
| 238 | $tab_panel = new SugarWidgetTabs($tabs, $current_key, 'showSubPanel'); |
||
| 239 | echo get_form_header('Related', '', false); |
||
| 240 | echo "<br />" . $tab_panel->display(); |
||
| 241 | } |
||
| 242 | |||
| 243 | if(empty($_REQUEST['subpanels'])) |
||
| 244 | { |
||
| 245 | $selected_group = $forceTabless?'':$this->getSelectedGroup(); |
||
| 246 | $usersLayout = $current_user->getPreference('subpanelLayout', $this->focus->module_dir); |
||
| 247 | |||
| 248 | // we need to use some intelligence here when restoring the user's layout, as new modules with new subpanels might have been installed since the user's layout was recorded |
||
| 249 | // this means that we can't just restore the old layout verbatim as the new subpanels would then go walkabout |
||
| 250 | // so we need to do a merge while attempting as best we can to preserve the sense of the specified order |
||
| 251 | // this is complicated by the different ordering schemes used in the two sources for the panels: the user's layout uses an ordinal layout, the panels from getTabs have an explicit ordering driven by the 'order' parameter |
||
| 252 | // it's not clear how to best reconcile these two schemes; so we punt on it, and add all new panels to the end of the user's layout. At least this will give them a clue that something has changed... |
||
| 253 | // we also now check for tabs that have been removed since the user saved his or her preferences. |
||
| 254 | |||
| 255 | $tabs = $this->getTabs($showContainer, $selected_group) ; |
||
| 256 | |||
| 257 | if(!empty($usersLayout)) |
||
| 258 | { |
||
| 259 | $availableTabs = $tabs ; |
||
| 260 | $tabs = array_intersect ( $usersLayout , $availableTabs ) ; // remove any tabs that have been removed since the user's layout was saved |
||
| 261 | foreach (array_diff ( $availableTabs , $usersLayout ) as $tab) |
||
| 262 | $tabs [] = $tab ; |
||
| 263 | } |
||
| 264 | } |
||
| 265 | else |
||
| 266 | { |
||
| 267 | $tabs = explode(',', $_REQUEST['subpanels']); |
||
| 268 | } |
||
| 269 | |||
| 270 | $tab_names = array(); |
||
| 271 | |||
| 272 | if($showContainer) |
||
| 273 | { |
||
| 274 | echo '<ul class="noBullet" id="subpanel_list">'; |
||
| 275 | } |
||
| 276 | //echo "<li id='hidden_0' style='height: 5px' class='noBullet'> </li>"; |
||
| 277 | if (empty($GLOBALS['relationships'])) { |
||
| 278 | if (!class_exists('Relationship')) { |
||
| 279 | require('modules/Relationships/Relationship.php'); |
||
| 280 | } |
||
| 281 | $rel= new Relationship(); |
||
| 282 | $rel->load_relationship_meta(); |
||
| 283 | } |
||
| 284 | |||
| 285 | // this array will store names of sub-panels that can contain items |
||
| 286 | // of each module |
||
| 287 | $module_sub_panels = array(); |
||
| 288 | |||
| 289 | foreach ($tabs as $tab) |
||
| 290 | { |
||
| 291 | //load meta definition of the sub-panel. |
||
| 292 | $thisPanel=$this->subpanel_definitions->load_subpanel($tab); |
||
| 293 | if ($thisPanel === false) |
||
| 294 | continue; |
||
| 295 | //this if-block will try to skip over ophaned subpanels. Studio/MB are being delete unloaded modules completely. |
||
| 296 | //this check will ignore subpanels that are collections (activities, history, etc) |
||
| 297 | if (!isset($thisPanel->_instance_properties['collection_list']) and isset($thisPanel->_instance_properties['get_subpanel_data']) ) { |
||
| 298 | //ignore when data source is a function |
||
| 299 | |||
| 300 | if (!isset($this->focus->field_defs[$thisPanel->_instance_properties['get_subpanel_data']])) { |
||
| 301 | if (stripos($thisPanel->_instance_properties['get_subpanel_data'],'function:') === false) { |
||
| 302 | $GLOBALS['log']->fatal("Bad subpanel definition, it has incorrect value for get_subpanel_data property " .$tab); |
||
| 303 | continue; |
||
| 304 | } |
||
| 305 | } else { |
||
| 306 | $rel_name=''; |
||
| 307 | if (isset($this->focus->field_defs[$thisPanel->_instance_properties['get_subpanel_data']]['relationship'])) { |
||
| 308 | $rel_name=$this->focus->field_defs[$thisPanel->_instance_properties['get_subpanel_data']]['relationship']; |
||
| 309 | } |
||
| 310 | |||
| 311 | if (empty($rel_name) or !isset($GLOBALS['relationships'][$rel_name])) { |
||
| 312 | $GLOBALS['log']->fatal("Missing relationship definition " .$rel_name. ". skipping " .$tab ." subpanel"); |
||
| 313 | continue; |
||
| 314 | } |
||
| 315 | } |
||
| 316 | } |
||
| 317 | |||
| 318 | if ($thisPanel->isCollection()) { |
||
| 319 | // collect names of sub-panels that may contain items of each module |
||
| 320 | $collection_list = $thisPanel->get_inst_prop_value('collection_list'); |
||
| 321 | if (is_array($collection_list)) { |
||
| 322 | foreach ($collection_list as $data) { |
||
| 323 | if (!empty($data['module'])) { |
||
| 324 | $module_sub_panels[$data['module']][$tab] = true; |
||
| 325 | } |
||
| 326 | } |
||
| 327 | } |
||
| 328 | } else { |
||
| 329 | $module = $thisPanel->get_module_name(); |
||
| 330 | if (!empty($module)) { |
||
| 331 | $module_sub_panels[$module][$tab] = true; |
||
| 332 | } |
||
| 333 | } |
||
| 334 | |||
| 335 | echo '<li class="noBullet" id="whole_subpanel_' . $tab . '">'; |
||
| 336 | |||
| 337 | $display= 'none'; |
||
| 338 | $div_display = $default_div_display; |
||
| 339 | $cookie_name = $tab . '_v'; |
||
| 340 | |||
| 341 | if (isset($thisPanel->_instance_properties['collapsed']) && $thisPanel->_instance_properties['collapsed']) |
||
| 342 | { |
||
| 343 | $div_display = 'none'; |
||
| 344 | } |
||
| 345 | |||
| 346 | if(isset($div_cookies[$cookie_name])){ |
||
| 347 | //If defaultSubPanelExpandCollapse is set, ignore the cookie that remembers whether the panel is expanded or collapsed. |
||
| 348 | //To be used with the above 'collapsed' metadata setting so they will always be set the same when the page is loaded. |
||
| 349 | if(!isset($sugar_config['defaultSubPanelExpandCollapse']) || $sugar_config['defaultSubPanelExpandCollapse'] == false) |
||
| 350 | $div_display = $div_cookies[$cookie_name]; |
||
| 351 | } |
||
| 352 | if(!empty($sugar_config['hide_subpanels'])){ |
||
| 353 | $div_display = 'none'; |
||
| 354 | } |
||
| 355 | if($thisPanel->isDefaultHidden()) { |
||
| 356 | $div_display = 'none'; |
||
| 357 | } |
||
| 358 | if($div_display == 'none'){ |
||
| 359 | $opp_display = 'inline'; |
||
| 360 | }else{ |
||
| 361 | $opp_display = 'none'; |
||
| 362 | } |
||
| 363 | |||
| 364 | if (!empty($this->layout_def_key) ) { |
||
| 365 | $layout_def_key = $this->layout_def_key; |
||
| 366 | } else { |
||
| 367 | $layout_def_key = ''; |
||
| 368 | } |
||
| 369 | |||
| 370 | if (empty($this->show_tabs)) |
||
| 371 | { |
||
| 372 | $show_icon_html = SugarThemeRegistry::current()->getImage( 'advanced_search', 'border="0" align="absmiddle"',null,null,'.gif',translate('LBL_SHOW')); |
||
| 373 | $hide_icon_html = SugarThemeRegistry::current()->getImage( 'basic_search', 'border="0" align="absmiddle"',null,null,'.gif',translate('LBL_HIDE')); |
||
| 374 | |||
| 375 | $max_min = "<a name=\"$tab\"> </a><span id=\"show_link_".$tab."\" style=\"display: $opp_display\"><a href='#' class='utilsLink' onclick=\"current_child_field = '".$tab."';showSubPanel('".$tab."',null,null,'".$layout_def_key."');document.getElementById('show_link_".$tab."').style.display='none';document.getElementById('hide_link_".$tab."').style.display='';return false;\">" |
||
| 376 | . "" . $show_icon_html . "</a></span>"; |
||
| 377 | $max_min .= "<span id=\"hide_link_".$tab."\" style=\"display: $div_display\"><a href='#' class='utilsLink' onclick=\"hideSubPanel('".$tab."');document.getElementById('hide_link_".$tab."').style.display='none';document.getElementById('show_link_".$tab."').style.display='';return false;\">" |
||
| 378 | . "" . $hide_icon_html . "</a></span>"; |
||
| 379 | echo '<div id="subpanel_title_' . $tab . '"'; |
||
| 380 | if(empty($sugar_config['lock_subpanels']) || $sugar_config['lock_subpanels'] == false) echo ' onmouseover="this.style.cursor = \'move\';"'; |
||
| 381 | echo '>' . get_form_header( $thisPanel->get_title(), $max_min, false) . '</div>'; |
||
| 382 | } |
||
| 383 | |||
| 384 | echo <<<EOQ |
||
| 385 | <div cookie_name="$cookie_name" id="subpanel_$tab" style="display:$div_display"> |
||
| 386 | <script>document.getElementById("subpanel_$tab" ).cookie_name="$cookie_name";</script> |
||
| 387 | EOQ; |
||
| 388 | $display_spd = ''; |
||
| 389 | if($div_display != 'none'){ |
||
| 390 | echo "<script>SUGAR.util.doWhen(\"typeof(markSubPanelLoaded) != 'undefined'\", function() {markSubPanelLoaded('$tab');});</script>"; |
||
| 391 | $old_contents = ob_get_contents(); |
||
| 392 | @ob_end_clean(); |
||
| 393 | |||
| 394 | ob_start(); |
||
| 395 | include_once('include/SubPanel/SubPanel.php'); |
||
| 396 | $subpanel_object = new SubPanel($this->module, $_REQUEST['record'], $tab,$thisPanel,$layout_def_key); |
||
| 397 | $subpanel_object->setTemplateFile('include/SubPanel/SubPanelDynamic.html'); |
||
| 398 | $subpanel_object->display(); |
||
| 399 | $subpanel_data = ob_get_contents(); |
||
| 400 | @ob_end_clean(); |
||
| 401 | |||
| 402 | ob_start(); |
||
| 403 | echo $this->get_buttons($thisPanel,$subpanel_object->subpanel_query); |
||
| 404 | $buttons = ob_get_contents(); |
||
| 405 | @ob_end_clean(); |
||
| 406 | |||
| 407 | ob_start(); |
||
| 408 | echo $old_contents; |
||
| 409 | //echo $buttons; |
||
| 410 | $display_spd = $subpanel_data; |
||
| 411 | } |
||
| 412 | echo <<<EOQ |
||
| 413 | <div id="list_subpanel_$tab">$display_spd</div> |
||
| 414 | </div> |
||
| 415 | EOQ; |
||
| 416 | array_push($tab_names, $tab); |
||
| 417 | echo '</li>'; |
||
| 418 | } // end $tabs foreach |
||
| 419 | if($showContainer) |
||
| 420 | { |
||
| 421 | echo '</ul>'; |
||
| 422 | |||
| 423 | |||
| 424 | if(!empty($selected_group)) |
||
| 425 | { |
||
| 426 | // closing table from tpls/singletabmenu.tpl |
||
| 427 | echo '</td></tr></table>'; |
||
| 428 | } |
||
| 429 | } |
||
| 430 | // drag/drop code |
||
| 431 | $tab_names = '["' . join($tab_names, '","') . '"]'; |
||
| 432 | global $sugar_config; |
||
| 433 | |||
| 434 | if(empty($sugar_config['lock_subpanels']) || $sugar_config['lock_subpanels'] == false) { |
||
| 435 | echo <<<EOQ |
||
| 436 | <script> |
||
| 437 | var SubpanelInit = function() { |
||
| 438 | SubpanelInitTabNames({$tab_names}); |
||
| 439 | } |
||
| 440 | var SubpanelInitTabNames = function(tabNames) { |
||
| 441 | subpanel_dd = new Array(); |
||
| 442 | j = 0; |
||
| 443 | for(i in tabNames) { |
||
| 444 | subpanel_dd[j] = new ygDDList('whole_subpanel_' + tabNames[i]); |
||
| 445 | subpanel_dd[j].setHandleElId('subpanel_title_' + tabNames[i]); |
||
| 446 | subpanel_dd[j].onMouseDown = SUGAR.subpanelUtils.onDrag; |
||
| 447 | subpanel_dd[j].afterEndDrag = SUGAR.subpanelUtils.onDrop; |
||
| 448 | j++; |
||
| 449 | } |
||
| 450 | |||
| 451 | YAHOO.util.DDM.mode = 1; |
||
| 452 | } |
||
| 453 | currentModule = '{$this->module}'; |
||
| 454 | SUGAR.util.doWhen( |
||
| 455 | "typeof(SUGAR.subpanelUtils) == 'object' && typeof(SUGAR.subpanelUtils.onDrag) == 'function'" + |
||
| 456 | " && document.getElementById('subpanel_list')", |
||
| 457 | SubpanelInit |
||
| 458 | ); |
||
| 459 | </script> |
||
| 460 | EOQ; |
||
| 461 | } |
||
| 462 | |||
| 463 | $module_sub_panels = array_map('array_keys', $module_sub_panels); |
||
| 464 | $module_sub_panels = json_encode($module_sub_panels); |
||
| 465 | echo <<<EOQ |
||
| 466 | <script> |
||
| 467 | var ModuleSubPanels = $module_sub_panels; |
||
| 468 | </script> |
||
| 469 | EOQ; |
||
| 470 | |||
| 471 | $ob_contents = ob_get_contents(); |
||
| 472 | ob_end_clean(); |
||
| 473 | return $ob_contents; |
||
| 474 | } |
||
| 475 | |||
| 526 |
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.