| Conditions | 13 |
| Paths | 7 |
| Total Lines | 73 |
| Code Lines | 43 |
| 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 |
||
| 42 | function xoopspoll_search($queryArray, $andor, $limit, $offset, $uid) |
||
| 43 | { |
||
| 44 | $ret = []; |
||
| 45 | if (0 === (int)$uid) { |
||
| 46 | // xoops_load('pollUtility', 'xoopspoll'); |
||
| 47 | $pollHandler = Helper::getInstance()->getHandler('Poll'); |
||
| 48 | $pollFields = ['poll_id', 'user_id', 'question', 'start_time']; |
||
| 49 | $criteria = new \CriteriaCompo(); |
||
| 50 | $criteria->add(new \Criteria('start_time', time(), '<=')); // only show polls that have started |
||
| 51 | |||
| 52 | /** |
||
| 53 | * @todo: |
||
| 54 | * find out if want to show polls that were created with a forum. If no, then change |
||
| 55 | * the link to forum topic_id |
||
| 56 | */ |
||
| 57 | |||
| 58 | /** |
||
| 59 | * check to see if we want to include polls created with forum (newbb) |
||
| 60 | */ |
||
| 61 | $configHandler = xoops_getHandler('config'); |
||
| 62 | /** @var \XoopsModuleHandler $moduleHandler */ |
||
| 63 | $moduleHandler = xoops_getHandler('module'); |
||
| 64 | $thisModule = $moduleHandler->getByDirname('xoopspoll'); |
||
| 65 | $this_module_config = $configHandler->getConfigsByCat(0, $thisModule->getVar('mid')); |
||
|
|
|||
| 66 | |||
| 67 | $pollsWithTopics = []; |
||
| 68 | if (($thisModule instanceof \XoopsModule) && $thisModule->isactive() |
||
| 69 | && $this_module_config['hide_forum_polls']) { |
||
| 70 | $newbbModule = $moduleHandler->getByDirname('newbb'); |
||
| 71 | if ($newbbModule instanceof \XoopsModule && $newbbModule->isactive()) { |
||
| 72 | /** @var Newbb\TopicHandler $topicHandler */ |
||
| 73 | $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic'); |
||
| 74 | $tFields = ['topic_id', 'poll_id']; |
||
| 75 | $tArray = $topicHandler->getAll(new \Criteria('topic_haspoll', 0, '>'), $tFields, false); |
||
| 76 | foreach ($tArray as $t) { |
||
| 77 | $pollsWithTopics[$t['poll_id']] = $t['topic_id']; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | unset($newbbModule); |
||
| 81 | } |
||
| 82 | |||
| 83 | $criteria->setSort('start_time'); |
||
| 84 | $criteria->setOrder('DESC'); |
||
| 85 | $criteria->setLimit((int)$limit); |
||
| 86 | $criteria->setStart((int)$offset); |
||
| 87 | |||
| 88 | if (is_array($queryArray) && !empty($queryArray)) { |
||
| 89 | $criteria->add(new \Criteria('question', "%{$queryArray[0]}%", 'LIKE')); |
||
| 90 | $criteria->add(new \Criteria('description', "%{$queryArray[0]}%", 'LIKE'), 'OR'); |
||
| 91 | array_shift($queryArray); //get rid of first element |
||
| 92 | |||
| 93 | foreach ($queryArray as $query) { |
||
| 94 | $criteria->add(new \Criteria('question', "%{$query}%", 'LIKE'), $andor); |
||
| 95 | $criteria->add(new \Criteria('description', "%{$query}%", 'LIKE'), 'OR'); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | $pollArray = $pollHandler->getAll($criteria, $pollFields, false); |
||
| 99 | foreach ($pollArray as $poll) { |
||
| 100 | $link = "pollresults.php?poll_id={$poll['poll_id']}"; |
||
| 101 | if (array_key_exists($poll['poll_id'], $pollsWithTopics)) { |
||
| 102 | $link = $GLOBALS['xoops']->url("modules/newbb/viewtopic.php?topic_id={$pollsWithTopics[$poll['poll_id']]}"); |
||
| 103 | } |
||
| 104 | |||
| 105 | $ret[] = [ |
||
| 106 | 'image' => 'assets/images/icons/logo_large.png', |
||
| 107 | 'link' => $link, |
||
| 108 | 'title' => $poll['question'], |
||
| 109 | 'time' => $poll['start_time'], |
||
| 110 | ]; |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | return $ret; |
||
| 115 | } |
||
| 116 |