Code Duplication    Length = 45-46 lines in 2 locations

main/inc/lib/group_portal_manager.lib.php 1 location

@@ 1455-1500 (lines=46) @@
1452
     * @param boolean $includeSubgroupsUsers Optional. Whether include the users from subgroups
1453
     * @return array
1454
     */
1455
    public static function getGroupUsersByUser(
1456
        $userId,
1457
        $relationType = GROUP_USER_PERMISSION_ADMIN,
1458
        $includeSubgroupsUsers = true
1459
    )
1460
    {
1461
        $userId = intval($userId);
1462
1463
        $groups = GroupPortalManager::get_groups_by_user($userId, $relationType);
1464
1465
        $groupsId = array_keys($groups);
1466
        $subgroupsId = [];
1467
        $userIdList = [];
1468
1469
        if ($includeSubgroupsUsers) {
1470
            foreach ($groupsId as $groupId) {
1471
                $subgroupsId = array_merge($subgroupsId, GroupPortalManager::getGroupsByDepthLevel($groupId));
1472
            }
1473
1474
            $groupsId = array_merge($groupsId, $subgroupsId);
1475
        }
1476
1477
        $groupsId = array_unique($groupsId);
1478
1479
        if (empty($groupsId)) {
1480
            return [];
1481
        }
1482
1483
        foreach ($groupsId as $groupId) {
1484
            $groupUsers = GroupPortalManager::get_users_by_group($groupId);
1485
1486
            if (empty($groupUsers)) {
1487
                continue;
1488
            }
1489
1490
            foreach ($groupUsers as $member) {
1491
                if ($member['user_id'] == $userId) {
1492
                    continue;
1493
                }
1494
1495
                $userIdList[] = intval($member['user_id']);
1496
            }
1497
        }
1498
1499
        return array_unique($userIdList);
1500
    }
1501
1502
}
1503

main/inc/lib/usergroup.lib.php 1 location

@@ 2232-2276 (lines=45) @@
2229
     * @param boolean $includeSubgroupsUsers Optional. Whether include the users from subgroups
2230
     * @return array
2231
     */
2232
    public function getGroupUsersByUser(
2233
        $userId,
2234
        $relationType = GROUP_USER_PERMISSION_ADMIN,
2235
        $includeSubgroupsUsers = true
2236
    ) {
2237
        $userId = intval($userId);
2238
2239
        $groups = $this->get_groups_by_user($userId, $relationType);
2240
2241
        $groupsId = array_keys($groups);
2242
        $subgroupsId = [];
2243
        $userIdList = [];
2244
2245
        if ($includeSubgroupsUsers) {
2246
            foreach ($groupsId as $groupId) {
2247
                $subgroupsId = array_merge($subgroupsId, self::getGroupsByDepthLevel($groupId));
2248
            }
2249
2250
            $groupsId = array_merge($groupsId, $subgroupsId);
2251
        }
2252
2253
        $groupsId = array_unique($groupsId);
2254
2255
        if (empty($groupsId)) {
2256
            return [];
2257
        }
2258
2259
        foreach ($groupsId as $groupId) {
2260
            $groupUsers = self::get_users_by_group($groupId);
2261
2262
            if (empty($groupUsers)) {
2263
                continue;
2264
            }
2265
2266
            foreach ($groupUsers as $member) {
2267
                if ($member['user_id'] == $userId) {
2268
                    continue;
2269
                }
2270
2271
                $userIdList[] = intval($member['user_id']);
2272
            }
2273
        }
2274
2275
        return array_unique($userIdList);
2276
    }
2277
2278
    /**
2279
     * Get the subgroups ID from a group.