Code Duplication    Length = 50-51 lines in 2 locations

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

@@ 1575-1624 (lines=50) @@
1572
     * the dir and file as the name implies if image does not exist it will
1573
     * return the unknow image if anonymous parameter is true if not it returns an empty array
1574
     */
1575
    public static function get_user_picture_path_by_id($id, $type = 'web', $userInfo = [])
1576
    {
1577
        switch ($type) {
1578
            case 'system': // Base: absolute system path.
1579
                $base = api_get_path(SYS_CODE_PATH);
1580
                break;
1581
            case 'web': // Base: absolute web path.
1582
            default:
1583
                $base = api_get_path(WEB_CODE_PATH);
1584
                break;
1585
        }
1586
1587
        $anonymousPath = array(
1588
            'dir' => $base.'img/',
1589
            'file' => 'unknown.jpg',
1590
            'email' => ''
1591
        );
1592
1593
        if (empty($id) || empty($type)) {
1594
            return $anonymousPath;
1595
        }
1596
1597
        $id = intval($id);
1598
        if (empty($userInfo)) {
1599
            $user_table = Database::get_main_table(TABLE_MAIN_USER);
1600
            $sql = "SELECT email, picture_uri FROM $user_table
1601
                    WHERE id=".$id;
1602
            $res = Database::query($sql);
1603
1604
            if (!Database::num_rows($res)) {
1605
                return $anonymousPath;
1606
            }
1607
            $user = Database::fetch_array($res);
1608
            if (empty($user['picture_uri'])) {
1609
                return $anonymousPath;
1610
            }
1611
        } else {
1612
            $user = $userInfo;
1613
        }
1614
1615
        $pictureFilename = trim($user['picture_uri']);
1616
1617
        $dir = self::getUserPathById($id, $type);
1618
1619
        return array(
1620
            'dir' => $dir,
1621
            'file' => $pictureFilename,
1622
            'email' => $user['email']
1623
        );
1624
    }
1625
1626
    /**
1627
     * *** READ BEFORE REVIEW THIS FUNCTION ***
@@ 1641-1691 (lines=51) @@
1638
     * the dir and file as the name implies if image does not exist it will
1639
     * return the unknown image if anonymous parameter is true if not it returns an empty array
1640
     */
1641
    public static function getUserPicturePathById($id, $type = 'web', $userInfo = [])
1642
    {
1643
        switch ($type) {
1644
            case 'system': // Base: absolute system path.
1645
                $base = api_get_path(SYS_CODE_PATH);
1646
                break;
1647
            case 'web': // Base: absolute web path.
1648
            default:
1649
                $base = api_get_path(WEB_CODE_PATH);
1650
                break;
1651
        }
1652
1653
        $anonymousPath = array(
1654
            'dir' => $base.'img/',
1655
            'file' => 'unknown.jpg',
1656
            'email' => ''
1657
        );
1658
1659
        if (empty($id) || empty($type)) {
1660
            return $anonymousPath;
1661
        }
1662
1663
        $id = intval($id);
1664
1665
        if (empty($userInfo)) {
1666
            $user_table = Database::get_main_table(TABLE_MAIN_USER);
1667
            $sql = "SELECT email, picture_uri FROM $user_table WHERE id=$id";
1668
            $res = Database::query($sql);
1669
1670
            if (!Database::num_rows($res)) {
1671
                return $anonymousPath;
1672
            }
1673
            $user = Database::fetch_array($res);
1674
1675
            if (empty($user['picture_uri'])) {
1676
                return $anonymousPath;
1677
            }
1678
        } else {
1679
            $user = $userInfo;
1680
        }
1681
1682
        $pictureFilename = trim($user['picture_uri']);
1683
1684
        $dir = self::getUserPathById($id, $type);
1685
1686
        return array(
1687
            'dir' => $dir,
1688
            'file' => $pictureFilename,
1689
            'email' => $user['email']
1690
        );
1691
    }
1692
1693
    /**
1694
     * Get user path from user ID (returns an array).