Conditions | 105 |
Paths | > 20000 |
Total Lines | 362 |
Code Lines | 222 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
328 | function print_left_auguria_menu($db, $menu_array_before, $menu_array_after, &$tabMenu, &$menu, $noout = 0, $forcemainmenu = '', $forceleftmenu = '', $moredata = null, $type_user = 0) |
||
329 | { |
||
330 | global $user, $conf, $langs, $hookmanager; |
||
331 | global $dolibarr_main_db_name, $mysoc; |
||
332 | |||
333 | $newmenu = $menu; |
||
334 | |||
335 | $mainmenu = ($forcemainmenu ? $forcemainmenu : $_SESSION["mainmenu"]); |
||
336 | $leftmenu = ($forceleftmenu ? '' : (empty($_SESSION["leftmenu"]) ? 'none' : $_SESSION["leftmenu"])); |
||
337 | |||
338 | global $usemenuhider; |
||
339 | $usemenuhider = 0; |
||
340 | |||
341 | if (is_array($moredata) && !empty($moredata['searchform'])) { // searchform can contains select2 code or link to show old search form or link to switch on search page |
||
342 | print "\n"; |
||
343 | print "<!-- Begin SearchForm -->\n"; |
||
344 | print '<div id="blockvmenusearch" class="blockvmenusearch">' . "\n"; |
||
345 | print $moredata['searchform']; |
||
346 | print '</div>' . "\n"; |
||
347 | print "<!-- End SearchForm -->\n"; |
||
348 | } |
||
349 | |||
350 | if (is_array($moredata) && !empty($moredata['bookmarks'])) { |
||
351 | print "\n"; |
||
352 | print "<!-- Begin Bookmarks -->\n"; |
||
353 | print '<div id="blockvmenubookmarks" class="blockvmenubookmarks">' . "\n"; |
||
354 | print $moredata['bookmarks']; |
||
355 | print '</div>' . "\n"; |
||
356 | print "<!-- End Bookmarks -->\n"; |
||
357 | } |
||
358 | |||
359 | $substitarray = getCommonSubstitutionArray($langs, 0, null, null); |
||
360 | |||
361 | // We update newmenu with entries found into database |
||
362 | $menuArbo = new Menubase($db, 'auguria'); |
||
363 | $newmenu = $menuArbo->menuLeftCharger($newmenu, $mainmenu, $leftmenu, ($user->socid ? 1 : 0), 'auguria', $tabMenu); |
||
364 | |||
365 | // We update newmenu for special dynamic menus |
||
366 | if (isModEnabled('bank') && $user->hasRight('banque', 'lire') && $mainmenu == 'bank') { // Entry for each bank account |
||
367 | include_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; // Required for to get Account::TYPE_CASH for example |
||
368 | |||
369 | $sql = "SELECT rowid, label, courant, rappro, courant"; |
||
370 | $sql .= " FROM " . MAIN_DB_PREFIX . "bank_account"; |
||
371 | $sql .= " WHERE entity = " . $conf->entity; |
||
372 | $sql .= " AND clos = 0"; |
||
373 | $sql .= " ORDER BY label"; |
||
374 | |||
375 | $resql = $db->query($sql); |
||
376 | if ($resql) { |
||
377 | $numr = $db->num_rows($resql); |
||
378 | $i = 0; |
||
379 | |||
380 | if ($numr > 0) { |
||
381 | $newmenu->add('/compta/bank/list.php?search_status=opened', $langs->trans("BankAccounts"), 0, $user->hasRight('banque', 'lire')); |
||
382 | } |
||
383 | |||
384 | while ($i < $numr) { |
||
385 | $objp = $db->fetch_object($resql); |
||
386 | $newmenu->add('/compta/bank/card.php?id=' . $objp->rowid, $objp->label, 1, $user->hasRight('banque', 'lire')); |
||
387 | if ($objp->rappro && $objp->courant != Account::TYPE_CASH && empty($objp->clos)) { // If not cash account and not closed and can be reconciliate |
||
388 | $newmenu->add('/compta/bank/bankentries_list.php?id=' . $objp->rowid, $langs->trans("Conciliate"), 2, $user->hasRight('banque', 'consolidate')); |
||
389 | } |
||
390 | $i++; |
||
391 | } |
||
392 | } else { |
||
393 | dol_print_error($db); |
||
394 | } |
||
395 | $db->free($resql); |
||
396 | } |
||
397 | |||
398 | if (isModEnabled('accounting') && $user->hasRight('accounting', 'comptarapport', 'lire') && $mainmenu == 'accountancy') { // Entry in accountancy journal for each bank account |
||
399 | $newmenu->add('', $langs->trans("RegistrationInAccounting"), 1, $user->hasRight('accounting', 'comptarapport', 'lire'), '', 'accountancy', 'accountancy_journal', 10); |
||
400 | |||
401 | // Multi journal |
||
402 | $sql = "SELECT rowid, code, label, nature"; |
||
403 | $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_journal"; |
||
404 | $sql .= " WHERE entity = " . $conf->entity; |
||
405 | $sql .= " AND active = 1"; |
||
406 | $sql .= " ORDER BY label DESC"; |
||
407 | |||
408 | $resql = $db->query($sql); |
||
409 | if ($resql) { |
||
410 | $numr = $db->num_rows($resql); |
||
411 | $i = 0; |
||
412 | |||
413 | if ($numr > 0) { |
||
414 | while ($i < $numr) { |
||
415 | $objp = $db->fetch_object($resql); |
||
416 | |||
417 | $nature = ''; |
||
418 | |||
419 | // Must match array $sourceList defined into journals_list.php |
||
420 | if ($objp->nature == 2 && isModEnabled('invoice') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_SALES')) { |
||
421 | $nature = "sells"; |
||
422 | } |
||
423 | if ( |
||
424 | $objp->nature == 3 |
||
425 | && isModEnabled('supplier_invoice') |
||
426 | && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_PURCHASES') |
||
427 | ) { |
||
428 | $nature = "purchases"; |
||
429 | } |
||
430 | if ($objp->nature == 4 && isModEnabled('bank')) { |
||
431 | $nature = "bank"; |
||
432 | } |
||
433 | if ($objp->nature == 5 && isModEnabled('expensereport') && !getDolGlobalString('ACCOUNTING_DISABLE_BINDING_ON_EXPENSEREPORTS')) { |
||
434 | $nature = "expensereports"; |
||
435 | } |
||
436 | if ($objp->nature == 1) { |
||
437 | $nature = "various"; |
||
438 | } |
||
439 | if ($objp->nature == 8) { |
||
440 | $nature = "inventory"; |
||
441 | } |
||
442 | if ($objp->nature == 9) { |
||
443 | $nature = "hasnew"; |
||
444 | } |
||
445 | |||
446 | // To enable when page exists |
||
447 | if (!getDolGlobalString('ACCOUNTANCY_SHOW_DEVELOP_JOURNAL')) { |
||
448 | if ($nature == 'hasnew' || $nature == 'inventory') { |
||
449 | $nature = ''; |
||
450 | } |
||
451 | } |
||
452 | |||
453 | if ($nature) { |
||
454 | $langs->load('accountancy'); |
||
455 | $journallabel = $langs->transnoentities($objp->label); // Labels in this table are set by loading llx_accounting_abc.sql. Label can be 'ACCOUNTING_SELL_JOURNAL', 'InventoryJournal', ... |
||
456 | $newmenu->add('/accountancy/journal/' . $nature . 'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal=' . $objp->rowid, $journallabel, 2, $user->hasRight('accounting', 'comptarapport', 'lire')); |
||
457 | } |
||
458 | $i++; |
||
459 | } |
||
460 | } else { |
||
461 | // Should not happen. Entries are added |
||
462 | $newmenu->add('', $langs->trans("NoJournalDefined"), 2, $user->hasRight('accounting', 'comptarapport', 'lire')); |
||
463 | } |
||
464 | } else { |
||
465 | dol_print_error($db); |
||
466 | } |
||
467 | $db->free($resql); |
||
468 | } |
||
469 | |||
470 | if (isModEnabled('ftp') && $mainmenu == 'ftp') { // Entry for FTP |
||
471 | $MAXFTP = 20; |
||
472 | $i = 1; |
||
473 | while ($i <= $MAXFTP) { |
||
474 | $paramkey = 'FTP_NAME_' . $i; |
||
475 | //print $paramkey; |
||
476 | if (!empty($conf->global->$paramkey)) { |
||
477 | $link = "/ftp/index.php?idmenu=" . $_SESSION["idmenu"] . "&numero_ftp=" . $i; |
||
478 | |||
479 | $newmenu->add($link, dol_trunc($conf->global->$paramkey, 24)); |
||
480 | } |
||
481 | $i++; |
||
482 | } |
||
483 | } |
||
484 | |||
485 | |||
486 | // Build final $menu_array = $menu_array_before +$newmenu->liste + $menu_array_after |
||
487 | //var_dump($menu_array_before);exit; |
||
488 | //var_dump($menu_array_after);exit; |
||
489 | $menu_array = $newmenu->liste; |
||
490 | if (is_array($menu_array_before)) { |
||
491 | $menu_array = array_merge($menu_array_before, $menu_array); |
||
492 | } |
||
493 | if (is_array($menu_array_after)) { |
||
494 | $menu_array = array_merge($menu_array, $menu_array_after); |
||
495 | } |
||
496 | //var_dump($menu_array);exit; |
||
497 | if (!is_array($menu_array)) { |
||
498 | return 0; |
||
499 | } |
||
500 | |||
501 | // Allow the $menu_array of the menu to be manipulated by modules |
||
502 | $parameters = array( |
||
503 | 'mainmenu' => $mainmenu, |
||
504 | ); |
||
505 | $hook_items = $menu_array; |
||
506 | $reshook = $hookmanager->executeHooks('menuLeftMenuItems', $parameters, $hook_items); // Note that $action and $object may have been modified by some hooks |
||
507 | |||
508 | if (is_numeric($reshook)) { |
||
509 | if ($reshook == 0 && !empty($hookmanager->results)) { |
||
510 | $menu_array[] = $hookmanager->results; // add |
||
511 | } elseif ($reshook == 1) { |
||
512 | $menu_array = $hookmanager->results; // replace |
||
513 | } |
||
514 | |||
515 | // @todo Sort menu items by 'position' value |
||
516 | // $position = array(); |
||
517 | // foreach ($menu_array as $key => $row) { |
||
518 | // $position[$key] = $row['position']; |
||
519 | // } |
||
520 | // $array1_sort_order = SORT_ASC; |
||
521 | // array_multisort($position, $array1_sort_order, $menu_array); |
||
522 | } |
||
523 | |||
524 | // Phan has a hard time tracking the type, for instance because it get hookmanager->results |
||
525 | // Force the typing at this point to get useful analysis below: |
||
526 | '@phan-var-force array<array{rowid:string,fk_menu:string,langs:string,enabled:int<0,2>,type:string,fk_mainmenu:string,fk_leftmenu:string,url:string,titre:string,perms:string,target:string,mainmenu:string,leftmenu:string,position:int,prefix:string,level:int}> $menu_array'; |
||
527 | |||
528 | // Show menu |
||
529 | $invert = !getDolGlobalString('MAIN_MENU_INVERT') ? "" : "invert"; |
||
530 | if (empty($noout)) { |
||
531 | $altok = 0; |
||
532 | $blockvmenuopened = false; |
||
533 | $lastlevel0 = ''; |
||
534 | $num = count($menu_array); |
||
535 | foreach (array_keys($menu_array) as $i) { // Loop on each menu entry (foreach better for static analysis) |
||
536 | $showmenu = true; |
||
537 | if (getDolGlobalString('MAIN_MENU_HIDE_UNAUTHORIZED') && empty($menu_array[$i]['enabled'])) { |
||
538 | $showmenu = false; |
||
539 | } |
||
540 | |||
541 | // Begin of new left menu block |
||
542 | if (empty($menu_array[$i]['level']) && $showmenu) { |
||
543 | $altok++; |
||
544 | $blockvmenuopened = true; |
||
545 | $lastopened = true; |
||
546 | for ($j = ($i + 1); $j < $num; $j++) { |
||
547 | if (empty($menu_array[$j]['level'])) { |
||
548 | $lastopened = false; |
||
549 | } |
||
550 | } |
||
551 | if ($altok % 2 == 0) { |
||
552 | print '<div class="blockvmenu blockvmenuimpair' . $invert . ($lastopened ? ' blockvmenulast' : '') . ($altok == 1 ? ' blockvmenufirst' : '') . '">' . "\n"; |
||
553 | } else { |
||
554 | print '<div class="blockvmenu blockvmenupair' . $invert . ($lastopened ? ' blockvmenulast' : '') . ($altok == 1 ? ' blockvmenufirst' : '') . '">' . "\n"; |
||
555 | } |
||
556 | } |
||
557 | |||
558 | // Add tabulation |
||
559 | $tabstring = ''; |
||
560 | $tabul = ($menu_array[$i]['level'] - 1); |
||
561 | if ($tabul > 0) { |
||
562 | for ($j = 0; $j < $tabul; $j++) { |
||
563 | $tabstring .= ' '; |
||
564 | } |
||
565 | } |
||
566 | |||
567 | // $menu_array[$i]['url'] can be a relative url, a full external url. We try substitution |
||
568 | |||
569 | $menu_array[$i]['url'] = make_substitutions($menu_array[$i]['url'], $substitarray); |
||
570 | |||
571 | $url = $shorturl = $shorturlwithoutparam = $menu_array[$i]['url']; |
||
572 | if (!preg_match("/^(http:\/\/|https:\/\/)/i", $menu_array[$i]['url'])) { |
||
573 | $tmp = explode('?', $menu_array[$i]['url'], 2); |
||
574 | $url = $shorturl = $tmp[0]; |
||
575 | $param = (isset($tmp[1]) ? $tmp[1] : ''); // params in url of the menu link |
||
576 | |||
577 | // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined. |
||
578 | if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && !empty($menu_array[$i]['mainmenu'])) { |
||
579 | $param .= ($param ? '&' : '') . 'mainmenu=' . $menu_array[$i]['mainmenu'] . '&leftmenu='; |
||
580 | } |
||
581 | if ((!preg_match('/mainmenu/i', $param)) && (!preg_match('/leftmenu/i', $param)) && empty($menu_array[$i]['mainmenu'])) { |
||
582 | $param .= ($param ? '&' : '') . 'leftmenu='; |
||
583 | } |
||
584 | //$url.="idmenu=".$menu_array[$i]['rowid']; // Already done by menuLoad |
||
585 | $url = dol_buildpath($url, 3) . ($param ? '?' . $param : ''); |
||
586 | $shorturlwithoutparam = $shorturl; |
||
587 | $shorturl = $shorturl . ($param ? '?' . $param : ''); |
||
588 | } |
||
589 | |||
590 | print '<!-- Process menu entry with mainmenu=' . $menu_array[$i]['mainmenu'] . ', leftmenu=' . $menu_array[$i]['leftmenu'] . ', level=' . $menu_array[$i]['level'] . ' enabled=' . $menu_array[$i]['enabled'] . ', position=' . $menu_array[$i]['position'] . ' prefix=' . $menu_array[$i]['prefix'] . ' -->' . "\n"; |
||
591 | |||
592 | // Menu level 0 |
||
593 | if ($menu_array[$i]['level'] == 0) { |
||
594 | if ($menu_array[$i]['enabled']) { // Enabled so visible |
||
595 | print '<div class="menu_titre">' . $tabstring; |
||
596 | if ($shorturlwithoutparam) { |
||
597 | print '<a class="vmenu" title="' . dol_escape_htmltag(dol_string_nohtmltag($menu_array[$i]['titre'])) . '" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>'; |
||
598 | } else { |
||
599 | print '<span class="vmenu">'; |
||
600 | } |
||
601 | if (!empty($menu_array[$i]['prefix'])) { |
||
602 | if (preg_match('/^fa\-[a-zA-Z0-9\-_]+$/', $menu_array[$i]['prefix'])) { |
||
603 | print '<span class="fas ' . $menu_array[$i]['prefix'] . ' paddingright pictofixedwidth"></span>'; |
||
604 | } else { |
||
605 | print $menu_array[$i]['prefix']; |
||
606 | } |
||
607 | } |
||
608 | |||
609 | // print ($menu_array[$i]['prefix'] ? $menu_array[$i]['prefix'] : ''); |
||
610 | print $menu_array[$i]['titre']; |
||
611 | if ($shorturlwithoutparam) { |
||
612 | print '</a>'; |
||
613 | } else { |
||
614 | print '</span>'; |
||
615 | } |
||
616 | print '</div>' . "\n"; |
||
617 | $lastlevel0 = 'enabled'; |
||
618 | } elseif ($showmenu) { // Not enabled but visible (so greyed) |
||
619 | print '<div class="menu_titre">' . $tabstring; |
||
620 | print '<span class="vmenudisabled">'; |
||
621 | if (!empty($menu_array[$i]['prefix'])) { |
||
622 | print $menu_array[$i]['prefix']; |
||
623 | } |
||
624 | print $menu_array[$i]['titre']; |
||
625 | print '</span>'; |
||
626 | print '</div>' . "\n"; |
||
627 | $lastlevel0 = 'greyed'; |
||
628 | } else { |
||
629 | $lastlevel0 = 'hidden'; |
||
630 | } |
||
631 | if ($showmenu) { |
||
632 | print '<div class="menu_top"></div>' . "\n"; |
||
633 | } |
||
634 | } |
||
635 | |||
636 | // Menu level > 0 |
||
637 | if ($menu_array[$i]['level'] > 0) { |
||
638 | $cssmenu = ''; |
||
639 | if ($menu_array[$i]['url']) { |
||
640 | $cssmenu = ' menu_contenu' . dol_string_nospecial(preg_replace('/\.php.*$/', '', $menu_array[$i]['url'])); |
||
641 | } |
||
642 | |||
643 | if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') { |
||
644 | // Enabled so visible, except if parent was not enabled. |
||
645 | print '<div class="menu_contenu' . $cssmenu . '">'; |
||
646 | print $tabstring; |
||
647 | if ($shorturlwithoutparam) { |
||
648 | print '<a class="vsmenu" title="' . dol_escape_htmltag(dol_string_nohtmltag($menu_array[$i]['titre'])) . '" href="' . $url . '"' . ($menu_array[$i]['target'] ? ' target="' . $menu_array[$i]['target'] . '"' : '') . '>'; |
||
649 | } else { |
||
650 | print '<span class="vsmenu" title="' . dol_escape_htmltag($menu_array[$i]['titre']) . '">'; |
||
651 | } |
||
652 | print $menu_array[$i]['titre']; |
||
653 | if ($shorturlwithoutparam) { |
||
654 | print '</a>'; |
||
655 | } else { |
||
656 | print '</span>'; |
||
657 | } |
||
658 | // If title is not pure text and contains a table, no carriage return added |
||
659 | if (!strstr($menu_array[$i]['titre'], '<table')) { |
||
660 | print '<br>'; |
||
661 | } |
||
662 | print '</div>' . "\n"; |
||
663 | } elseif ($showmenu && $lastlevel0 == 'enabled') { |
||
664 | // Not enabled but visible (so greyed), except if parent was not enabled. |
||
665 | print '<div class="menu_contenu' . $cssmenu . '">'; |
||
666 | print $tabstring; |
||
667 | print '<span class="spanlilevel0 vsmenudisabled vsmenudisabledmargin">' . $menu_array[$i]['titre'] . '</span><br>'; |
||
668 | print '</div>' . "\n"; |
||
669 | } |
||
670 | } |
||
671 | |||
672 | // If next is a new block or if there is nothing after |
||
673 | if (empty($menu_array[$i + 1]['level'])) { // End menu block |
||
674 | if ($showmenu) { |
||
675 | print '<div class="menu_end"></div>' . "\n"; |
||
676 | } |
||
677 | if ($blockvmenuopened) { |
||
678 | print '</div>' . "\n"; |
||
679 | $blockvmenuopened = false; |
||
680 | } |
||
681 | } |
||
682 | } |
||
683 | |||
684 | if ($altok) { |
||
685 | print '<div class="blockvmenuend"></div>'; // End menu block |
||
686 | } |
||
687 | } |
||
688 | |||
689 | return count($menu_array); |
||
690 | } |
||
734 |