| Conditions | 13 |
| Paths | 108 |
| Total Lines | 67 |
| 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 |
||
| 32 | function resource_prepare_head($object) |
||
| 33 | { |
||
| 34 | global $langs, $conf, $user; |
||
| 35 | $h = 0; |
||
| 36 | $head = array(); |
||
| 37 | |||
| 38 | $head[$h][0] = dol_buildpath('/resource/card.php',1).'?id='.$object->id; |
||
| 39 | $head[$h][1] = $langs->trans("ResourceCard"); |
||
| 40 | $head[$h][2] = 'resource'; |
||
| 41 | $h++; |
||
| 42 | |||
| 43 | if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && (empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER) || empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY))) |
||
| 44 | { |
||
| 45 | $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external')); |
||
| 46 | $head[$h][0] = DOL_URL_ROOT.'/resource/contact.php?id='.$object->id; |
||
| 47 | $head[$h][1] = $langs->trans('ContactsAddresses'); |
||
| 48 | if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>'; |
||
| 49 | $head[$h][2] = 'contact'; |
||
| 50 | $h++; |
||
| 51 | } |
||
| 52 | |||
| 53 | // Show more tabs from modules |
||
| 54 | // Entries must be declared in modules descriptor with line |
||
| 55 | // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab |
||
| 56 | // $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab |
||
| 57 | complete_head_from_modules($conf,$langs,$object,$head,$h,'resource'); |
||
| 58 | |||
| 59 | if (empty($conf->global->MAIN_DISABLE_NOTES_TAB)) |
||
| 60 | { |
||
| 61 | $nbNote = 0; |
||
| 62 | if(!empty($object->note_private)) $nbNote++; |
||
| 63 | if(!empty($object->note_public)) $nbNote++; |
||
| 64 | $head[$h][0] = DOL_URL_ROOT.'/resource/note.php?id='.$object->id; |
||
| 65 | $head[$h][1] = $langs->trans('Notes'); |
||
| 66 | if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>'; |
||
| 67 | $head[$h][2] = 'note'; |
||
| 68 | $h++; |
||
| 69 | } |
||
| 70 | |||
| 71 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
||
| 72 | $upload_dir = $conf->resource->dir_output . "/" . dol_sanitizeFileName($object->ref); |
||
| 73 | $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$')); |
||
| 74 | $head[$h][0] = DOL_URL_ROOT.'/resource/document.php?id='.$object->id; |
||
| 75 | $head[$h][1] = $langs->trans("Documents"); |
||
| 76 | if($nbFiles > 0) $head[$h][1].= ' <span class="badge">'.$nbFiles.'</span>'; |
||
| 77 | $head[$h][2] = 'documents'; |
||
| 78 | $h++; |
||
| 79 | |||
| 80 | $head[$h][0] = DOL_URL_ROOT.'/resource/agenda.php?id='.$object->id; |
||
| 81 | $head[$h][1] = $langs->trans("Events"); |
||
| 82 | if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) )) |
||
| 83 | { |
||
| 84 | $head[$h][1].= '/'; |
||
| 85 | $head[$h][1].= $langs->trans("Agenda"); |
||
| 86 | } |
||
| 87 | $head[$h][2] = 'agenda'; |
||
| 88 | $h++; |
||
| 89 | |||
| 90 | /*$head[$h][0] = DOL_URL_ROOT.'/resource/info.php?id='.$object->id; |
||
| 91 | $head[$h][1] = $langs->trans('Info'); |
||
| 92 | $head[$h][2] = 'info'; |
||
| 93 | $h++;*/ |
||
| 94 | |||
| 95 | complete_head_from_modules($conf,$langs,$object,$head,$h,'resource', 'remove'); |
||
| 96 | |||
| 97 | return $head; |
||
| 98 | } |
||
| 99 | |||
| 133 |