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