Conditions | 51 |
Paths | > 20000 |
Total Lines | 253 |
Code Lines | 219 |
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 |
||
62 | public function loadBox($max = 5) |
||
63 | { |
||
64 | global $user, $langs; |
||
65 | $langs->load("boxes"); |
||
66 | |||
67 | $this->max = $max; |
||
68 | $this->info_box_head = array('text' => $langs->trans("DolibarrStateBoard")); |
||
69 | |||
70 | if (empty($user->socid) && !getDolGlobalString('MAIN_DISABLE_GLOBAL_BOXSTATS')) { |
||
71 | $hookmanager = new HookManager($this->db); |
||
72 | $hookmanager->initHooks(array('index')); |
||
73 | $object = new stdClass(); |
||
74 | $action = ''; |
||
75 | $parameters = array(); |
||
76 | $hookmanager->executeHooks('addStatisticLine', $parameters, $object, $action); |
||
77 | $boxstatItems = array(); |
||
78 | $boxstatFromHook = ''; |
||
79 | $boxstatFromHook = $hookmanager->resPrint; |
||
80 | $boxstat = ''; |
||
81 | |||
82 | $keys = array( |
||
83 | 'users', |
||
84 | 'members', |
||
85 | 'expensereports', |
||
86 | 'holidays', |
||
87 | 'customers', |
||
88 | 'prospects', |
||
89 | 'suppliers', |
||
90 | 'contacts', |
||
91 | 'products', |
||
92 | 'services', |
||
93 | 'projects', |
||
94 | 'proposals', |
||
95 | 'orders', |
||
96 | 'invoices', |
||
97 | 'donations', |
||
98 | 'supplier_proposals', |
||
99 | 'supplier_orders', |
||
100 | 'supplier_invoices', |
||
101 | 'contracts', |
||
102 | 'interventions', |
||
103 | 'ticket', |
||
104 | 'dolresource' |
||
105 | ); |
||
106 | $conditions = array( |
||
107 | 'users' => $user->hasRight('user', 'user', 'lire'), |
||
108 | 'members' => isModEnabled('member') && $user->hasRight('adherent', 'lire'), |
||
109 | 'customers' => isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS'), |
||
110 | 'prospects' => isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS'), |
||
111 | 'suppliers' => ( |
||
112 | (isModEnabled("fournisseur") && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight('fournisseur', 'lire')) |
||
113 | || (isModEnabled("supplier_order") && $user->hasRight('supplier_order', 'lire')) |
||
114 | || (isModEnabled("supplier_invoice") && $user->hasRight('supplier_invoice', 'lire')) |
||
115 | ) |
||
116 | && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS'), |
||
117 | 'contacts' => isModEnabled('societe') && $user->hasRight('societe', 'contact', 'lire'), |
||
118 | 'products' => isModEnabled('product') && $user->hasRight('product', 'read'), |
||
119 | 'services' => isModEnabled('service') && $user->hasRight('service', 'read'), |
||
120 | 'proposals' => isModEnabled('propal') && $user->hasRight('propal', 'read'), |
||
121 | 'orders' => isModEnabled('order') && $user->hasRight('commande', 'lire'), |
||
122 | 'invoices' => isModEnabled('invoice') && $user->hasRight('facture', 'lire'), |
||
123 | 'donations' => isModEnabled('don') && $user->hasRight('don', 'lire'), |
||
124 | 'contracts' => isModEnabled('contract') && $user->hasRight('contrat', 'lire'), |
||
125 | 'interventions' => isModEnabled('intervention') && $user->hasRight('ficheinter', 'lire'), |
||
126 | 'supplier_orders' => isModEnabled('supplier_order') && $user->hasRight('fournisseur', 'commande', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_ORDERS_STATS'), |
||
127 | 'supplier_invoices' => isModEnabled('supplier_invoice') && $user->hasRight('fournisseur', 'facture', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_INVOICES_STATS'), |
||
128 | 'supplier_proposals' => isModEnabled('supplier_proposal') && $user->hasRight('supplier_proposal', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_PROPOSAL_STATS'), |
||
129 | 'projects' => isModEnabled('project') && $user->hasRight('projet', 'lire'), |
||
130 | 'expensereports' => isModEnabled('expensereport') && $user->hasRight('expensereport', 'lire'), |
||
131 | 'holidays' => isModEnabled('holiday') && $user->hasRight('holiday', 'read'), |
||
132 | 'ticket' => isModEnabled('ticket') && $user->hasRight('ticket', 'read'), |
||
133 | 'dolresource' => isModEnabled('resource') && $user->hasRight('resource', 'read') |
||
134 | ); |
||
135 | $classes = array( |
||
136 | 'users' => 'User', |
||
137 | 'members' => 'Adherent', |
||
138 | 'customers' => 'Client', |
||
139 | 'prospects' => 'Client', |
||
140 | 'suppliers' => 'Fournisseur', |
||
141 | 'contacts' => 'Contact', |
||
142 | 'products' => 'Product', |
||
143 | 'services' => 'ProductService', |
||
144 | 'proposals' => 'Propal', |
||
145 | 'orders' => 'Commande', |
||
146 | 'invoices' => 'Facture', |
||
147 | 'donations' => 'Don', |
||
148 | 'contracts' => 'Contrat', |
||
149 | 'interventions' => 'Fichinter', |
||
150 | 'supplier_orders' => 'CommandeFournisseur', |
||
151 | 'supplier_invoices' => 'FactureFournisseur', |
||
152 | 'supplier_proposals' => 'SupplierProposal', |
||
153 | 'projects' => 'Project', |
||
154 | 'expensereports' => 'ExpenseReport', |
||
155 | 'holidays' => 'Holiday', |
||
156 | 'ticket' => 'Ticket', |
||
157 | 'dolresource' => 'Dolresource' |
||
158 | ); |
||
159 | $includes = array( |
||
160 | 'users' => DOL_DOCUMENT_ROOT . "/user/class/user.class.php", |
||
161 | 'members' => DOL_DOCUMENT_ROOT . "/adherents/class/adherent.class.php", |
||
162 | 'customers' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php", |
||
163 | 'prospects' => DOL_DOCUMENT_ROOT . "/societe/class/client.class.php", |
||
164 | 'suppliers' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.class.php", |
||
165 | 'contacts' => DOL_DOCUMENT_ROOT . "/contact/class/contact.class.php", |
||
166 | 'products' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php", |
||
167 | 'services' => DOL_DOCUMENT_ROOT . "/product/class/product.class.php", |
||
168 | 'proposals' => DOL_DOCUMENT_ROOT . "/comm/propal/class/propal.class.php", |
||
169 | 'orders' => DOL_DOCUMENT_ROOT . "/commande/class/commande.class.php", |
||
170 | 'invoices' => DOL_DOCUMENT_ROOT . "/compta/facture/class/facture.class.php", |
||
171 | 'donations' => DOL_DOCUMENT_ROOT . "/don/class/don.class.php", |
||
172 | 'contracts' => DOL_DOCUMENT_ROOT . "/contrat/class/contrat.class.php", |
||
173 | 'interventions' => DOL_DOCUMENT_ROOT . "/fichinter/class/fichinter.class.php", |
||
174 | 'supplier_orders' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.commande.class.php", |
||
175 | 'supplier_invoices' => DOL_DOCUMENT_ROOT . "/fourn/class/fournisseur.facture.class.php", |
||
176 | 'supplier_proposals' => DOL_DOCUMENT_ROOT . "/supplier_proposal/class/supplier_proposal.class.php", |
||
177 | 'projects' => DOL_DOCUMENT_ROOT . "/projet/class/project.class.php", |
||
178 | 'expensereports' => DOL_DOCUMENT_ROOT . "/expensereport/class/expensereport.class.php", |
||
179 | 'holidays' => DOL_DOCUMENT_ROOT . "/holiday/class/holiday.class.php", |
||
180 | 'ticket' => DOL_DOCUMENT_ROOT . "/ticket/class/ticket.class.php", |
||
181 | 'dolresource' => DOL_DOCUMENT_ROOT . "/resource/class/dolresource.class.php" |
||
182 | ); |
||
183 | $links = array( |
||
184 | 'users' => DOL_URL_ROOT . '/user/list.php', |
||
185 | 'members' => DOL_URL_ROOT . '/adherents/list.php?statut=1&mainmenu=members', |
||
186 | 'customers' => DOL_URL_ROOT . '/societe/list.php?type=c&mainmenu=companies', |
||
187 | 'prospects' => DOL_URL_ROOT . '/societe/list.php?type=p&mainmenu=companies', |
||
188 | 'suppliers' => DOL_URL_ROOT . '/societe/list.php?type=f&mainmenu=companies', |
||
189 | 'contacts' => DOL_URL_ROOT . '/contact/list.php?mainmenu=companies', |
||
190 | 'products' => DOL_URL_ROOT . '/product/list.php?type=0&mainmenu=products', |
||
191 | 'services' => DOL_URL_ROOT . '/product/list.php?type=1&mainmenu=products', |
||
192 | 'proposals' => DOL_URL_ROOT . '/comm/propal/list.php?mainmenu=commercial&leftmenu=propals', |
||
193 | 'orders' => DOL_URL_ROOT . '/commande/list.php?mainmenu=commercial&leftmenu=orders', |
||
194 | 'invoices' => DOL_URL_ROOT . '/compta/facture/list.php?mainmenu=billing&leftmenu=customers_bills', |
||
195 | 'donations' => DOL_URL_ROOT . '/don/list.php?leftmenu=donations', |
||
196 | 'contracts' => DOL_URL_ROOT . '/contrat/list.php?mainmenu=commercial&leftmenu=contracts', |
||
197 | 'interventions' => DOL_URL_ROOT . '/fichinter/list.php?mainmenu=commercial&leftmenu=ficheinter', |
||
198 | 'supplier_orders' => DOL_URL_ROOT . '/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers', |
||
199 | 'supplier_invoices' => DOL_URL_ROOT . '/fourn/facture/list.php?mainmenu=billing&leftmenu=suppliers_bills', |
||
200 | 'supplier_proposals' => DOL_URL_ROOT . '/supplier_proposal/list.php?mainmenu=commercial&leftmenu=', |
||
201 | 'projects' => DOL_URL_ROOT . '/projet/list.php?mainmenu=project', |
||
202 | 'expensereports' => DOL_URL_ROOT . '/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport', |
||
203 | 'holidays' => DOL_URL_ROOT . '/holiday/list.php?mainmenu=hrm&leftmenu=holiday', |
||
204 | 'ticket' => DOL_URL_ROOT . '/ticket/list.php?leftmenu=ticket', |
||
205 | 'dolresource' => DOL_URL_ROOT . '/resource/list.php?mainmenu=agenda', |
||
206 | ); |
||
207 | $titres = array( |
||
208 | 'users' => "Users", |
||
209 | 'members' => "Members", |
||
210 | 'customers' => "ThirdPartyCustomersStats", |
||
211 | 'prospects' => "ThirdPartyProspectsStats", |
||
212 | 'suppliers' => "Suppliers", |
||
213 | 'contacts' => "Contacts", |
||
214 | 'products' => "Products", |
||
215 | 'services' => "Services", |
||
216 | 'proposals' => "CommercialProposalsShort", |
||
217 | 'orders' => "CustomersOrders", |
||
218 | 'invoices' => "BillsCustomers", |
||
219 | 'donations' => "Donations", |
||
220 | 'contracts' => "Contracts", |
||
221 | 'interventions' => "Interventions", |
||
222 | 'supplier_orders' => "SuppliersOrders", |
||
223 | 'supplier_invoices' => "SuppliersInvoices", |
||
224 | 'supplier_proposals' => "SupplierProposalShort", |
||
225 | 'projects' => "Projects", |
||
226 | 'expensereports' => "ExpenseReports", |
||
227 | 'holidays' => "Holidays", |
||
228 | 'ticket' => "Ticket", |
||
229 | 'dolresource' => "Resources", |
||
230 | ); |
||
231 | $langfile = array( |
||
232 | 'customers' => "companies", |
||
233 | 'contacts' => "companies", |
||
234 | 'services' => "products", |
||
235 | 'proposals' => "propal", |
||
236 | 'invoices' => "bills", |
||
237 | 'supplier_orders' => "orders", |
||
238 | 'supplier_invoices' => "bills", |
||
239 | 'supplier_proposals' => 'supplier_proposal', |
||
240 | 'expensereports' => "trips", |
||
241 | 'holidays' => "holiday", |
||
242 | ); |
||
243 | $boardloaded = array(); |
||
244 | |||
245 | foreach ($keys as $val) { |
||
246 | if ($conditions[$val]) { |
||
247 | $boxstatItem = ''; |
||
248 | $class = $classes[$val]; |
||
249 | // Search in cache if load_state_board is already realized |
||
250 | $classkeyforcache = $class; |
||
251 | if ($classkeyforcache == 'ProductService') { |
||
252 | $classkeyforcache = 'Product'; // ProductService use same load_state_board than Product |
||
253 | } |
||
254 | |||
255 | if (!isset($boardloaded[$classkeyforcache]) || !is_object($boardloaded[$classkeyforcache])) { |
||
256 | $board = Misc::loadModel($class, $this->db); |
||
257 | |||
258 | if (empty($board)) { |
||
259 | include_once $includes[$val]; // Loading a class cost around 1Mb |
||
260 | $board = new $class($this->db); |
||
261 | } |
||
262 | |||
263 | if (method_exists($board, 'load_state_board')) { |
||
264 | $board->load_state_board(); |
||
265 | } elseif (method_exists($board, 'loadStateBoard')) { |
||
266 | $board->loadStateBoard(); |
||
267 | } else { |
||
268 | $board = -1; |
||
269 | } |
||
270 | $boardloaded[$class] = $board; |
||
271 | } else { |
||
272 | $board = $boardloaded[$classkeyforcache]; |
||
273 | } |
||
274 | |||
275 | $langs->load(empty($langfile[$val]) ? $val : $langfile[$val]); |
||
276 | |||
277 | $text = $langs->trans($titres[$val]); |
||
278 | $boxstatItem .= '<a href="' . $links[$val] . '" class="boxstatsindicator thumbstat nobold nounderline">'; |
||
279 | $boxstatItem .= '<div class="boxstats">'; |
||
280 | $boxstatItem .= '<span class="boxstatstext" title="' . dol_escape_htmltag($text) . '">' . $text . '</span><br>'; |
||
281 | $boxstatItem .= '<span class="boxstatsindicator">' . img_object("", $board->picto, 'class="inline-block"') . ' ' . (!empty($board->nb[$val]) ? $board->nb[$val] : 0) . '</span>'; |
||
282 | $boxstatItem .= '</div>'; |
||
283 | $boxstatItem .= '</a>'; |
||
284 | |||
285 | $boxstatItems[$val] = $boxstatItem; |
||
286 | } |
||
287 | } |
||
288 | |||
289 | if (!empty($boxstatFromHook) || !empty($boxstatItems)) { |
||
290 | $boxstat .= $boxstatFromHook; |
||
291 | |||
292 | if (is_array($boxstatItems) && count($boxstatItems) > 0) { |
||
293 | $boxstat .= implode('', $boxstatItems); |
||
294 | } |
||
295 | |||
296 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
297 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
298 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
299 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
300 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
301 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
302 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
303 | $boxstat .= '<a class="boxstatsindicator thumbstat nobold nounderline"><div class="boxstatsempty"></div></a>'; |
||
304 | |||
305 | $this->info_box_contents[0][0] = array( |
||
306 | 'tr' => 'class="nohover"', |
||
307 | 'td' => 'class="tdwidgetstate"', |
||
308 | 'textnoformat' => $boxstat |
||
309 | ); |
||
310 | } |
||
311 | } else { |
||
312 | $this->info_box_contents[0][0] = array( |
||
313 | 'td' => '', |
||
314 | 'text' => $langs->trans("ReadPermissionNotAllowed") |
||
315 | ); |
||
333 |