Code Duplication    Length = 36-41 lines in 2 locations

main/inc/lib/usergroup.lib.php 2 locations

@@ 1788-1823 (lines=36) @@
1785
     * @return array  with group content
1786
     * @author Julio Montoya
1787
     * */
1788
    public function get_groups_by_popularity($num = 6, $with_image = true)
1789
    {
1790
        $table_group_rel_user = $this->usergroup_rel_user_table;
1791
        $tbl_group = $this->table;
1792
        if (empty($num)) {
1793
            $num = 6;
1794
        } else {
1795
            $num = intval($num);
1796
        }
1797
        // only show admins and readers
1798
        $where_relation_condition = " WHERE g.group_type = ".self::SOCIAL_CLASS." AND
1799
                                      gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
1800
        $sql = "SELECT DISTINCT count(user_id) as count, g.picture, g.name, g.description, g.id
1801
				FROM $tbl_group g
1802
				INNER JOIN $table_group_rel_user gu
1803
				ON gu.usergroup_id = g.id $where_relation_condition
1804
				GROUP BY g.id
1805
				ORDER BY count DESC
1806
				LIMIT $num";
1807
1808
        $result=Database::query($sql);
1809
        $array = array();
1810
        while ($row = Database::fetch_array($result, 'ASSOC')) {
1811
            if ($with_image) {
1812
                $picture = self::get_picture_group($row['id'], $row['picture'],80);
1813
                $img = '<img src="'.$picture['file'].'" />';
1814
                $row['picture'] = $img;
1815
            }
1816
            if (empty($row['id'])) {
1817
                continue;
1818
            }
1819
            $array[$row['id']] = $row;
1820
        }
1821
1822
        return $array;
1823
    }
1824
1825
    /** Gets the last groups created
1826
     * @param int  quantity of records
@@ 1831-1871 (lines=41) @@
1828
     * @return array  with group content
1829
     * @author Julio Montoya
1830
     * */
1831
    public function get_groups_by_age($num = 6, $with_image = true)
1832
    {
1833
        $table_group_rel_user = $this->usergroup_rel_user_table;
1834
        $tbl_group = $this->table;
1835
1836
        if (empty($num)) {
1837
            $num = 6;
1838
        } else {
1839
            $num = intval($num);
1840
        }
1841
        $where_relation_condition = " WHERE g.group_type = ".self::SOCIAL_CLASS." AND
1842
                                      gu.relation_type IN ('".GROUP_USER_PERMISSION_ADMIN."' , '".GROUP_USER_PERMISSION_READER."', '".GROUP_USER_PERMISSION_HRM."') ";
1843
        $sql = "SELECT DISTINCT
1844
                  count(user_id) as count,
1845
                  g.picture,
1846
                  g.name,
1847
                  g.description,
1848
                  g.id
1849
                FROM $tbl_group g
1850
                INNER JOIN $table_group_rel_user gu
1851
                ON gu.usergroup_id = g.id
1852
                $where_relation_condition
1853
                GROUP BY g.id
1854
                ORDER BY created_at DESC
1855
                LIMIT $num ";
1856
1857
        $result=Database::query($sql);
1858
        $array = array();
1859
        while ($row = Database::fetch_array($result, 'ASSOC')) {
1860
            if ($with_image) {
1861
                $picture = self::get_picture_group($row['id'], $row['picture'],80);
1862
                $img = '<img src="'.$picture['file'].'" />';
1863
                $row['picture'] = $img;
1864
            }
1865
            if (empty($row['id'])) {
1866
                continue;
1867
            }
1868
            $array[$row['id']] = $row;
1869
        }
1870
        return $array;
1871
    }
1872
1873
    /**
1874
     * Gets the group's members