Code Duplication    Length = 30-34 lines in 2 locations

main/forum/forumfunction.inc.php 2 locations

@@ 1530-1563 (lines=34) @@
1527
                GROUP BY threads.forum_id";
1528
1529
        // Course Admin
1530
        if (api_is_allowed_to_edit()) {
1531
            // Select all the forum information of all forums (that are not deleted).
1532
            $sql = "SELECT item_properties.*, forum.* 
1533
                    FROM $table_forums forum
1534
                    INNER JOIN $table_item_property item_properties
1535
                    ON (
1536
                        forum.forum_id = item_properties.ref AND
1537
                        forum.c_id = item_properties.c_id
1538
                    )
1539
                    WHERE
1540
                        item_properties.visibility <> 2 AND
1541
                        item_properties.tool = '".TOOL_FORUM."'
1542
                        $condition_session AND
1543
                        forum.c_id = $course_id AND
1544
                        item_properties.c_id = $course_id
1545
                        $includeGroupsForumSelect
1546
                    ORDER BY forum_order ASC";
1547
1548
            // Select the number of threads of the forums (only the threads that are not deleted).
1549
            $sql2 = "SELECT count(*) AS number_of_threads, threads.forum_id
1550
                    FROM $table_threads threads
1551
                    INNER JOIN $table_item_property item_properties
1552
                    ON (
1553
                        threads.thread_id = item_properties.ref AND
1554
                        threads.c_id = item_properties.c_id
1555
                        $sessionIdLink
1556
                    )
1557
                    WHERE
1558
                        item_properties.visibility<>2 AND
1559
                        item_properties.tool='".TOOL_FORUM_THREAD."' AND
1560
                        threads.c_id = $course_id AND
1561
                        item_properties.c_id = $course_id
1562
                    GROUP BY threads.forum_id";
1563
        }
1564
    } else {
1565
        // GETTING ONE SPECIFIC FORUM
1566
        /* We could do the splitup into student and course admin also but we want
@@ 4985-5014 (lines=30) @@
4982
            GROUP BY threads.forum_id";
4983
4984
    // Course Admin
4985
    if (api_is_allowed_to_edit()) {
4986
        // Select all the forum information of all forums (that are not deleted).
4987
        $sql = "SELECT *
4988
                FROM $table_forums forum INNER JOIN $table_item_property item_properties
4989
                ON (forum.forum_id = item_properties.ref AND item_properties.c_id = forum.c_id)
4990
                WHERE
4991
                    forum.forum_of_group = $groupId AND
4992
                    forum.c_id = $course_id AND
4993
                    item_properties.c_id = $course_id AND                    
4994
                    item_properties.visibility <> 2 AND
4995
                    item_properties.tool = '".TOOL_FORUM."'
4996
                ORDER BY forum_order ASC";
4997
4998
        // Select the number of threads of the forums (only the threads that are not deleted).
4999
        $sql2 = "SELECT count(thread_id) AS number_of_threads, threads.forum_id
5000
                 FROM $table_threads threads INNER JOIN $table_item_property item_properties
5001
                 ON (threads.thread_id=item_properties.ref AND item_properties.c_id = threads.c_id)
5002
                 WHERE
5003
                    threads.c_id = $course_id AND
5004
                    item_properties.c_id = $course_id AND
5005
                    item_properties.visibility <> 2 AND
5006
                    item_properties.tool='".TOOL_FORUM_THREAD."'
5007
                GROUP BY threads.forum_id";
5008
        // Select the number of posts of the forum.
5009
        $sql3 = "SELECT count(post_id) AS number_of_posts, forum_id
5010
                FROM $table_posts
5011
                WHERE c_id = $course_id 
5012
                GROUP BY forum_id";
5013
    }
5014
5015
    // Handling all the forum information.
5016
    $result = Database::query($sql);
5017
    $forum_list = array();