| @@ 29-39 (lines=11) @@ | ||
| 26 | $time = 2147483647; //mysql int max value |
|
| 27 | } |
|
| 28 | ||
| 29 | public static function get_by_id($id) |
|
| 30 | { |
|
| 31 | $table = Database::get_main_table(TABLE_MAIN_USER_API_KEY); |
|
| 32 | $sql = "SELECT * FROM $table WHERE id=$id"; |
|
| 33 | $res = Database::query($sql); |
|
| 34 | if (Database::num_rows($res) < 1) { |
|
| 35 | return false; |
|
| 36 | } |
|
| 37 | $result = Database::fetch_array($res, 'ASSOC'); |
|
| 38 | return $result; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * |
|
| @@ 1077-1087 (lines=11) @@ | ||
| 1074 | * @assert ('') === false |
|
| 1075 | * @assert ('xyzxyzxyz') === true |
|
| 1076 | */ |
|
| 1077 | public static function is_username_available($username) |
|
| 1078 | { |
|
| 1079 | if (empty($username)) { |
|
| 1080 | return false; |
|
| 1081 | } |
|
| 1082 | $table_user = Database :: get_main_table(TABLE_MAIN_USER); |
|
| 1083 | $sql = "SELECT username FROM $table_user |
|
| 1084 | WHERE username = '".Database::escape_string($username)."'"; |
|
| 1085 | $res = Database::query($sql); |
|
| 1086 | return Database::num_rows($res) == 0; |
|
| 1087 | } |
|
| 1088 | ||
| 1089 | /** |
|
| 1090 | * Creates a username using person's names, i.e. creates jmontoya from Julio Montoya. |
|
| @@ 1543-1555 (lines=13) @@ | ||
| 1540 | * status of "6" (anonymous). |
|
| 1541 | * @return int User ID of the anonymous user, or O if no anonymous user found |
|
| 1542 | */ |
|
| 1543 | function api_get_anonymous_id() |
|
| 1544 | { |
|
| 1545 | $table = Database::get_main_table(TABLE_MAIN_USER); |
|
| 1546 | $sql = "SELECT user_id FROM $table WHERE status = ".ANONYMOUS; |
|
| 1547 | $res = Database::query($sql); |
|
| 1548 | if (Database::num_rows($res) > 0) { |
|
| 1549 | $row = Database::fetch_array($res); |
|
| 1550 | return $row['user_id']; |
|
| 1551 | } |
|
| 1552 | ||
| 1553 | // No anonymous user was found. |
|
| 1554 | return 0; |
|
| 1555 | } |
|
| 1556 | ||
| 1557 | /** |
|
| 1558 | * @param string $courseCode |
|