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