Code Duplication    Length = 23-26 lines in 2 locations

main/forum/forumfunction.inc.php 2 locations

@@ 3830-3855 (lines=26) @@
3827
3828
    $course_id = api_get_course_int_id();
3829
3830
    if (api_is_allowed_to_edit(null, true)) {
3831
        $sql = "SELECT count(*) as number_of_posts
3832
                FROM $table_posts posts, $table_threads threads, $table_item_property item_property
3833
                WHERE
3834
                posts.c_id = $course_id AND
3835
                item_property.c_id = $course_id AND
3836
                posts.forum_id='".Database::escape_string($forum_id)."'
3837
                AND posts.thread_id=threads.thread_id
3838
                AND item_property.ref=threads.thread_id
3839
                AND item_property.visibility<>2
3840
                AND item_property.tool='".TOOL_FORUM_THREAD."'
3841
                ";
3842
    } else {
3843
        $sql = "SELECT count(*) as number_of_posts
3844
                FROM $table_posts posts, $table_threads threads, $table_item_property item_property
3845
                WHERE
3846
                posts.c_id = $course_id AND
3847
                item_property.c_id = $course_id AND
3848
                posts.forum_id='".Database::escape_string($forum_id)."'
3849
                AND posts.thread_id=threads.thread_id
3850
                AND item_property.ref=threads.thread_id
3851
                AND item_property.visibility=1
3852
                AND posts.visible=1
3853
                AND item_property.tool='".TOOL_FORUM_THREAD."'
3854
                ";
3855
    }
3856
    $result = Database::query($sql);
3857
    $row = Database::fetch_array($result);
3858
    $number_of_posts = $row['number_of_posts'];
@@ 3861-3883 (lines=23) @@
3858
    $number_of_posts = $row['number_of_posts'];
3859
3860
    // We could loop through the result array and count the number of different group_ids, but I have chosen to use a second sql statement.
3861
    if (api_is_allowed_to_edit(null, true)) {
3862
        $sql = "SELECT count(*) as number_of_topics
3863
                FROM $table_threads threads, $table_item_property item_property
3864
                WHERE
3865
                threads.c_id = $course_id AND
3866
                item_property.c_id = $course_id AND
3867
                threads.forum_id='".Database::escape_string($forum_id)."'
3868
                AND item_property.ref=threads.thread_id
3869
                AND item_property.visibility<>2
3870
                AND item_property.tool='".TOOL_FORUM_THREAD."'
3871
                ";
3872
    } else {
3873
        $sql = "SELECT count(*) as number_of_topics
3874
                FROM $table_threads threads, $table_item_property item_property
3875
                WHERE
3876
                threads.c_id = $course_id AND
3877
                item_property.c_id = $course_id AND
3878
                threads.forum_id='".Database::escape_string($forum_id)."'
3879
                AND item_property.ref=threads.thread_id
3880
                AND item_property.visibility=1
3881
                AND item_property.tool='".TOOL_FORUM_THREAD."'
3882
                ";
3883
    }
3884
    $result = Database::query($sql);
3885
    $row = Database::fetch_array($result);
3886
    $number_of_topics = $row['number_of_topics'];