Completed
Branch develop (09fbe4)
by
unknown
29:23
created

resource.lib.php ➔ resource_prepare_head()   C

Complexity

Conditions 13
Paths 108

Size

Total Lines 67

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 13
nc 108
nop 1
dl 0
loc 67
rs 5.96
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/* Module to manage locations, buildings, floors and rooms into Dolibarr ERP/CRM
3
 * Copyright (C) 2013	Jean-François Ferry	<[email protected]>
4
 * Copyright (C) 2016	Gilles Poirier		<[email protected]>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
/**
21
 *	\file		htdocs/core/lib/resource.lib.php
22
 *	\ingroup	resource
23
 *	\brief		This file is library for resource module
24
 */
25
26
/**
27
 * Prepare head for tabs
28
 *
29
 * @param	Object	$object		Object
30
 * @return	array				Array of head entries
31
 */
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
100
/**
101
 * Prepare head for admin tabs
102
 *
103
 * @return  array               Array of head entries
104
 */
105
function resource_admin_prepare_head()
106
{
107
108
	global $langs, $conf, $user;
109
110
	$h = 0;
111
	$head = array();
112
113
	$head[$h][0] = DOL_URL_ROOT.'/admin/resource.php';
114
	$head[$h][1] = $langs->trans("ResourceSetup");
115
	$head[$h][2] = 'general';
116
	$h++;
117
118
	// Show more tabs from modules
119
	// Entries must be declared in modules descriptor with line
120
	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
121
	// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to remove a tab
122
	complete_head_from_modules($conf,$langs,null,$head,$h,'resource_admin');
123
124
	$head[$h][0] = DOL_URL_ROOT.'/admin/resource_extrafields.php';
125
	$head[$h][1] = $langs->trans("ExtraFields");
126
	$head[$h][2] = 'attributes';
127
	$h++;
128
129
	complete_head_from_modules($conf,$langs,null,$head,$h,'resource_admin','remove');
130
131
	return $head;
132
}
133