Code Duplication    Length = 50-51 lines in 2 locations

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

@@ 1497-1546 (lines=50) @@
1494
     * the dir and file as the name implies if image does not exist it will
1495
     * return the unknow image if anonymous parameter is true if not it returns an empty array
1496
     */
1497
    public static function get_user_picture_path_by_id($id, $type = 'web', $userInfo = [])
1498
    {
1499
        switch ($type) {
1500
            case 'system': // Base: absolute system path.
1501
                $base = api_get_path(SYS_CODE_PATH);
1502
                break;
1503
            case 'web': // Base: absolute web path.
1504
            default:
1505
                $base = api_get_path(WEB_CODE_PATH);
1506
                break;
1507
        }
1508
1509
        $anonymousPath = array(
1510
            'dir' => $base.'img/',
1511
            'file' => 'unknown.jpg',
1512
            'email' => ''
1513
        );
1514
1515
        if (empty($id) || empty($type)) {
1516
            return $anonymousPath;
1517
        }
1518
1519
        $id = intval($id);
1520
        if (empty($userInfo)) {
1521
            $user_table = Database:: get_main_table(TABLE_MAIN_USER);
1522
            $sql = "SELECT email, picture_uri FROM $user_table
1523
                    WHERE id=".$id;
1524
            $res = Database::query($sql);
1525
1526
            if (!Database::num_rows($res)) {
1527
                return $anonymousPath;
1528
            }
1529
            $user = Database::fetch_array($res);
1530
            if (empty($user['picture_uri'])) {
1531
                return $anonymousPath;
1532
            }
1533
        } else {
1534
            $user = $userInfo;
1535
        }
1536
1537
        $pictureFilename = trim($user['picture_uri']);
1538
1539
        $dir = self::getUserPathById($id, $type);
1540
1541
        return array(
1542
            'dir' => $dir,
1543
            'file' => $pictureFilename,
1544
            'email' => $user['email']
1545
        );
1546
    }
1547
1548
    /**
1549
     * *** READ BEFORE REVIEW THIS FUNCTION ***
@@ 1563-1613 (lines=51) @@
1560
     * the dir and file as the name implies if image does not exist it will
1561
     * return the unknow image if anonymous parameter is true if not it returns an empty array
1562
     */
1563
    public static function getUserPicturePathById($id, $type = 'web', $userInfo = [])
1564
    {
1565
        switch ($type) {
1566
            case 'system': // Base: absolute system path.
1567
                $base = api_get_path(SYS_CODE_PATH);
1568
                break;
1569
            case 'web': // Base: absolute web path.
1570
            default:
1571
                $base = api_get_path(WEB_CODE_PATH);
1572
                break;
1573
        }
1574
1575
        $anonymousPath = array(
1576
            'dir' => $base.'img/',
1577
            'file' => 'unknown.jpg',
1578
            'email' => ''
1579
        );
1580
1581
        if (empty($id) || empty($type)) {
1582
            return $anonymousPath;
1583
        }
1584
1585
        $id = intval($id);
1586
1587
        if (empty($userInfo)) {
1588
            $user_table = Database:: get_main_table(TABLE_MAIN_USER);
1589
            $sql = "SELECT email, picture_uri FROM $user_table WHERE id=$id";
1590
            $res = Database::query($sql);
1591
1592
            if (!Database::num_rows($res)) {
1593
                return $anonymousPath;
1594
            }
1595
            $user = Database::fetch_array($res);
1596
1597
            if (empty($user['picture_uri'])) {
1598
                return $anonymousPath;
1599
            }
1600
        } else {
1601
            $user = $userInfo;
1602
        }
1603
1604
        $pictureFilename = trim($user['picture_uri']);
1605
1606
        $dir = self::getUserPathById($id, $type);
1607
1608
        return array(
1609
            'dir' => $dir,
1610
            'file' => $pictureFilename,
1611
            'email' => $user['email']
1612
        );
1613
    }
1614
1615
    /**
1616
     * Get user path from user ID (returns an array).