Code Duplication    Length = 21-24 lines in 2 locations

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

@@ 1413-1436 (lines=24) @@
1410
     * @param array $groupInfo
1411
     * @return bool TRUE if self-registration is allowed in the given group.
1412
     */
1413
    public static function is_self_registration_allowed($user_id, $groupInfo)
1414
    {
1415
        $course_id = api_get_course_int_id();
1416
        if (!$user_id > 0) {
1417
            return false;
1418
        }
1419
        $groupIid = $groupInfo['iid'];
1420
        $table_group = Database::get_course_table(TABLE_GROUP);
1421
        if (isset($groupIid)) {
1422
            $sql = "SELECT status, self_registration_allowed
1423
                    FROM $table_group
1424
                    WHERE c_id = $course_id AND iid = $groupIid";
1425
            $result = Database::query($sql);
1426
            $group = Database::fetch_object($result);
1427
1428
            if ($group->status == 0 || $group->self_registration_allowed != 1) {
1429
                return false;
1430
            }
1431
1432
            return self::can_user_subscribe($user_id, $groupInfo);
1433
        } else {
1434
            return false;
1435
        }
1436
    }
1437
1438
    /**
1439
     * Is sef-unregistration allowed?
@@ 1444-1464 (lines=21) @@
1441
     * @param array $groupInfo
1442
     * @return bool TRUE if self-unregistration is allowed in the given group.
1443
     */
1444
    public static function is_self_unregistration_allowed($user_id, $groupInfo)
1445
    {
1446
        if (!$user_id > 0 || empty($groupInfo)) {
1447
            return false;
1448
        }
1449
        $groupIid = $groupInfo['iid'];
1450
        $table_group = Database::get_course_table(TABLE_GROUP);
1451
        $course_id = api_get_course_int_id();
1452
1453
        $sql = "SELECT status, self_unregistration_allowed
1454
                FROM $table_group
1455
                WHERE c_id = $course_id AND iid = $groupIid";
1456
        $result = Database::query($sql);
1457
        $group = Database::fetch_object($result);
1458
1459
        if ($group->status == 0 || $group->self_unregistration_allowed != 1) {
1460
            return false;
1461
        }
1462
1463
        return self::is_subscribed($user_id, $groupInfo);
1464
    }
1465
1466
    /**
1467
     * Is user subscribed in group?