| Conditions | 7 |
| Paths | 15 |
| Total Lines | 108 |
| Code Lines | 68 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 93 | public function loadBox($max = 5) |
||
| 94 | { |
||
| 95 | global $user, $langs; |
||
| 96 | |||
| 97 | $this->max = $max; |
||
| 98 | |||
| 99 | require_once DOL_DOCUMENT_ROOT."/knowledgemanagement/class/knowledgerecord.class.php"; |
||
| 100 | |||
| 101 | $text = $langs->trans("BoxLastModifiedKnowledgerecordDescription", $max); |
||
| 102 | $this->info_box_head = array( |
||
| 103 | 'text' => $text, |
||
| 104 | 'limit' => dol_strlen($text), |
||
| 105 | ); |
||
| 106 | |||
| 107 | $this->info_box_contents[0][0] = array( |
||
| 108 | 'td' => 'class="left"', |
||
| 109 | 'text' => $langs->trans("BoxLastKnowledgerecordContent"), |
||
| 110 | ); |
||
| 111 | |||
| 112 | if ($user->hasRight('knowledgemanagement', 'knowledgerecord', 'read')) { |
||
| 113 | $sql = 'SELECT k.rowid as id, k.date_creation, k.ref, k.lang, k.question, k.status as status'; |
||
| 114 | $sql .= " FROM ".MAIN_DB_PREFIX."knowledgemanagement_knowledgerecord as k"; |
||
| 115 | $sql .= " WHERE k.entity IN (".getEntity('knowledgemanagement').")"; |
||
| 116 | |||
| 117 | if ($user->socid) { |
||
| 118 | $sql .= " AND k.fk_soc= ".((int) $user->socid); |
||
| 119 | } |
||
| 120 | |||
| 121 | $sql.= " AND k.status > 0"; |
||
| 122 | |||
| 123 | $sql .= " ORDER BY k.tms DESC, k.rowid DESC "; |
||
| 124 | $sql .= $this->db->plimit($max, 0); |
||
| 125 | |||
| 126 | $resql = $this->db->query($sql); |
||
| 127 | if ($resql) { |
||
| 128 | $num = $this->db->num_rows($resql); |
||
| 129 | |||
| 130 | $i = 0; |
||
| 131 | |||
| 132 | while ($i < $num) { |
||
| 133 | $objp = $this->db->fetch_object($resql); |
||
| 134 | |||
| 135 | $datec = $this->db->jdate($objp->date_creation); |
||
| 136 | |||
| 137 | $knowledgerecord = new KnowledgeRecord($this->db); |
||
| 138 | $knowledgerecord->id = $objp->id; |
||
| 139 | $knowledgerecord->date_creation = $objp->date_creation; |
||
| 140 | $knowledgerecord->ref = $objp->ref; |
||
| 141 | $knowledgerecord->status = $objp->status; |
||
| 142 | $knowledgerecord->question = $objp->question; |
||
| 143 | |||
| 144 | $r = 0; |
||
| 145 | |||
| 146 | // Ticket |
||
| 147 | $this->info_box_contents[$i][$r] = array( |
||
| 148 | 'td' => 'class="nowraponall"', |
||
| 149 | 'text' => $knowledgerecord->getNomUrl(1), |
||
| 150 | 'asis' => 1 |
||
| 151 | ); |
||
| 152 | $r++; |
||
| 153 | |||
| 154 | // Question |
||
| 155 | $this->info_box_contents[$i][$r] = array( |
||
| 156 | 'td' => 'class="tdoverflowmax200"', |
||
| 157 | 'text' => '<span title="'.dol_escape_htmltag($objp->question).'">'.dol_escape_htmltag($objp->question).'</span>', |
||
| 158 | 'url' => DOL_URL_ROOT."/knowledgemanagement/knowledgerecord_card.php?id=".urlencode($objp->id), |
||
| 159 | ); |
||
| 160 | $r++; |
||
| 161 | |||
| 162 | // Language |
||
| 163 | $labellang = ($objp->lang ? $langs->trans('Language_'.$objp->lang) : ''); |
||
| 164 | $this->info_box_contents[$i][$r] = array( |
||
| 165 | 'td' => 'class="tdoverflowmax100"', |
||
| 166 | 'text' => picto_from_langcode($objp->lang, 'class="paddingrightonly saturatemedium opacitylow"') . $labellang, |
||
| 167 | 'asis' => 1, |
||
| 168 | ); |
||
| 169 | $r++; |
||
| 170 | |||
| 171 | // Date creation |
||
| 172 | $this->info_box_contents[$i][$r] = array( |
||
| 173 | 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateCreation").': '.dol_print_date($datec, 'dayhour', 'tzuserrel')).'"', |
||
| 174 | 'text' => dol_print_date($datec, 'dayhour', 'tzuserrel'), |
||
| 175 | ); |
||
| 176 | $r++; |
||
| 177 | |||
| 178 | // Statut |
||
| 179 | $this->info_box_contents[$i][$r] = array( |
||
| 180 | 'td' => 'class="right nowraponall"', |
||
| 181 | 'text' => $knowledgerecord->getLibStatut(3), |
||
| 182 | ); |
||
| 183 | $r++; |
||
| 184 | |||
| 185 | $i++; |
||
| 186 | } |
||
| 187 | |||
| 188 | if ($num == 0) { |
||
| 189 | $this->info_box_contents[$i][0] = array( |
||
| 190 | 'td' => '', |
||
| 191 | 'text' => '<span class="opacitymedium">'.$langs->trans("BoxLastTicketNoRecordedTickets").'</span>', |
||
| 192 | ); |
||
| 193 | } |
||
| 194 | } else { |
||
| 195 | dol_print_error($this->db); |
||
| 196 | } |
||
| 197 | } else { |
||
| 198 | $this->info_box_contents[0][0] = array( |
||
| 199 | 'td' => '', |
||
| 200 | 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>', |
||
| 201 | ); |
||
| 218 |