| Conditions | 68 |
| Paths | 3936 |
| Total Lines | 204 |
| Code Lines | 131 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 335 | public function createQuickSearchCode($defs, $defs2, $view = '', $module='') |
||
| 336 | { |
||
| 337 | $sqs_objects = array(); |
||
| 338 | require_once('include/QuickSearchDefaults.php'); |
||
| 339 | if(isset($this) && $this instanceof TemplateHandler) //If someone calls createQuickSearchCode as a static method (@see ImportViewStep3) $this becomes anoter object, not TemplateHandler |
||
| 340 | { |
||
| 341 | $qsd = QuickSearchDefaults::getQuickSearchDefaults($this->getQSDLookup()); |
||
| 342 | }else |
||
| 343 | { |
||
| 344 | $qsd = QuickSearchDefaults::getQuickSearchDefaults(array()); |
||
| 345 | } |
||
| 346 | $qsd->setFormName($view); |
||
| 347 | if(preg_match('/^SearchForm_.+/', $view)){ |
||
| 348 | if(strpos($view, 'popup_query_form')){ |
||
| 349 | $qsd->setFormName('popup_query_form'); |
||
| 350 | $parsedView = 'advanced'; |
||
| 351 | }else{ |
||
| 352 | $qsd->setFormName('search_form'); |
||
| 353 | $parsedView = preg_replace("/^SearchForm_/", "", $view); |
||
| 354 | } |
||
| 355 | //Loop through the Meta-Data fields to see which ones need quick search support |
||
| 356 | foreach($defs as $f) { |
||
| 357 | $field = $f; |
||
| 358 | $name = $qsd->form_name . '_' . $field['name']; |
||
| 359 | |||
| 360 | if($field['type'] == 'relate' && isset($field['module']) && preg_match('/_name$|_c$/si',$name) || !empty($field['quicksearch']) ) { |
||
| 361 | if(preg_match('/^(Campaigns|Teams|Users|Contacts|Accounts)$/si', $field['module'], $matches)) { |
||
| 362 | |||
| 363 | if($matches[0] == 'Campaigns') { |
||
| 364 | $sqs_objects[$name.'_'.$parsedView] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
||
| 365 | } else if($matches[0] == 'Users'){ |
||
| 366 | |||
| 367 | if(!empty($f['name']) && !empty($f['id_name'])) { |
||
| 368 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser($f['name'],$f['id_name']); |
||
| 369 | } |
||
| 370 | else { |
||
| 371 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSUser(); |
||
| 372 | } |
||
| 373 | } else if($matches[0] == 'Campaigns') { |
||
| 374 | $sqs_objects[$name.'_'.$parsedView] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
||
| 375 | } else if($matches[0] == 'Accounts') { |
||
| 376 | $nameKey = $name; |
||
| 377 | $idKey = isset($field['id_name']) ? $field['id_name'] : 'account_id'; |
||
| 378 | |||
| 379 | //There are billingKey, shippingKey and additionalFields entries you can define in editviewdefs.php |
||
| 380 | //entry to allow quick search to autocomplete fields with a suffix value of the |
||
| 381 | //billing/shippingKey value (i.e. 'billingKey' => 'primary' in Contacts will populate |
||
| 382 | //primary_XXX fields with the Account's billing address values). |
||
| 383 | //addtionalFields are key/value pair of fields to fill from Accounts(key) to Contacts(value) |
||
| 384 | $billingKey = isset($f['displayParams']['billingKey']) ? $f['displayParams']['billingKey'] : null; |
||
| 385 | $shippingKey = isset($f['displayParams']['shippingKey']) ? $f['displayParams']['shippingKey'] : null; |
||
| 386 | $additionalFields = isset($f['displayParams']['additionalFields']) ? $f['displayParams']['additionalFields'] : null; |
||
| 387 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSAccount($nameKey, $idKey, $billingKey, $shippingKey, $additionalFields); |
||
| 388 | } else if($matches[0] == 'Contacts'){ |
||
| 389 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSContact($field['name'], $field['id_name']); |
||
| 390 | } |
||
| 391 | } else { |
||
| 392 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent($field['module']); |
||
| 393 | if(!isset($field['field_list']) && !isset($field['populate_list'])) { |
||
| 394 | $sqs_objects[$name.'_'.$parsedView]['populate_list'] = array($field['name'], $field['id_name']); |
||
| 395 | $sqs_objects[$name.'_'.$parsedView]['field_list'] = array('name', 'id'); |
||
| 396 | } else { |
||
| 397 | $sqs_objects[$name.'_'.$parsedView]['populate_list'] = $field['field_list']; |
||
| 398 | $sqs_objects[$name.'_'.$parsedView]['field_list'] = $field['populate_list']; |
||
| 399 | } |
||
| 400 | } |
||
| 401 | } else if($field['type'] == 'parent') { |
||
| 402 | $sqs_objects[$name.'_'.$parsedView] = $qsd->getQSParent(); |
||
| 403 | } //if-else |
||
| 404 | } //foreach |
||
| 405 | |||
| 406 | foreach ( $sqs_objects as $name => $field ) |
||
| 407 | foreach ( $field['populate_list'] as $key => $fieldname ) |
||
| 408 | $sqs_objects[$name]['populate_list'][$key] = $sqs_objects[$name]['populate_list'][$key] . '_'.$parsedView; |
||
| 409 | }else{ |
||
| 410 | //Loop through the Meta-Data fields to see which ones need quick search support |
||
| 411 | foreach($defs2 as $f) { |
||
| 412 | if(!isset($defs[$f['name']])) continue; |
||
| 413 | |||
| 414 | $field = $defs[$f['name']]; |
||
| 415 | if ($view == "ConvertLead") |
||
| 416 | { |
||
| 417 | $field['name'] = $module . $field['name']; |
||
| 418 | if (isset($field['module']) && isset($field['id_name']) && substr($field['id_name'], -4) == "_ida") { |
||
| 419 | $lc_module = strtolower($field['module']); |
||
| 420 | $ida_suffix = "_".$lc_module.$lc_module."_ida"; |
||
| 421 | if (preg_match('/'.$ida_suffix.'$/', $field['id_name']) > 0) { |
||
| 422 | $field['id_name'] = $module . $field['id_name']; |
||
| 423 | } |
||
| 424 | else |
||
| 425 | $field['id_name'] = $field['name'] . "_" . $field['id_name']; |
||
| 426 | } |
||
| 427 | else { |
||
| 428 | if (!empty($field['id_name'])) |
||
| 429 | $field['id_name'] = $module.$field['id_name']; |
||
| 430 | } |
||
| 431 | } |
||
| 432 | $name = $qsd->form_name . '_' . $field['name']; |
||
| 433 | |||
| 434 | |||
| 435 | if($field['type'] == 'relate' && isset($field['module']) && (preg_match('/_name$|_c$/si',$name) || !empty($field['quicksearch']))) { |
||
| 436 | if (!preg_match('/_c$/si',$name) |
||
| 437 | && (!isset($field['id_name']) || !preg_match('/_c$/si',$field['id_name'])) |
||
| 438 | && preg_match('/^(Campaigns|Teams|Users|Contacts|Accounts)$/si', $field['module'], $matches) |
||
| 439 | ) { |
||
| 440 | |||
| 441 | if($matches[0] == 'Campaigns') { |
||
| 442 | $sqs_objects[$name] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
||
| 443 | } else if($matches[0] == 'Users'){ |
||
| 444 | if($field['name'] == 'reports_to_name'){ |
||
| 445 | $sqs_objects[$name] = $qsd->getQSUser('reports_to_name','reports_to_id'); |
||
| 446 | // Bug #52994 : QuickSearch for a 1-M User relationship changes assigned to user |
||
| 447 | }elseif($field['name'] == 'assigned_user_name'){ |
||
| 448 | $sqs_objects[$name] = $qsd->getQSUser('assigned_user_name','assigned_user_id'); |
||
| 449 | } |
||
| 450 | else |
||
| 451 | { |
||
| 452 | $sqs_objects[$name] = $qsd->getQSUser($field['name'], $field['id_name']); |
||
| 453 | |||
| 454 | } |
||
| 455 | } else if($matches[0] == 'Campaigns') { |
||
| 456 | $sqs_objects[$name] = $qsd->loadQSObject('Campaigns', 'Campaign', $field['name'], $field['id_name'], $field['id_name']); |
||
| 457 | } else if($matches[0] == 'Accounts') { |
||
| 458 | $nameKey = $name; |
||
| 459 | $idKey = isset($field['id_name']) ? $field['id_name'] : 'account_id'; |
||
| 460 | |||
| 461 | //There are billingKey, shippingKey and additionalFields entries you can define in editviewdefs.php |
||
| 462 | //entry to allow quick search to autocomplete fields with a suffix value of the |
||
| 463 | //billing/shippingKey value (i.e. 'billingKey' => 'primary' in Contacts will populate |
||
| 464 | //primary_XXX fields with the Account's billing address values). |
||
| 465 | //addtionalFields are key/value pair of fields to fill from Accounts(key) to Contacts(value) |
||
| 466 | $billingKey = SugarArray::staticGet($f, 'displayParams.billingKey'); |
||
| 467 | $shippingKey = SugarArray::staticGet($f, 'displayParams.shippingKey'); |
||
| 468 | $additionalFields = SugarArray::staticGet($f, 'displayParams.additionalFields'); |
||
| 469 | $sqs_objects[$name] = $qsd->getQSAccount($nameKey, $idKey, $billingKey, $shippingKey, $additionalFields); |
||
| 470 | } else if($matches[0] == 'Contacts'){ |
||
| 471 | $sqs_objects[$name] = $qsd->getQSContact($field['name'], $field['id_name']); |
||
| 472 | if(preg_match('/_c$/si',$name) || !empty($field['quicksearch'])){ |
||
| 473 | $sqs_objects[$name]['field_list'] = array('salutation', 'first_name', 'last_name', 'id'); |
||
| 474 | } |
||
| 475 | } |
||
| 476 | } else { |
||
| 477 | $sqs_objects[$name] = $qsd->getQSParent($field['module']); |
||
| 478 | if(!isset($field['field_list']) && !isset($field['populate_list'])) { |
||
| 479 | $sqs_objects[$name]['populate_list'] = array($field['name'], $field['id_name']); |
||
| 480 | // now handle quicksearches where the column to match is not 'name' but rather specified in 'rname' |
||
| 481 | if (!isset($field['rname'])) |
||
| 482 | $sqs_objects[$name]['field_list'] = array('name', 'id'); |
||
| 483 | else |
||
| 484 | { |
||
| 485 | $sqs_objects[$name]['field_list'] = array($field['rname'], 'id'); |
||
| 486 | $sqs_objects[$name]['order'] = $field['rname']; |
||
| 487 | $sqs_objects[$name]['conditions'] = array(array('name'=>$field['rname'],'op'=>'like_custom','end'=>'%','value'=>'')); |
||
| 488 | } |
||
| 489 | } else { |
||
| 490 | $sqs_objects[$name]['populate_list'] = $field['field_list']; |
||
| 491 | $sqs_objects[$name]['field_list'] = $field['populate_list']; |
||
| 492 | } |
||
| 493 | } |
||
| 494 | } else if($field['type'] == 'parent') { |
||
| 495 | $sqs_objects[$name] = $qsd->getQSParent(); |
||
| 496 | } //if-else |
||
| 497 | |||
| 498 | // Bug 53949 - Captivea (sve) - Partial fix : Append metadata fields that are not already included in $sqs_objects array |
||
| 499 | // (for example with hardcoded modules before, metadata arrays are not taken into account in 6.4.x 6.5.x) |
||
| 500 | // As QuickSearchDefault methods are called at other places, this will not fix the SQS problem for everywhere, but it fixes it on Editview |
||
| 501 | |||
| 502 | //merge populate_list && field_list with vardef |
||
| 503 | if (!empty($field['field_list']) && !empty($field['populate_list'])) { |
||
| 504 | for ($j=0; $j<count($field['field_list']); $j++) { |
||
| 505 | //search for the same couple (field_list_item,populate_field_item) |
||
| 506 | $field_list_item = $field['field_list'][$j]; |
||
| 507 | $field_list_item_alternate = $qsd->form_name . '_' . $field['field_list'][$j]; |
||
| 508 | $populate_list_item = $field['populate_list'][$j]; |
||
| 509 | $found = false; |
||
| 510 | for ($k=0; $k<count($sqs_objects[$name]['field_list']); $k++) { |
||
| 511 | if (($field_list_item == $sqs_objects[$name]['populate_list'][$k] || $field_list_item_alternate == $sqs_objects[$name]['populate_list'][$k]) && //il faut inverser field_list et populate_list (cf lignes 465,466 ci-dessus) |
||
| 512 | $populate_list_item == $sqs_objects[$name]['field_list'][$k]) { |
||
| 513 | $found = true; |
||
| 514 | break; |
||
| 515 | } |
||
| 516 | } |
||
| 517 | if (!$found) { |
||
| 518 | $sqs_objects[$name]['field_list'][] = $field['populate_list'][$j]; // as in lines 462 and 463 |
||
| 519 | $sqs_objects[$name]['populate_list'][] = $field['field_list'][$j]; |
||
| 520 | } |
||
| 521 | } |
||
| 522 | } |
||
| 523 | |||
| 524 | } //foreach |
||
| 525 | } |
||
| 526 | |||
| 527 | //Implement QuickSearch for the field |
||
| 528 | if(!empty($sqs_objects) && count($sqs_objects) > 0) { |
||
| 529 | $quicksearch_js = '<script language="javascript">'; |
||
| 530 | $quicksearch_js.= 'if(typeof sqs_objects == \'undefined\'){var sqs_objects = new Array;}'; |
||
| 531 | $json = getJSONobj(); |
||
| 532 | foreach($sqs_objects as $sqsfield=>$sqsfieldArray){ |
||
| 533 | $quicksearch_js .= "sqs_objects['$sqsfield']={$json->encode($sqsfieldArray)};"; |
||
| 534 | } |
||
| 535 | return $quicksearch_js . '</script>'; |
||
| 536 | } |
||
| 537 | return ''; |
||
| 538 | } |
||
| 539 | |||
| 552 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.