| Conditions | 8 |
| Paths | 26 |
| Total Lines | 55 |
| Code Lines | 34 |
| 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 |
||
| 30 | function workstationPrepareHead($object) |
||
| 31 | { |
||
| 32 | global $db, $langs, $conf; |
||
| 33 | |||
| 34 | $langs->load("workstation@workstation"); |
||
| 35 | |||
| 36 | $h = 0; |
||
| 37 | $head = array(); |
||
| 38 | |||
| 39 | $head[$h][0] = dol_buildpath("/workstation/workstation_card.php", 1).'?id='.$object->id; |
||
| 40 | $head[$h][1] = $langs->trans("Card"); |
||
| 41 | $head[$h][2] = 'card'; |
||
| 42 | $h++; |
||
| 43 | |||
| 44 | if (isset($object->fields['note_public']) || isset($object->fields['note_private'])) |
||
| 45 | { |
||
| 46 | $nbNote = 0; |
||
| 47 | if (!empty($object->note_private)) $nbNote++; |
||
| 48 | if (!empty($object->note_public)) $nbNote++; |
||
| 49 | $head[$h][0] = dol_buildpath('/workstation/workstation_note.php', 1).'?id='.$object->id; |
||
| 50 | $head[$h][1] = $langs->trans('Notes'); |
||
| 51 | if ($nbNote > 0) $head[$h][1] .= (empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER) ? '<span class="badge marginleftonlyshort">'.$nbNote.'</span>' : ''); |
||
| 52 | $head[$h][2] = 'note'; |
||
| 53 | $h++; |
||
| 54 | } |
||
| 55 | |||
| 56 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
||
| 57 | require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; |
||
| 58 | $upload_dir = $conf->workstation->dir_output."/workstation/".dol_sanitizeFileName($object->ref); |
||
| 59 | $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); |
||
| 60 | $nbLinks = Link::count($db, $object->element, $object->id); |
||
| 61 | $head[$h][0] = dol_buildpath("/workstation/workstation_document.php", 1).'?id='.$object->id; |
||
| 62 | $head[$h][1] = $langs->trans('Documents'); |
||
| 63 | if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= '<span class="badge marginleftonlyshort">'.($nbFiles + $nbLinks).'</span>'; |
||
| 64 | $head[$h][2] = 'document'; |
||
| 65 | $h++; |
||
| 66 | |||
| 67 | $head[$h][0] = dol_buildpath("/workstation/workstation_agenda.php", 1).'?id='.$object->id; |
||
| 68 | $head[$h][1] = $langs->trans("Events"); |
||
| 69 | $head[$h][2] = 'agenda'; |
||
| 70 | $h++; |
||
| 71 | |||
| 72 | // Show more tabs from modules |
||
| 73 | // Entries must be declared in modules descriptor with line |
||
| 74 | //$this->tabs = array( |
||
| 75 | // 'entity:+tabname:Title:@workstation:/workstation/mypage.php?id=__ID__' |
||
| 76 | //); // to add new tab |
||
| 77 | //$this->tabs = array( |
||
| 78 | // 'entity:-tabname:Title:@workstation:/workstation/mypage.php?id=__ID__' |
||
| 79 | //); // to remove a tab |
||
| 80 | complete_head_from_modules($conf, $langs, $object, $head, $h, 'workstation@workstation'); |
||
| 81 | |||
| 82 | complete_head_from_modules($conf, $langs, $object, $head, $h, 'workstation@workstation', 'remove'); |
||
| 83 | |||
| 84 | return $head; |
||
| 85 | } |
||
| 86 |