Conditions | 30 |
Paths | 81 |
Total Lines | 287 |
Lines | 5 |
Ratio | 1.74 % |
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 |
||
282 | function render_forums($forum_guid) |
||
283 | { |
||
284 | elgg_load_css('gcforums-css'); |
||
285 | $entity = get_entity($forum_guid); |
||
286 | |||
287 | |||
288 | if ($entity instanceof ElggEntity) { |
||
289 | |||
290 | $dbprefix = elgg_get_config('dbprefix'); |
||
291 | $base_url = elgg_get_site_entity()->getURL(); |
||
292 | $group_entity = get_entity(gcforums_get_forum_in_group($entity->getGUID(), $entity->getGUID())); |
||
293 | $current_user = elgg_get_logged_in_user_entity(); |
||
294 | // set the breadcrumb trail |
||
295 | assemble_forum_breadcrumb($entity); |
||
296 | |||
297 | // forums will always remain as content within a group |
||
298 | elgg_set_page_owner_guid($group_entity->getGUID()); |
||
299 | $return = array(); |
||
300 | |||
301 | if ($forum_guid !== $group_entity->guid) |
||
302 | $content .= "<div class='forums-menu-buttons'>".gcforums_menu_buttons($entity->getGUID(), $group_entity->getGUID())."</div> "; |
||
303 | |||
304 | |||
305 | // administrative only tool to fix up all the topics that were misplaced |
||
306 | if (elgg_is_admin_logged_in()) { |
||
307 | $content .= elgg_view_form('gcforums/move_topic'); |
||
308 | } |
||
309 | |||
310 | $query = "SELECT * FROM elggentities e, elggentity_subtypes es WHERE e.subtype = es.id AND e.container_guid = {$forum_guid} AND es.subtype = 'hjforumtopic'"; |
||
311 | $topics = get_data($query); |
||
312 | |||
313 | // sort |
||
314 | usort($topics, function($a, $b) { |
||
315 | return $b->guid - $a->guid; |
||
316 | }); |
||
317 | |||
318 | if (count($topics) > 0 && !$entity->enable_posting) { |
||
319 | $content .= " |
||
320 | <div class='topic-main-box'> |
||
321 | <div style='background: #e6e6e6; width:100%;' > |
||
322 | <div class='topic-header'>".elgg_echo('gcforums:translate:hjforumtopic')." |
||
323 | <div class='topic-information'>options</div> |
||
324 | <div class='topic-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
325 | <div class='topic-information'>".elgg_echo('gcforums:translate:replies')."</div> |
||
326 | <div class='topic-information'>".elgg_echo('gcforums:translate:topic_starter')."</div> |
||
327 | </div>"; |
||
328 | |||
329 | /// topic |
||
330 | foreach ($topics as $topic) { |
||
331 | |||
332 | $topic = get_entity($topic->guid); |
||
333 | $hyperlink = "<a href='{$base_url}gcforums/topic/view/{$topic->guid}'><strong>{$topic->title}</strong></a>"; |
||
334 | if (!$topic->guid) continue; |
||
335 | $query = "SELECT e.guid, ue.username, e.time_created |
||
336 | FROM {$dbprefix}entities e, {$dbprefix}users_entity ue |
||
337 | WHERE e.container_guid = {$topic->guid} AND e.owner_guid = ue.guid"; |
||
338 | $replies = get_data($query); |
||
339 | |||
340 | |||
341 | $total_replies = count($replies); |
||
342 | $topic_starter = get_user($topic->owner_guid)->username; |
||
343 | $time_posted = $replies[$total_replies - 1]->time_created; |
||
344 | $time_posted = date('Y-m-d H:i:s', $time_posted); |
||
345 | |||
346 | $options = render_edit_options($topic->guid, $group_entity->guid); |
||
347 | if ($options == '') $options = '-'; |
||
348 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$topic->guid})" : ""; |
||
349 | $last_post = ($total_replies <= 0) ? elgg_echo('gcforums:no_posts') : "<div>{$replies[$total_replies - 1]->username}</div> <div>{$time_posted}</div>"; |
||
350 | |||
351 | $content .= " |
||
352 | <div class='topic-info-header'> |
||
353 | <div class='topic-description'>{$hyperlink} {$admin_only}</div> |
||
354 | <div class='topic-options-edit'>{$options}</div> |
||
355 | <div class='topic-options'>{$last_post}</div> |
||
356 | <div class='topic-options'>{$total_replies}</div> |
||
357 | <div class='topic-options'>{$topic_starter}</div> |
||
358 | </div>"; |
||
359 | } |
||
360 | |||
361 | $content .= "</div> </div> </p> <br/>"; |
||
362 | } |
||
363 | |||
364 | |||
365 | |||
366 | /// display the categories if the forum has this enabled |
||
367 | if ($entity->enable_subcategories || $entity instanceof ElggGroup) { |
||
368 | |||
369 | $categories = elgg_get_entities(array( |
||
370 | 'types' => 'object', |
||
371 | 'subtypes' => 'hjforumcategory', |
||
372 | 'limit' => false, |
||
373 | 'container_guid' => $forum_guid |
||
374 | )); |
||
375 | |||
376 | /// category |
||
377 | foreach ($categories as $category) { |
||
378 | $options = render_edit_options($category->guid, $group_entity->getGUID()); |
||
379 | if ($options == '') $options = '-'; |
||
380 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$category->guid})" : ""; |
||
381 | $content .= " |
||
382 | <p> |
||
383 | <div class='category-main-box'> |
||
384 | <div class='category-options'>{$options} {$admin_only}</div> |
||
385 | <h1>{$category->title}</h1> |
||
386 | <div class='category-description'>{$category->description}</div> |
||
387 | </div>"; |
||
388 | |||
389 | |||
390 | $forums = elgg_get_entities_from_relationship(array( |
||
391 | 'relationship' => 'filed_in', |
||
392 | 'relationship_guid' => $category->getGUID(), |
||
393 | 'container_guid' => $entity->getGUID(), |
||
394 | 'inverse_relationship' => true, |
||
395 | 'limit' => false |
||
396 | )); |
||
397 | |||
398 | if (sizeof($forums) > 0) { |
||
399 | |||
400 | $content .= "<div class='forum-main-box'> |
||
401 | <div style='background: #e6e6e6; width:100%;' > |
||
402 | <div class='forum-header'>Forum |
||
403 | <div class='forum-information'>options</div> |
||
404 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_topics')."</div> |
||
405 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_replies')."</div> |
||
406 | <div class='forum-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
407 | </div>"; |
||
408 | |||
409 | /// forums |
||
410 | foreach ($forums as $forum) { |
||
411 | $total_topics = get_forums_statistics_information($forum->guid, TOTAL_TOPICS); |
||
412 | $total_posts = get_forums_statistics_information($forum->guid, TOTAL_POST); |
||
413 | $recent_post = get_forums_statistics_information($forum->guid, RECENT_POST); |
||
414 | $options = render_edit_options($forum->getGUID(), $group_entity->getGUID()); |
||
415 | |||
416 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$forum->guid})" : ""; |
||
417 | |||
418 | $hyperlink = "<a href='{$base_url}gcforums/view/{$forum->getGUID()}'><strong>{$forum->title}</strong></a>"; |
||
419 | |||
420 | $content .= "<div class='forum-info-header'> |
||
421 | <div class='forum-description'>{$hyperlink} {$admin_only} |
||
422 | <div class='forum-description-text'>{$forum->description}</div> |
||
423 | </div> |
||
424 | <div class='forum-options-edit'>{$options}</div> |
||
425 | <div class='forum-options'>{$total_topics}</div> |
||
426 | <div class='forum-options'>{$total_posts}</div> |
||
427 | <div class='forum-options'>{$recent_post}</div> |
||
428 | </div>"; |
||
429 | } |
||
430 | $content .= "</div> </div> </p> <br/>"; |
||
431 | |||
432 | } else { |
||
433 | $content .= "<div class='forum-empty'>".elgg_echo('gcforums:forums_not_available')."</div>"; |
||
434 | } |
||
435 | } |
||
436 | |||
437 | |||
438 | if (elgg_is_admin_logged_in() /*|| $group_entity->getOwnerGUID() == $current_user->guid || check_entity_relationship($current_user->getGUID(), 'operator', $group_entity->getGUID())*/) { |
||
439 | |||
440 | /// there are the problem where user creates forum in the existing forum with categories enabled, show the forums without categories |
||
441 | $forums = elgg_get_entities_from_relationship(array( |
||
442 | 'relationship' => 'descendant', |
||
443 | 'container_guid' => $forum_guid, |
||
444 | 'subtypes' => array('hjforum'), |
||
445 | 'relationship_guid' => $forum_guid, |
||
446 | 'inverse_relationship' => true, |
||
447 | 'types' => 'object', |
||
448 | 'limit' => 0, |
||
449 | )); |
||
450 | |||
451 | if (sizeof($forums) > 0) { |
||
452 | |||
453 | $content .= " |
||
454 | <div class='forum-category-issue-notice'> |
||
455 | <section class='alert alert-danger'> |
||
456 | <strong>This only shows up for administrators</strong>. |
||
457 | If you don't see a specific forum appearing above, you can correct that by editing the forums below. |
||
458 | </section> |
||
459 | <div class='forum-main-box'> |
||
460 | <div style='background: #e6e6e6; width:100%;' > |
||
461 | <div class='forum-header'>Forum |
||
462 | <div class='forum-information'>options</div> |
||
463 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_topics')."</div> |
||
464 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_replies')."</div> |
||
465 | <div class='forum-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
466 | </div>"; |
||
467 | |||
468 | foreach ($forums as $forum) { |
||
469 | |||
470 | $query = "SELECT COUNT(guid_one) AS total FROM elggentity_relationships WHERE guid_one = '{$forum->guid}' AND relationship = 'filed_in' AND guid_two = 0"; |
||
471 | $is_filed_in_category = get_data($query); |
||
472 | |||
473 | //if ($is_filed_in_category[0]->total == 1) { |
||
474 | |||
475 | $total_topics = get_forums_statistics_information($forum->guid, TOTAL_TOPICS); |
||
476 | $total_posts = get_forums_statistics_information($forum->guid, TOTAL_POST); |
||
477 | $recent_post = get_forums_statistics_information($forum->guid, RECENT_POST); |
||
478 | $options = render_edit_options($forum->getGUID(), $group_entity->getGUID()); |
||
479 | if ($options == '') $options = '-'; |
||
480 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$forum->guid})" : ""; |
||
481 | $hyperlink = "<a href='{$base_url}gcforums/view/{$forum->getGUID()}'><strong>{$forum->title}</strong></a>"; |
||
482 | |||
483 | $content .= " |
||
484 | <div class='forum-info-header'> |
||
485 | <div class='forum-description'>{$hyperlink} {$admin_only} |
||
486 | <div class='forum-description-text'>{$forum->description}</div> |
||
487 | </div> |
||
488 | <div class='forum-options-edit'>{$options}</div> |
||
489 | <div class='forum-options'>{$total_topics}</div> |
||
490 | <div class='forum-options'>{$total_posts}</div> |
||
491 | <div class='forum-options'>{$recent_post}</div> |
||
492 | </div>"; |
||
493 | //} |
||
494 | } |
||
495 | |||
496 | $content .= "</div> </div> </div> </p> <br/>"; |
||
497 | } |
||
498 | } |
||
499 | |||
500 | |||
501 | |||
502 | } else { |
||
503 | |||
504 | /// display forums with no categories |
||
505 | $forums = elgg_get_entities_from_relationship(array( |
||
506 | 'relationship' => 'descendant', |
||
507 | 'subtypes' => array('hjforum'), |
||
508 | 'relationship_guid' => $forum_guid, |
||
509 | 'inverse_relationship' => true, |
||
510 | 'types' => 'object', |
||
511 | 'limit' => 0, |
||
512 | )); |
||
513 | |||
514 | if (sizeof($forums) > 0) { |
||
515 | $content .= " |
||
516 | <div class='forum-main-box'> |
||
517 | <div style='background: #e6e6e6; width:100%;' > |
||
518 | <div class='forum-header'>Forum |
||
519 | <div class='forum-information'>options</div> |
||
520 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_topics')."</div> |
||
521 | <div class='forum-information'>".elgg_echo('gcforums:translate:total_replies')."</div> |
||
522 | <div class='forum-information'>".elgg_echo('gcforums:translate:last_posted')."</div> |
||
523 | </div>"; |
||
524 | |||
525 | foreach ($forums as $forum) { |
||
526 | |||
527 | if ($forum->getContainerGUID() != $entity->getGUID()) continue; |
||
528 | |||
529 | $total_topics = get_forums_statistics_information($forum->guid, TOTAL_TOPICS); |
||
530 | $total_posts = get_forums_statistics_information($forum->guid, TOTAL_POST); |
||
531 | $recent_post = get_forums_statistics_information($forum->guid, RECENT_POST); |
||
532 | $options = render_edit_options($forum->getGUID(), $group_entity->getGUID()); |
||
533 | if ($options == '') $options = '-'; |
||
534 | $hyperlink = "<a href='{$base_url}gcforums/view/{$forum->getGUID()}'><strong>{$forum->title}</strong></a>"; |
||
535 | $admin_only = (elgg_is_admin_logged_in()) ? "(guid:{$forum->guid})" : ""; |
||
536 | |||
537 | $content .= " |
||
538 | <div class='forum-info-header'> |
||
539 | <div class='forum-description'>{$hyperlink} {$admin_only} |
||
540 | <div class='forum-description-text'>{$forum->description}</div> |
||
541 | </div> |
||
542 | <div class='forum-options-edit'>{$options}</div> |
||
543 | <div class='forum-options'>{$total_topics}</div> |
||
544 | <div class='forum-options'>{$total_posts}</div> |
||
545 | <div class='forum-options'>{$recent_post}</div> |
||
546 | </div>"; |
||
547 | } |
||
548 | |||
549 | $content .= "</div> </div> </p> <br/>"; |
||
550 | } |
||
551 | } |
||
552 | |||
553 | $title = $entity->title; |
||
554 | if (!$title) $title = elgg_echo('gcforum:heading:default_title'); |
||
555 | |||
556 | |||
557 | $return['filter'] = ''; |
||
558 | $return['title'] = gc_explode_translation($title, get_current_language()); |
||
559 | $return['content'] = $content; |
||
560 | |||
561 | View Code Duplication | } else { |
|
562 | $return['filter'] = ''; |
||
563 | $return['title'] = '404 - '.elgg_echo('gcforums:notfound'); |
||
564 | $return['content'] = elgg_echo('gcforums:notfound'); |
||
565 | } |
||
566 | |||
567 | return $return; |
||
568 | } |
||
569 | |||
798 |
This check looks for function calls that miss required arguments.