Conditions | 14 |
Paths | 152 |
Total Lines | 78 |
Code Lines | 58 |
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 |
||
196 | public function buildDigest(\XoopsObject $digest) |
||
197 | { |
||
198 | global $xoopsModule; |
||
199 | |||
200 | if (!\defined('SUMMARY_LENGTH')) { |
||
201 | \define('SUMMARY_LENGTH', 100); |
||
202 | } |
||
203 | |||
204 | /** @var Newbb\ForumHandler $forumHandler */ |
||
205 | $forumHandler = \XoopsModules\Newbb\Helper::getInstance()->getHandler('Forum'); |
||
206 | $thisUser = $GLOBALS['xoopsUser']; |
||
207 | $GLOBALS['xoopsUser'] = null; // To get posts accessible by anonymous |
||
208 | $GLOBALS['xoopsUser'] = $thisUser; |
||
209 | |||
210 | $accessForums = $forumHandler->getIdsByPermission(); // get all accessible forums |
||
211 | $forumCriteria = ' AND t.forum_id IN (' . \implode(',', $accessForums) . ')'; |
||
212 | $approveCriteria = ' AND t.approved = 1 AND p.approved = 1'; |
||
213 | $time_criteria = ' AND t.digest_time > ' . $this->last_digest; |
||
214 | |||
215 | $karma_criteria = $GLOBALS['xoopsModuleConfig']['enable_karma'] ? ' AND p.post_karma=0' : ''; |
||
216 | $reply_criteria = $GLOBALS['xoopsModuleConfig']['allow_require_reply'] ? ' AND p.require_reply=0' : ''; |
||
217 | |||
218 | $query = 'SELECT t.topic_id, t.forum_id, t.topic_title, t.topic_time, t.digest_time, p.uid, p.poster_name, pt.post_text FROM ' |
||
219 | . $this->db->prefix('newbb_topics') |
||
220 | . ' t, ' |
||
221 | . $this->db->prefix('newbb_posts_text') |
||
222 | . ' pt, ' |
||
223 | . $this->db->prefix('newbb_posts') |
||
224 | . ' p WHERE t.topic_digest = 1 AND p.topic_id=t.topic_id AND p.pid=0 ' |
||
225 | . $forumCriteria |
||
226 | . $approveCriteria |
||
227 | . $time_criteria |
||
228 | . $karma_criteria |
||
229 | . $reply_criteria |
||
230 | . ' AND pt.post_id=p.post_id ORDER BY t.digest_time DESC'; |
||
231 | if (!$result = $this->db->query($query)) { |
||
232 | //echo "<br>No result:<br>$query"; |
||
233 | return false; |
||
234 | } |
||
235 | $rows = []; |
||
236 | $users = []; |
||
237 | while (false !== ($row = $this->db->fetchArray($result))) { |
||
238 | $users[$row['uid']] = 1; |
||
239 | $rows[] = $row; |
||
240 | } |
||
241 | if (\count($rows) < 1) { |
||
242 | return false; |
||
243 | } |
||
244 | $uids = \array_keys($users); |
||
245 | if (\count($uids) > 0) { |
||
246 | /** @var \XoopsMemberHandler $memberHandler */ |
||
247 | $memberHandler = \xoops_getHandler('member'); |
||
248 | $user_criteria = new \Criteria('uid', '(' . \implode(',', $uids) . ')', 'IN'); |
||
249 | $users = $memberHandler->getUsers($user_criteria, true); |
||
250 | } else { |
||
251 | $users = []; |
||
252 | } |
||
253 | |||
254 | foreach ($rows as $topic) { |
||
255 | if ($topic['uid'] > 0) { |
||
256 | if (isset($users[$topic['uid']]) && \is_object($users[$topic['uid']]) |
||
257 | && $users[$topic['uid']]->isActive()) { |
||
258 | $topic['uname'] = $users[$topic['uid']]->getVar('uname'); |
||
259 | } else { |
||
260 | $topic['uname'] = $GLOBALS['xoopsConfig']['anonymous']; |
||
261 | } |
||
262 | } else { |
||
263 | $topic['uname'] = $topic['poster_name'] ?: $GLOBALS['xoopsConfig']['anonymous']; |
||
264 | } |
||
265 | $summary = \Xmf\Metagen::generateDescription($topic['post_text'], SUMMARY_LENGTH); |
||
266 | $author = $topic['uname'] . ' (' . \formatTimestamp($topic['topic_time']) . ')'; |
||
267 | $link = XOOPS_URL . '/modules/' . $xoopsModule->dirname() . '/viewtopic.php?topic_id=' . $topic['topic_id'] . '&forum=' . $topic['forum_id']; |
||
268 | $title = $topic['topic_title']; |
||
269 | $digest->addItem($title, $link, $author, $summary); |
||
270 | } |
||
271 | $digest->buildContent(); |
||
272 | |||
273 | return true; |
||
274 | } |
||
276 |