| Conditions | 12 |
| Paths | 45 |
| Total Lines | 117 |
| Code Lines | 76 |
| 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 |
||
| 52 | function loadBox($max=5) |
||
| 53 | { |
||
| 54 | global $user, $langs, $db, $conf; |
||
| 55 | |||
| 56 | $this->max=$max; |
||
| 57 | |||
| 58 | include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
||
| 59 | |||
| 60 | $this->info_box_head = array('text' => $langs->trans("BoxLastProductsInContract",$max)); |
||
| 61 | |||
| 62 | if ($user->rights->service->lire && $user->rights->contrat->lire) |
||
| 63 | { |
||
| 64 | $contractstatic=new Contrat($db); |
||
| 65 | $contratlignestatic=new ContratLigne($db); |
||
| 66 | $thirdpartytmp = new Societe($db); |
||
| 67 | |||
| 68 | $sql = "SELECT s.nom as name, s.rowid as socid,"; |
||
| 69 | $sql.= " c.rowid, c.ref, c.statut as contract_status,"; |
||
| 70 | $sql.= " cd.rowid as cdid, cd.tms as datem, cd.statut, cd.label, cd.description, cd.product_type as type,"; |
||
| 71 | $sql.= " p.rowid as product_id, p.ref as product_ref"; |
||
| 72 | $sql.= " FROM (".MAIN_DB_PREFIX."societe as s"; |
||
| 73 | $sql.= " INNER JOIN ".MAIN_DB_PREFIX."contrat as c ON s.rowid = c.fk_soc"; |
||
| 74 | $sql.= " INNER JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; |
||
| 75 | $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; |
||
| 76 | if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= "INNER JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; |
||
| 77 | $sql.= ")"; |
||
| 78 | $sql.= " WHERE c.entity = ".$conf->entity; |
||
| 79 | if($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; |
||
| 80 | $sql.= $db->order("c.tms","DESC"); |
||
| 81 | $sql.= $db->plimit($max, 0); |
||
| 82 | |||
| 83 | $result = $db->query($sql); |
||
| 84 | if ($result) |
||
| 85 | { |
||
| 86 | $num = $db->num_rows($result); |
||
| 87 | $now=dol_now(); |
||
| 88 | |||
| 89 | $i = 0; |
||
| 90 | |||
| 91 | while ($i < $num) |
||
| 92 | { |
||
| 93 | $objp = $db->fetch_object($result); |
||
| 94 | $datem=$db->jdate($objp->datem); |
||
| 95 | |||
| 96 | $contratlignestatic->id=$objp->cdid; |
||
| 97 | $contratlignestatic->fk_contrat=$objp->rowid; |
||
| 98 | $contratlignestatic->label=$objp->label; |
||
| 99 | $contratlignestatic->description=$objp->description; |
||
| 100 | $contratlignestatic->type=$objp->type; |
||
| 101 | $contratlignestatic->product_id=$objp->product_id; |
||
| 102 | $contratlignestatic->product_ref=$objp->product_ref; |
||
| 103 | |||
| 104 | $contractstatic->statut=$objp->contract_status; |
||
| 105 | $contractstatic->id=$objp->rowid; |
||
| 106 | $contractstatic->ref=$objp->ref; |
||
| 107 | |||
| 108 | $thirdpartytmp->name = $objp->name; |
||
| 109 | $thirdpartytmp->id = $objp->socid; |
||
| 110 | |||
| 111 | // Multilangs |
||
| 112 | if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active |
||
| 113 | { |
||
| 114 | $sqld = "SELECT label"; |
||
| 115 | $sqld.= " FROM ".MAIN_DB_PREFIX."product_lang"; |
||
| 116 | $sqld.= " WHERE fk_product=".$objp->product_id; |
||
| 117 | $sqld.= " AND lang='". $langs->getDefaultLang() ."'"; |
||
| 118 | $sqld.= " LIMIT 1"; |
||
| 119 | |||
| 120 | $resultd = $db->query($sqld); |
||
| 121 | if ($resultd) |
||
| 122 | { |
||
| 123 | $objtp = $db->fetch_object($resultd); |
||
| 124 | if ($objtp->label != '') $contratlignestatic->label = $objtp->label; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | |||
| 128 | $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"', |
||
| 129 | 'text' => $contratlignestatic->getNomUrl(1), |
||
| 130 | 'asis' => 1 |
||
| 131 | ); |
||
| 132 | |||
| 133 | $this->info_box_contents[$i][] = array('td' => '', |
||
| 134 | 'text' => $contractstatic->getNomUrl(1), |
||
| 135 | 'asis' => 1 |
||
| 136 | ); |
||
| 137 | |||
| 138 | $this->info_box_contents[$i][] = array('td' => '', |
||
| 139 | 'text' => $thirdpartytmp->getNomUrl(1), |
||
| 140 | 'asis' => 1 |
||
| 141 | ); |
||
| 142 | |||
| 143 | $this->info_box_contents[$i][] = array('td' => '', |
||
| 144 | 'text' => dol_print_date($datem,'day')); |
||
| 145 | |||
| 146 | $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', |
||
| 147 | 'text' => $contratlignestatic->LibStatut($objp->statut,3) |
||
| 148 | ); |
||
| 149 | |||
| 150 | $i++; |
||
| 151 | } |
||
| 152 | if ($num==0) $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoContractedProducts")); |
||
| 153 | |||
| 154 | $db->free($result); |
||
| 155 | } |
||
| 156 | else |
||
| 157 | { |
||
| 158 | $this->info_box_contents[0][0] = array( 'td' => 'align="left"', |
||
| 159 | 'maxlength'=>500, |
||
| 160 | 'text' => ($db->error().' sql='.$sql)); |
||
| 161 | } |
||
| 162 | } |
||
| 163 | else { |
||
| 164 | $this->info_box_contents[0][0] = array('td' => 'align="left"', |
||
| 165 | 'text' => $langs->trans("ReadPermissionNotAllowed")); |
||
| 166 | } |
||
| 167 | |||
| 168 | } |
||
| 169 | |||
| 185 |