| Conditions | 10 |
| Paths | 192 |
| Total Lines | 116 |
| Code Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 31 | function editfaq($faqid = '') |
||
| 32 | { |
||
| 33 | global $answerHandler, $xoopsUser, $xoopsUser, $xoopsConfig, $xoopsDB, $modify, $xoopsModuleConfig, $xoopsModule, $XOOPS_URL, $myts, $pathIcon16, $smartModuleConfig; |
||
| 34 | |||
| 35 | require_once XOOPS_ROOT_PATH . '/class/xoopsformloader.php'; |
||
|
|
|||
| 36 | |||
| 37 | // Creating the FAQ object |
||
| 38 | $faqObj = new Smartfaq\Faq($faqid); |
||
| 39 | |||
| 40 | // Creating the category object |
||
| 41 | $categoryObj = $faqObj->category(); |
||
| 42 | |||
| 43 | if ($faqObj->notLoaded()) { |
||
| 44 | redirect_header('index.php', 1, _AM_SF_NOFAQSELECTED); |
||
| 45 | } |
||
| 46 | |||
| 47 | switch ($faqObj->status()) { |
||
| 48 | |||
| 49 | case Constants::SF_STATUS_ANSWERED: |
||
| 50 | $breadcrumb_action1 = _AM_SF_SUBMITTED; |
||
| 51 | $breadcrumb_action2 = _AM_SF_APPROVING; |
||
| 52 | $collapsableBar_title = _AM_SF_SUBMITTED_TITLE; |
||
| 53 | $collapsableBar_info = _AM_SF_SUBMITTED_INFO; |
||
| 54 | $button_caption = _AM_SF_APPROVE; |
||
| 55 | $an_status = Constants::SF_AN_STATUS_PROPOSED; |
||
| 56 | break; |
||
| 57 | |||
| 58 | } |
||
| 59 | |||
| 60 | $module_id = $xoopsModule->getVar('mid'); |
||
| 61 | $gpermHandler = xoops_getHandler('groupperm'); |
||
| 62 | $groups = $xoopsUser ? $xoopsUser->getGroups() : XOOPS_GROUP_ANONYMOUS; |
||
| 63 | |||
| 64 | if (!Smartfaq\Utility::userIsAdmin() |
||
| 65 | && (!$gpermHandler->checkRight('category_admin', $faqObj->categoryid(), $groups, $module_id))) { |
||
| 66 | redirect_header('javascript:history.go(-1)', 1, _NOPERM); |
||
| 67 | } |
||
| 68 | // Retreiving the official answer |
||
| 69 | $official_answer = $faqObj->answer(); |
||
| 70 | |||
| 71 | Smartfaq\Utility::collapsableBar('bottomtable', 'bottomtableicon'); |
||
| 72 | echo "<img id='bottomtableicon' src=" . XOOPS_URL . '/modules/' . $xoopsModule->dirname() . "/assets/images/icon/close12.gif alt=''></a> " . _AM_SF_SUBMITTED_ANSWER . '</h3>'; |
||
| 73 | echo "<div id='bottomtable'>"; |
||
| 74 | echo '<span style="color: #567; margin: 3px 0 12px 0; font-size: small; display: block; ">' . _AM_SF_SUBMITTED_ANSWER_INFO . '</span>'; |
||
| 75 | |||
| 76 | $proposed_answers = $answerHandler->getAllAnswers($faqid, Constants::SF_AN_STATUS_PROPOSED); |
||
| 77 | |||
| 78 | if (0 == count($proposed_answers)) { |
||
| 79 | redirect_header('index.php', 1, _AM_SF_NOANSWERS); |
||
| 80 | } |
||
| 81 | |||
| 82 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer> |
||
| 83 | <tr> |
||
| 84 | <td class='head' width='100px'>" . _AM_SF_CATEGORY . "</td> |
||
| 85 | <td class='even'>" . $categoryObj->name() . "</td> |
||
| 86 | </tr> |
||
| 87 | <tr> |
||
| 88 | <td class='head' width='100px'>" . _AM_SF_QUESTION . "</td> |
||
| 89 | <td class='even'>" . $faqObj->question() . '</td> |
||
| 90 | </tr>'; |
||
| 91 | if ($official_answer) { |
||
| 92 | echo " |
||
| 93 | <tr> |
||
| 94 | <td class='head' width='100px'>" . _AM_SF_ANSWER_OFFICIAL . "</td> |
||
| 95 | <td class='even'>" . $official_answer->answer() . '</td> |
||
| 96 | </tr>'; |
||
| 97 | } |
||
| 98 | echo "</table><br>\n"; |
||
| 99 | |||
| 100 | echo "<table width='100%' cellspacing=1 cellpadding=3 border=0 class = outer>"; |
||
| 101 | echo '<tr>'; |
||
| 102 | echo "<th width='40' class='bg3' align='center'><b>" . _AM_SF_ARTID . '</b></td>'; |
||
| 103 | echo "<th class='bg3' class='bg3' align='center'><b>" . _AM_SF_ANSWER . '</b></td>'; |
||
| 104 | |||
| 105 | echo "<th width='90' class='bg3' align='center'><b>" . _AM_SF_ANSWERED . '</b></td>'; |
||
| 106 | |||
| 107 | echo "<th width='180' class='bg3' align='center'><b>" . _AM_SF_CREATED . '</b></td>'; |
||
| 108 | echo "<th width='120' class='bg3' align='center'><b>" . _AM_SF_ACTION . '</b></td>'; |
||
| 109 | echo '</tr>'; |
||
| 110 | |||
| 111 | $merge = ''; |
||
| 112 | $modify = ''; |
||
| 113 | $approve = ''; |
||
| 114 | foreach ($proposed_answers as $proposed_answer) { |
||
| 115 | if (Constants::SF_STATUS_NEW_ANSWER == $faqObj->status()) { |
||
| 116 | $merge = "<a href='faq.php?op=merge&faqid=" |
||
| 117 | . $faqObj->faqid() |
||
| 118 | . '&answerid=' |
||
| 119 | . $proposed_answer->answerid() |
||
| 120 | . "'><img src='" |
||
| 121 | . XOOPS_URL |
||
| 122 | . '/modules/' |
||
| 123 | . $xoopsModule->dirname() |
||
| 124 | . "/assets/images/icon/merge.gif' title='" |
||
| 125 | . _AM_SF_FAQ_MERGE |
||
| 126 | . "' alt='" |
||
| 127 | . _AM_SF_FAQ_MERGE |
||
| 128 | . "'></a> "; |
||
| 129 | $approve = "<a href='answer.php?op=selectanswer&faqid=" . $faqid . '&answerid=' . $proposed_answer->answerid() . "'><img src='" . $pathIcon16 . '/on.png' . "' title='" . _AM_SF_FAQ_APPROVE_NEW_ANSWER . "' alt='" . _AM_SF_APPROVESUB . "'></a>"; |
||
| 130 | } |
||
| 131 | $modify = "<a href='faq.php?op=mod&faqid=" . $faqObj->faqid() . '&answerid=' . $proposed_answer->answerid() . "'><img src='" . $pathIcon16 . '/edit.png' . "' title='" . _AM_SF_FAQ_REVIEW . "' alt='" . _AM_SF_FAQ_REVIEW . "'></a> "; |
||
| 132 | $delete = "<a href='answer.php?op=del&faqid=" . $faqObj->faqid() . '&answerid=' . $proposed_answer->answerid() . "'><img src='" . $pathIcon16 . '/delete.png' . "' title='" . _AM_SF_DELETESUBM . "' alt='" . _AM_SF_DELETESUBM . "'></a>"; |
||
| 133 | echo '<tr>'; |
||
| 134 | echo "<td class='head' align='center'>" . $proposed_answer->answerid() . '</td>'; |
||
| 135 | echo "<td class='even' align='left'>" . $proposed_answer->answer() . '</td>'; |
||
| 136 | |||
| 137 | //show name of the answer submitter |
||
| 138 | $submitter = Smartfaq\Utility::getLinkedUnameFromId($proposed_answer->uid(), $smartModuleConfig['userealname']); |
||
| 139 | echo "<td class='even' align='center'>" . $submitter . '</td>'; |
||
| 140 | |||
| 141 | echo "<td class='even' align='center'>" . $proposed_answer->datesub() . '</td>'; |
||
| 142 | echo "<td class='even' align='center'> $merge $modify $approve $delete </td>"; |
||
| 143 | echo '</tr>'; |
||
| 144 | } |
||
| 145 | |||
| 146 | echo "</table>\n<br>"; |
||
| 147 | } |
||
| 292 |