Conditions | 49 |
Paths | > 20000 |
Total Lines | 190 |
Code Lines | 126 |
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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
1 | <?php |
||
179 | public function showactions($object, $typeelement, $socid = 0, $forceshowtitle = 0, $morecss = 'listactions', $max = 0, $moreparambacktopage = '', $morehtmlcenter = '', $assignedtouser = 0) |
||
180 | { |
||
181 | global $langs, $conf, $user, $hookmanager; |
||
182 | |||
183 | require_once constant('DOL_DOCUMENT_ROOT') . '/comm/action/class/actioncomm.class.php'; |
||
184 | |||
185 | $sortfield = 'a.datep,a.id'; |
||
186 | $sortorder = 'DESC,DESC'; |
||
187 | |||
188 | $actioncomm = new ActionComm($this->db); |
||
189 | $listofactions = $actioncomm->getActions($socid, $object->id, $typeelement, '', $sortfield, $sortorder, ($max ? ($max + 1) : 0)); |
||
190 | if (!is_array($listofactions)) { |
||
191 | dol_print_error($this->db, 'FailedToGetActions'); |
||
192 | } |
||
193 | |||
194 | require_once constant('DOL_DOCUMENT_ROOT') . '/comm/action/class/cactioncomm.class.php'; |
||
195 | $caction = new CActionComm($this->db); |
||
196 | $arraylist = $caction->liste_array(1, 'code', '', (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') ? 1 : 0), '', 1); |
||
197 | |||
198 | $num = count($listofactions); |
||
199 | if ($num || $forceshowtitle) { |
||
200 | $title = $langs->trans("LatestLinkedEvents", $max ? $max : ''); |
||
201 | |||
202 | $urlbacktopage = $_SERVER['PHP_SELF'] . '?id=' . $object->id . ($moreparambacktopage ? '&' . $moreparambacktopage : ''); |
||
203 | |||
204 | $projectid = $object->fk_project; |
||
205 | if ($typeelement == 'project') { |
||
206 | $projectid = $object->id; |
||
207 | } |
||
208 | $taskid = 0; |
||
209 | if ($typeelement == 'task') { |
||
210 | $taskid = $object->id; |
||
211 | } |
||
212 | |||
213 | $usercanaddaction = 0; |
||
214 | if (empty($assignedtouser) || $assignedtouser == $user->id) { |
||
215 | $usercanaddaction = $user->hasRight('agenda', 'myactions', 'create'); |
||
216 | $assignedtouser = 0; |
||
217 | } else { |
||
218 | $usercanaddaction = $user->hasRight('agenda', 'allactions', 'create'); |
||
219 | } |
||
220 | |||
221 | $url = ''; |
||
222 | $morehtmlright = ''; |
||
223 | if (isModEnabled('agenda') && $usercanaddaction) { |
||
224 | $url = constant('BASE_URL') . '/comm/action/card.php?action=create&token=' . newToken() . '&datep=' . urlencode(dol_print_date(dol_now(), 'dayhourlog', 'tzuser')); |
||
225 | $url .= '&origin=' . urlencode($typeelement) . '&originid=' . ((int) $object->id) . ((!empty($object->socid) && $object->socid > 0) ? '&socid=' . ((int) $object->socid) : ((!empty($socid) && $socid > 0) ? '&socid=' . ((int) $socid) : '')); |
||
226 | $url .= ($projectid > 0 ? '&projectid=' . ((int) $projectid) : '') . ($taskid > 0 ? '&taskid=' . ((int) $taskid) : ''); |
||
227 | $url .= ($assignedtouser > 0 ? '&assignedtouser=' . $assignedtouser : ''); |
||
228 | $url .= '&backtopage=' . urlencode($urlbacktopage); |
||
229 | $morehtmlright .= dolGetButtonTitle($langs->trans("AddEvent"), '', 'fa fa-plus-circle', $url); |
||
230 | } |
||
231 | |||
232 | $parameters = array( |
||
233 | 'title' => &$title, |
||
234 | 'morehtmlright' => &$morehtmlright, |
||
235 | 'morehtmlcenter' => &$morehtmlcenter, |
||
236 | 'usercanaddaction' => $usercanaddaction, |
||
237 | 'url' => &$url, |
||
238 | 'typeelement' => $typeelement, |
||
239 | 'projectid' => $projectid, |
||
240 | 'assignedtouser' => $assignedtouser, |
||
241 | 'taskid' => $taskid, |
||
242 | 'urlbacktopage' => $urlbacktopage |
||
243 | ); |
||
244 | |||
245 | $reshook = $hookmanager->executeHooks('showActionsLoadFicheTitre', $parameters, $object); |
||
246 | |||
247 | if ($reshook < 0) { |
||
248 | setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
||
249 | } |
||
250 | |||
251 | $error = 0; |
||
252 | if (empty($reshook)) { |
||
253 | print '<!-- formactions->showactions -->' . "\n"; |
||
254 | print load_fiche_titre($title, $morehtmlright, '', 0, 0, '', $morehtmlcenter); |
||
255 | } |
||
256 | |||
257 | $page = 0; |
||
258 | $param = ''; |
||
259 | |||
260 | print '<div class="div-table-responsive-no-min">'; |
||
261 | print '<table class="centpercent noborder' . ($morecss ? ' ' . $morecss : '') . '">'; |
||
262 | print '<tr class="liste_titre">'; |
||
263 | print getTitleFieldOfList('Ref', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); |
||
264 | print getTitleFieldOfList('Date', 0, $_SERVER["PHP_SELF"], 'a.datep', $page, $param, '', $sortfield, $sortorder, 'center ', 1); |
||
265 | print getTitleFieldOfList('By', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); |
||
266 | print getTitleFieldOfList('Type', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); |
||
267 | print getTitleFieldOfList('Title', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, '', 1); |
||
268 | print getTitleFieldOfList('', 0, $_SERVER["PHP_SELF"], '', $page, $param, '', $sortfield, $sortorder, 'right ', 1); |
||
269 | print '</tr>'; |
||
270 | print "\n"; |
||
271 | |||
272 | if (is_array($listofactions) && count($listofactions)) { |
||
273 | $cacheusers = array(); |
||
274 | |||
275 | $cursorevent = 0; |
||
276 | foreach ($listofactions as $actioncomm) { |
||
277 | if ($max && $cursorevent >= $max) { |
||
278 | break; |
||
279 | } |
||
280 | |||
281 | print '<tr class="oddeven">'; |
||
282 | |||
283 | // Ref |
||
284 | print '<td class="nowraponall">' . $actioncomm->getNomUrl(1, -1) . '</td>'; |
||
285 | |||
286 | // Date |
||
287 | print '<td class="center nowraponall">' . dol_print_date($actioncomm->datep, 'dayhour', 'tzuserrel'); |
||
288 | if ($actioncomm->datef) { |
||
289 | $tmpa = dol_getdate($actioncomm->datep); |
||
290 | $tmpb = dol_getdate($actioncomm->datef); |
||
291 | if ($tmpa['mday'] == $tmpb['mday'] && $tmpa['mon'] == $tmpb['mon'] && $tmpa['year'] == $tmpb['year']) { |
||
292 | if ($tmpa['hours'] != $tmpb['hours'] || $tmpa['minutes'] != $tmpb['minutes']) { |
||
293 | print '-' . dol_print_date($actioncomm->datef, 'hour', 'tzuserrel'); |
||
294 | } |
||
295 | } else { |
||
296 | print '-' . dol_print_date($actioncomm->datef, 'dayhour', 'tzuserrel'); |
||
297 | } |
||
298 | } |
||
299 | print '</td>'; |
||
300 | |||
301 | // Owner |
||
302 | print '<td class="nowraponall tdoverflowmax125">'; |
||
303 | if (!empty($actioncomm->userownerid)) { |
||
304 | if (isset($cacheusers[$actioncomm->userownerid]) && is_object($cacheusers[$actioncomm->userownerid])) { |
||
305 | $tmpuser = $cacheusers[$actioncomm->userownerid]; |
||
306 | } else { |
||
307 | $tmpuser = new User($this->db); |
||
|
|||
308 | $tmpuser->fetch($actioncomm->userownerid); |
||
309 | $cacheusers[$actioncomm->userownerid] = $tmpuser; |
||
310 | } |
||
311 | if ($tmpuser->id > 0) { |
||
312 | print $tmpuser->getNomUrl(-1, '', 0, 0, 16, 0, 'firstelselast', ''); |
||
313 | } |
||
314 | } |
||
315 | print '</td>'; |
||
316 | |||
317 | $actionstatic = $actioncomm; |
||
318 | |||
319 | // Example: Email sent from invoice card |
||
320 | //$actionstatic->code = 'AC_BILL_SENTBYMAIL |
||
321 | //$actionstatic->type_code = 'AC_OTHER_AUTO' |
||
322 | |||
323 | // Type |
||
324 | $labeltype = $actionstatic->type_code; |
||
325 | if (!getDolGlobalString('AGENDA_USE_EVENT_TYPE') && empty($arraylist[$labeltype])) { |
||
326 | $labeltype = 'AC_OTH'; |
||
327 | } |
||
328 | if (preg_match('/^TICKET_MSG/', $actionstatic->code)) { |
||
329 | $labeltype = $langs->trans("Message"); |
||
330 | } else { |
||
331 | if (!empty($arraylist[$labeltype])) { |
||
332 | $labeltype = $arraylist[$labeltype]; |
||
333 | } |
||
334 | if ($actionstatic->type_code == 'AC_OTH_AUTO' && ($actionstatic->type_code != $actionstatic->code) && $labeltype && !empty($arraylist[$actionstatic->code])) { |
||
335 | $labeltype .= ' - ' . $arraylist[$actionstatic->code]; // Use code in priority on type_code |
||
336 | } |
||
337 | } |
||
338 | print '<td class="tdoverflowmax100" title="' . dol_escape_htmltag($labeltype) . '">'; |
||
339 | print $actioncomm->getTypePicto(); |
||
340 | print $labeltype; |
||
341 | print '</td>'; |
||
342 | |||
343 | // Label |
||
344 | print '<td class="tdoverflowmax200">'; |
||
345 | print $actioncomm->getNomUrl(0); |
||
346 | print '</td>'; |
||
347 | |||
348 | // Status |
||
349 | print '<td class="right">'; |
||
350 | print $actioncomm->getLibStatut(3); |
||
351 | print '</td>'; |
||
352 | print '</tr>'; |
||
353 | |||
354 | $cursorevent++; |
||
355 | } |
||
356 | } else { |
||
357 | print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">' . $langs->trans("None") . '</span></td></tr>'; |
||
358 | } |
||
359 | |||
360 | if ($max && $num > $max) { |
||
361 | print '<tr class="oddeven"><td colspan="6"><span class="opacitymedium">' . $langs->trans("More") . '...</span></td></tr>'; |
||
362 | } |
||
363 | |||
364 | print '</table>'; |
||
365 | print '</div>'; |
||
366 | } |
||
367 | |||
368 | return $num; |
||
369 | } |
||
451 |