Conditions | 13 |
Paths | 160 |
Total Lines | 164 |
Code Lines | 130 |
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 |
||
301 | function publisher_editCat($showmenu = false, $categoryid = 0, $nb_subcats = 4, $categoryObj = null) |
||
302 | { |
||
303 | $xoops = Xoops::getInstance(); |
||
304 | $helper = Helper::getInstance(); |
||
305 | /* @var Publisher\Category $categoryObj */ |
||
306 | |||
307 | // if there is a parameter, and the id exists, retrieve data: we're editing a category |
||
308 | if (0 != $categoryid) { |
||
309 | // Creating the category object for the selected category |
||
310 | $categoryObj = $helper->getCategoryHandler()->get($categoryid); |
||
311 | if ($categoryObj->notLoaded()) { |
||
312 | $xoops->redirect('category.php', 1, _AM_PUBLISHER_NOCOLTOEDIT); |
||
313 | } |
||
314 | } else { |
||
315 | if (!$categoryObj) { |
||
316 | $categoryObj = $helper->getCategoryHandler()->create(); |
||
317 | } |
||
318 | } |
||
319 | |||
320 | if (0 != $categoryid) { |
||
321 | if ($showmenu) { |
||
322 | //publisher_adminMenu(1, _AM_PUBLISHER_CATEGORIES . " > " . _AM_PUBLISHER_EDITING); |
||
323 | } |
||
324 | echo "<br>\n"; |
||
325 | Publisher\Utils::openCollapsableBar('edittable', 'edittableicon', _AM_PUBLISHER_EDITCOL, _AM_PUBLISHER_CATEGORY_EDIT_INFO); |
||
326 | } else { |
||
327 | if ($showmenu) { |
||
328 | //publisher_adminMenu(1, _AM_PUBLISHER_CATEGORIES . " > " . _AM_PUBLISHER_CREATINGNEW); |
||
329 | } |
||
330 | Publisher\Utils::openCollapsableBar('createtable', 'createtableicon', _AM_PUBLISHER_CATEGORY_CREATE, _AM_PUBLISHER_CATEGORY_CREATE_INFO); |
||
331 | } |
||
332 | |||
333 | /* @var Publisher\Form\CategoryForm $sform */ |
||
334 | // $sform = $helper->getForm($categoryObj, 'Category'); |
||
335 | $sform = new CategoryForm($categoryObj); |
||
336 | $sform->setSubCatsCount($nb_subcats); |
||
337 | $sform->display(); |
||
338 | |||
339 | if (!$categoryid) { |
||
340 | Publisher\Utils::closeCollapsableBar('createtable', 'createtableicon'); |
||
341 | } else { |
||
342 | Publisher\Utils::closeCollapsableBar('edittable', 'edittableicon'); |
||
343 | } |
||
344 | |||
345 | //Added by fx2024 |
||
346 | if ($categoryid) { |
||
347 | $sel_cat = $categoryid; |
||
348 | |||
349 | Publisher\Utils::openCollapsableBar('subcatstable', 'subcatsicon', _AM_PUBLISHER_SUBCAT_CAT, _AM_PUBLISHER_SUBCAT_CAT_DSC); |
||
350 | // Get the total number of sub-categories |
||
351 | $categoriesObj = $helper->getCategoryHandler()->get($sel_cat); |
||
352 | $totalsubs = $helper->getCategoryHandler()->getCategoriesCount($sel_cat); |
||
353 | // creating the categories objects that are published |
||
354 | $subcatsObj = $helper->getCategoryHandler()->getCategories(0, 0, $categoriesObj->getVar('categoryid')); |
||
355 | |||
356 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
357 | echo '<tr>'; |
||
358 | echo "<td width='60' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATID . '</strong></td>'; |
||
359 | echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_CATCOLNAME . '</strong></td>'; |
||
360 | echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_SUBDESCRIPT . '</strong></td>'; |
||
361 | echo "<td width='60' class='bg3' align='right'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>'; |
||
362 | echo '</tr>'; |
||
363 | if ($totalsubs > 0) { |
||
364 | /* @var Publisher\Category $subcat */ |
||
365 | foreach ($subcatsObj as $subcat) { |
||
366 | $modify = "<a href='category.php?op=mod&categoryid=" |
||
367 | . $subcat->getVar('categoryid') |
||
368 | . "'><img src='" |
||
369 | . XoopsBaseConfig::get('url') |
||
370 | . '/modules/' |
||
371 | . $helper->getModule()->dirname() |
||
372 | . "/images/links/edit.gif' title='" |
||
373 | . _AM_PUBLISHER_MODIFY |
||
374 | . "' alt='" |
||
375 | . _AM_PUBLISHER_MODIFY |
||
376 | . "'></a>"; |
||
377 | $delete = "<a href='category.php?op=del&categoryid=" |
||
378 | . $subcat->getVar('categoryid') |
||
379 | . "'><img src='" |
||
380 | . XoopsBaseConfig::get('url') |
||
381 | . '/modules/' |
||
382 | . $helper->getModule()->dirname() |
||
383 | . "/images/links/delete.png' title='" |
||
384 | . _AM_PUBLISHER_DELETE |
||
385 | . "' alt='" |
||
386 | . _AM_PUBLISHER_DELETE |
||
387 | . "'></a>"; |
||
388 | echo '<tr>'; |
||
389 | echo "<td class='head' align='left'>" . $subcat->getVar('categoryid') . '</td>'; |
||
390 | echo "<td class='even' align='left'><a href='" . XoopsBaseConfig::get('url') . '/modules/' . $helper->getModule()->dirname() . '/category.php?categoryid=' . $subcat->getVar('categoryid') . '&parentid=' . $subcat->getVar('parentid') . "'>" . $subcat->getVar('name') . '</a></td>'; |
||
391 | echo "<td class='even' align='left'>" . $subcat->getVar('description') . '</td>'; |
||
392 | echo "<td class='even' align='right'> {$modify} {$delete} </td>"; |
||
393 | echo '</tr>'; |
||
394 | } |
||
395 | } else { |
||
396 | echo '<tr>'; |
||
397 | echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOSUBCAT . '</td>'; |
||
398 | echo '</tr>'; |
||
399 | } |
||
400 | echo "</table>\n"; |
||
401 | echo "<br>\n"; |
||
402 | Publisher\Utils::closeCollapsableBar('subcatstable', 'subcatsicon'); |
||
403 | |||
404 | Publisher\Utils::openCollapsableBar('bottomtable', 'bottomtableicon', _AM_PUBLISHER_CAT_ITEMS, _AM_PUBLISHER_CAT_ITEMS_DSC); |
||
405 | $startitem = Request::getInt('startitem'); |
||
406 | // Get the total number of published ITEMS |
||
407 | $totalitems = $helper->getItemHandler()->getItemsCount($sel_cat, [_PUBLISHER_STATUS_PUBLISHED]); |
||
408 | // creating the items objects that are published |
||
409 | $itemsObj = $helper->getItemHandler()->getAllPublished($helper->getConfig('idxcat_perpage'), $startitem, $sel_cat); |
||
410 | $allcats = $helper->getCategoryHandler()->getObjects(null, true); |
||
411 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
412 | echo '<tr>'; |
||
413 | echo "<td width='40' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ITEMID . '</strong></td>'; |
||
414 | echo "<td width='20%' class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMCOLNAME . '</strong></td>'; |
||
415 | echo "<td class='bg3' align='left'><strong>" . _AM_PUBLISHER_ITEMDESC . '</strong></td>'; |
||
416 | echo "<td width='90' class='bg3' align='center'><strong>" . _AM_PUBLISHER_CREATED . '</strong></td>'; |
||
417 | echo "<td width='60' class='bg3' align='center'><strong>" . _AM_PUBLISHER_ACTION . '</strong></td>'; |
||
418 | echo '</tr>'; |
||
419 | if ($totalitems > 0) { |
||
420 | foreach ($itemsObj as $iValue) { |
||
421 | $categoryObj = $allcats[$iValue->getVar('categoryid')]; |
||
422 | $modify = "<a href='item.php?op=mod&itemid=" |
||
423 | . $iValue->getVar('itemid') |
||
424 | . "'><img src='" |
||
425 | . XoopsBaseConfig::get('url') |
||
426 | . '/modules/' |
||
427 | . $helper->getModule()->dirname() |
||
428 | . "/images/links/edit.gif' title='" |
||
429 | . _AM_PUBLISHER_EDITITEM |
||
430 | . "' alt='" |
||
431 | . _AM_PUBLISHER_EDITITEM |
||
432 | . "'></a>"; |
||
433 | $delete = "<a href='item.php?op=del&itemid=" |
||
434 | . $iValue->getVar('itemid') |
||
435 | . "'><img src='" |
||
436 | . XoopsBaseConfig::get('url') |
||
437 | . '/modules/' |
||
438 | . $helper->getModule()->dirname() |
||
439 | . "/images/links/delete.png' title='" |
||
440 | . _AM_PUBLISHER_DELETEITEM |
||
441 | . "' alt='" |
||
442 | . _AM_PUBLISHER_DELETEITEM |
||
443 | . "'></a>"; |
||
444 | echo '<tr>'; |
||
445 | echo "<td class='head' align='center'>" . $iValue->getVar('itemid') . '</td>'; |
||
446 | echo "<td class='even' align='left'>" . $categoryObj->getVar('name') . '</td>'; |
||
447 | echo "<td class='even' align='left'>" . $iValue->getitemLink() . '</td>'; |
||
448 | echo "<td class='even' align='center'>" . $iValue->datesub('s') . '</td>'; |
||
449 | echo "<td class='even' align='center'> $modify $delete </td>"; |
||
450 | echo '</tr>'; |
||
451 | } |
||
452 | } else { |
||
453 | echo '<tr>'; |
||
454 | echo "<td class='head' align='center' colspan= '7'>" . _AM_PUBLISHER_NOITEMS . '</td>'; |
||
455 | echo '</tr>'; |
||
456 | } |
||
457 | echo "</table>\n"; |
||
458 | echo "<br>\n"; |
||
459 | $parentid = Request::getInt('parentid'); |
||
460 | $pagenav_extra_args = "op=mod&categoryid=$sel_cat&parentid=$parentid"; |
||
461 | $pagenav = new XoopsPageNav($totalitems, $helper->getConfig('idxcat_perpage'), $startitem, 'startitem', $pagenav_extra_args); |
||
462 | echo '<div style="text-align:right;">' . $pagenav->renderNav() . '</div>'; |
||
463 | echo "<input type='button' name='button' onclick=\"location='item.php?op=mod&categoryid=" . $sel_cat . "'\" value='" . _AM_PUBLISHER_CREATEITEM . "'> "; |
||
464 | echo '</div>'; |
||
465 | } |
||
468 |
This function has been deprecated. The supplier of the function has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.