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