Code Duplication    Length = 30-34 lines in 2 locations

main/forum/forumfunction.inc.php 2 locations

@@ 1529-1562 (lines=34) @@
1526
                GROUP BY threads.forum_id";
1527
1528
        // Course Admin
1529
        if (api_is_allowed_to_edit()) {
1530
            // Select all the forum information of all forums (that are not deleted).
1531
            $sql = "SELECT item_properties.*, forum.* 
1532
                    FROM $table_forums forum
1533
                    INNER JOIN $table_item_property item_properties
1534
                    ON (
1535
                        forum.forum_id = item_properties.ref AND
1536
                        forum.c_id = item_properties.c_id
1537
                    )
1538
                    WHERE
1539
                        item_properties.visibility <> 2 AND
1540
                        item_properties.tool = '".TOOL_FORUM."'
1541
                        $condition_session AND
1542
                        forum.c_id = $course_id AND
1543
                        item_properties.c_id = $course_id
1544
                        $includeGroupsForumSelect
1545
                    ORDER BY forum_order ASC";
1546
1547
            // Select the number of threads of the forums (only the threads that are not deleted).
1548
            $sql2 = "SELECT count(*) AS number_of_threads, threads.forum_id
1549
                    FROM $table_threads threads
1550
                    INNER JOIN $table_item_property item_properties
1551
                    ON (
1552
                        threads.thread_id = item_properties.ref AND
1553
                        threads.c_id = item_properties.c_id
1554
                        $sessionIdLink
1555
                    )
1556
                    WHERE
1557
                        item_properties.visibility<>2 AND
1558
                        item_properties.tool='".TOOL_FORUM_THREAD."' AND
1559
                        threads.c_id = $course_id AND
1560
                        item_properties.c_id = $course_id
1561
                    GROUP BY threads.forum_id";
1562
        }
1563
    } else {
1564
        // GETTING ONE SPECIFIC FORUM
1565
        /* We could do the splitup into student and course admin also but we want
@@ 5080-5109 (lines=30) @@
5077
            GROUP BY threads.forum_id";
5078
5079
    // Course Admin
5080
    if (api_is_allowed_to_edit()) {
5081
        // Select all the forum information of all forums (that are not deleted).
5082
        $sql = "SELECT *
5083
                FROM $table_forums forum INNER JOIN $table_item_property item_properties
5084
                ON (forum.forum_id = item_properties.ref AND item_properties.c_id = forum.c_id)
5085
                WHERE
5086
                    forum.forum_of_group = $groupId AND
5087
                    forum.c_id = $course_id AND
5088
                    item_properties.c_id = $course_id AND                    
5089
                    item_properties.visibility <> 2 AND
5090
                    item_properties.tool = '".TOOL_FORUM."'
5091
                ORDER BY forum_order ASC";
5092
5093
        // Select the number of threads of the forums (only the threads that are not deleted).
5094
        $sql2 = "SELECT count(thread_id) AS number_of_threads, threads.forum_id
5095
                 FROM $table_threads threads INNER JOIN $table_item_property item_properties
5096
                 ON (threads.thread_id=item_properties.ref AND item_properties.c_id = threads.c_id)
5097
                 WHERE
5098
                    threads.c_id = $course_id AND
5099
                    item_properties.c_id = $course_id AND
5100
                    item_properties.visibility <> 2 AND
5101
                    item_properties.tool='".TOOL_FORUM_THREAD."'
5102
                GROUP BY threads.forum_id";
5103
        // Select the number of posts of the forum.
5104
        $sql3 = "SELECT count(post_id) AS number_of_posts, forum_id
5105
                FROM $table_posts
5106
                WHERE c_id = $course_id 
5107
                GROUP BY forum_id";
5108
    }
5109
5110
    // Handling all the forum information.
5111
    $result = Database::query($sql);
5112
    $forum_list = array();