| Conditions | 16 |
| Paths | 80 |
| Total Lines | 106 |
| Code Lines | 62 |
| Lines | 28 |
| Ratio | 26.42 % |
| 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 |
||
| 205 | * @return string HTML form for display by block admin |
||
| 206 | * @global mixed $GLOBALS ['xoopsUser'] |
||
| 207 | * @uses xoops_getModuleHandler() function to get class handler for this modules class(es) |
||
| 208 | */ |
||
| 209 | function xoopspollBlockSinglepollEdit($options) |
||
| 210 | { |
||
| 211 | /** |
||
| 212 | * Options[] |
||
| 213 | * 0 = show expired polls in block |
||
| 214 | * 1 = poll id to show |
||
| 215 | * if hiding expired poll then the next non-expired poll |
||
| 216 | * will show if the selected poll is hidden |
||
| 217 | * 2 = show results button in block |
||
| 218 | * 3 = show options as list|select |
||
| 219 | */ |
||
| 220 | |||
| 221 | // find out if want to show expired polls in block |
||
| 222 | // (otherwise it will hide block once it expires) |
||
| 223 | if (0 === $options[0]) { |
||
| 224 | $chk0no = ' checked'; |
||
| 225 | $chk0yes = ''; |
||
| 226 | } else { |
||
| 227 | $chk0no = ''; |
||
| 228 | $chk0yes = ' checked'; |
||
| 229 | } |
||
| 230 | $form = "<table><tr><td class='width25 middle'>" |
||
| 231 | . _MB_XOOPSPOLL_SHOW_EXP |
||
| 232 | . ':</td><td>' |
||
| 233 | . "<label class='middle' for='yes'>" |
||
| 234 | . _YES |
||
| 235 | . "</label>\n" |
||
| 236 | . "<input type='radio' name='options[0]' value='1'{$chk0yes} id='yes'>\n" |
||
| 237 | . "<label class='middle' style='margin-left: 2em;' for='no'> " |
||
| 238 | . _NO |
||
| 239 | . "</label>\n" |
||
| 240 | . "<input type='radio' name='options[0]' value='0'{$chk0no} id='no'>\n" |
||
| 241 | . "</td></tr>\n"; |
||
| 242 | |||
| 243 | $pollHandler = Helper::getInstance()->getHandler('Poll'); |
||
| 244 | $pollFields = ['poll_id', 'start_time', 'end_time', 'question', 'weight']; |
||
| 245 | $criteria = new \CriteriaCompo(); |
||
| 246 | // $criteria->add(new \Criteria('end_time', time(), '>')); |
||
| 247 | $criteria->setOrder('ASC'); |
||
| 248 | $criteria->setSort('weight'); |
||
| 249 | /** |
||
| 250 | * Note that you can select polls that have not started yet so they will automatically show |
||
| 251 | * up in the block once they have started. To only allow selection of active polls uncomment |
||
| 252 | * the following line in the code - this could be made a module config option if desired |
||
| 253 | */ // $criteria->add(new \Criteria('start_time', time(), '<=')); |
||
| 254 | /** |
||
| 255 | * now check to see if we want to hide polls that were created using newbb |
||
| 256 | */ |
||
| 257 | $configHandler = xoops_getHandler('config'); |
||
| 258 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 259 | $moduleHandler = xoops_getHandler('module'); |
||
| 260 | $thisModule = $moduleHandler->getByDirname('xoopspoll'); |
||
| 261 | $this_module_config = $configHandler->getConfigsByCat(0, $thisModule->getVar('mid')); |
||
| 262 | |||
| 263 | if ($this_module_config['hide_forum_polls'] && ($thisModule instanceof \XoopsModule) && $thisModule->isactive()) { |
||
| 264 | $newbbModule = $moduleHandler->getByDirname('newbb'); |
||
| 265 | if ($newbbModule instanceof \XoopsModule && $newbbModule->isactive()) { |
||
| 266 | /** @var Newbb\TopicHandler $topicHandler */ |
||
| 267 | $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||
| 268 | $tFields = ['topic_id', 'poll_id']; |
||
| 269 | $tArray = $topicHandler->getAll(new \Criteria('topic_haspoll', 0, '>'), $tFields, false); |
||
| 270 | if (!empty($tArray)) { |
||
| 271 | $tcriteria = []; |
||
| 272 | foreach ($tArray as $t) { |
||
| 273 | $tcriteria[] = $t['poll_id']; |
||
| 274 | } |
||
| 275 | if (!empty($tcriteria)) { |
||
| 276 | $tstring = '(' . implode(',', $tcriteria) . ')'; |
||
| 277 | $criteria->add(new \Criteria('poll_id', $tstring, 'NOT IN')); |
||
| 278 | } |
||
| 279 | } |
||
| 280 | unset($topicHandler, $tFields, $tArray); |
||
| 281 | } |
||
| 282 | unset($newbbModule); |
||
| 283 | } |
||
| 284 | |||
| 285 | $allPollsArray = $pollHandler->getAll($criteria, $pollFields, false); |
||
| 286 | |||
| 287 | // next get a list of all available polls for select box |
||
| 288 | $form .= '<tr><td>' . _MB_XOOPSPOLL_POLLS . ":</td><td style='text-align: left; margin-left: 1em;'>\n"; |
||
| 289 | if (empty($allPollsArray)) { |
||
| 290 | $form .= "<span class='errorMsg'>" . _MB_XOOPSPOLL_NONE_ACTIVE . '</span>'; |
||
| 291 | } else { |
||
| 292 | $form .= "<select name='options[1]'>\n"; |
||
| 293 | foreach ($allPollsArray as $thisPoll) { |
||
| 294 | $selected = ($thisPoll['poll_id'] === $options[1]) ? ' selected' : ''; |
||
| 295 | $taggedQuestion = ($thisPoll['end_time'] < time()) ? $thisPoll['question'] . '**' : $thisPoll['question']; |
||
| 296 | $form .= " <option value='" . $thisPoll['poll_id'] . "'{$selected}>" . $taggedQuestion . "</option>\n"; |
||
| 297 | } |
||
| 298 | $form .= "</select>\n" . ' ** - ' . _MB_XOOPSPOLL_EXPIRED_INDICATOR . "\n"; |
||
| 299 | } |
||
| 300 | if (0 === $options[2]) { |
||
| 301 | $chk2no = ' checked'; |
||
| 302 | $chk2yes = ''; |
||
| 303 | } else { |
||
| 304 | $chk2no = ''; |
||
| 305 | $chk2yes = ' checked'; |
||
| 306 | } |
||
| 307 | $form .= "</td></tr>\n" |
||
| 308 | . "<tr><td class='width25 middle'>" |
||
| 309 | . _MB_XOOPSPOLL_SHOW_RESULT_LINK |
||
| 310 | . ':</td><td>' |
||
| 311 | . "<label class='middle' for='yesr'>" |
||
| 349 |