supernova-ws /
SuperNova
| 1 | <?php |
||||
| 2 | |||||
| 3 | /** |
||||
| 4 | * User: Gorlum |
||||
| 5 | * Date: 18.09.2015 |
||||
| 6 | * Time: 11:36 |
||||
| 7 | */ |
||||
| 8 | |||||
| 9 | use DBAL\db_mysql; |
||||
| 10 | |||||
| 11 | /** |
||||
| 12 | * Class PlayerToAccountTranslate |
||||
| 13 | */ |
||||
| 14 | class PlayerToAccountTranslate { |
||||
| 15 | /** |
||||
| 16 | * БД из которой читать данные |
||||
| 17 | * |
||||
| 18 | * @var db_mysql $db |
||||
| 19 | */ |
||||
| 20 | protected static $db = null; |
||||
| 21 | protected static $is_init = false; |
||||
| 22 | |||||
| 23 | protected static function init() { |
||||
| 24 | if(!empty(static::$db)) { |
||||
| 25 | return; |
||||
| 26 | } |
||||
| 27 | static::$db = SN::$db; |
||||
| 28 | } |
||||
| 29 | |||||
| 30 | /** |
||||
| 31 | * Регистрирует игрока на указанный аккаунт указанного провайдера |
||||
| 32 | * |
||||
| 33 | * @param $provider_id_safe |
||||
| 34 | * @param $provider_account_id_safe |
||||
| 35 | * @param $user_id_safe |
||||
| 36 | * |
||||
| 37 | * @return array|resource |
||||
| 38 | */ |
||||
| 39 | // OK v4.7 |
||||
| 40 | public static function db_translate_register_user($provider_id_unsafe, $provider_account_id_unsafe, $user_id_unsafe) { |
||||
| 41 | static::init(); |
||||
| 42 | |||||
| 43 | $provider_id_safe = static::$db->db_escape($provider_id_unsafe); |
||||
| 44 | $provider_account_id_safe = static::$db->db_escape($provider_account_id_unsafe); |
||||
| 45 | $user_id_safe = static::$db->db_escape($user_id_unsafe); |
||||
| 46 | |||||
| 47 | return static::$db->doquery( |
||||
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
Loading history...
|
|||||
| 48 | "INSERT INTO `{{account_translate}}` (`provider_id`, `provider_account_id`, `user_id`) VALUES |
||||
| 49 | ({$provider_id_safe}, {$provider_account_id_safe}, {$user_id_safe});" |
||||
| 50 | ); |
||||
| 51 | } |
||||
| 52 | |||||
| 53 | /** |
||||
| 54 | * Возвращает из `account_translate` список пользователей, которые прилинкованы к списку аккаунтов на указанном провайдере |
||||
| 55 | * @version 4.5 |
||||
| 56 | * |
||||
| 57 | * @param int $provider_id_unsafe Идентификатор провайдера авторизации |
||||
| 58 | * @param int|int[] $account_list |
||||
| 59 | * |
||||
| 60 | * @return array |
||||
| 61 | */ |
||||
| 62 | // OK v4.7 |
||||
| 63 | public static function db_translate_get_users_from_account_list($provider_id_unsafe, $account_list) { |
||||
| 64 | static::init(); |
||||
| 65 | |||||
| 66 | $account_translation = array(); |
||||
| 67 | |||||
| 68 | $provider_id_safe = intval($provider_id_unsafe); |
||||
| 69 | !is_array($account_list) ? $account_list = array($account_list) : false; |
||||
| 70 | |||||
| 71 | foreach($account_list as $provider_account_id_unsafe) { |
||||
| 72 | $provider_account_id_safe = intval($provider_account_id_unsafe); |
||||
| 73 | |||||
| 74 | // TODO - Здесь могут отсутствовать аккаунты - проверять провайдером |
||||
| 75 | $query = static::$db->doquery( |
||||
| 76 | "SELECT `user_id` FROM {{account_translate}} WHERE `provider_id` = {$provider_id_safe} AND `provider_account_id` = {$provider_account_id_safe} FOR UPDATE" |
||||
| 77 | ); |
||||
| 78 | while($row = static::$db->db_fetch($query)) { |
||||
|
0 ignored issues
–
show
It seems like
$query can also be of type true; however, parameter $query_result of DBAL\db_mysql::db_fetch() does only seem to accept mysqli_result, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 79 | $account_translation[$row['user_id']][$provider_id_unsafe][$provider_account_id_unsafe] = true; |
||||
| 80 | } |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | return $account_translation; |
||||
| 84 | } |
||||
| 85 | |||||
| 86 | /** |
||||
| 87 | * @param int|string $user_id_unsafe |
||||
| 88 | * @param int $provider_id_unsafe |
||||
| 89 | * |
||||
| 90 | * @return array - array[playerId][providerId][providerAccountId] |
||||
| 91 | */ |
||||
| 92 | public static function db_translate_get_account_by_user_id($user_id_unsafe, $provider_id_unsafe = 0) { |
||||
| 93 | static::init(); |
||||
| 94 | |||||
| 95 | $user_id_safe = static::$db->db_escape($user_id_unsafe); |
||||
| 96 | $provider_id_safe = static::$db->db_escape($provider_id_unsafe); |
||||
| 97 | |||||
| 98 | $account_translation = array(); |
||||
| 99 | |||||
| 100 | $query = static::$db->doquery( |
||||
| 101 | "SELECT * FROM {{account_translate}} WHERE `user_id` = {$user_id_safe} " . |
||||
| 102 | ($provider_id_unsafe ? "AND `provider_id` = {$provider_id_safe} " : '') . |
||||
| 103 | "ORDER BY `timestamp` FOR UPDATE" |
||||
| 104 | ); |
||||
| 105 | while($row = static::$db->db_fetch($query)) { |
||||
|
0 ignored issues
–
show
It seems like
$query can also be of type true; however, parameter $query_result of DBAL\db_mysql::db_fetch() does only seem to accept mysqli_result, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 106 | $account_translation[$row['user_id']][$row['provider_id']][$row['provider_account_id']] = $row; |
||||
| 107 | } |
||||
| 108 | |||||
| 109 | return $account_translation; |
||||
| 110 | } |
||||
| 111 | |||||
| 112 | public static function db_translate_unregister_user($user_id_unsafe) { |
||||
| 113 | static::init(); |
||||
| 114 | |||||
| 115 | $user_id_safe = static::$db->db_escape($user_id_unsafe); |
||||
| 116 | return static::$db->doquery( |
||||
| 117 | "DELETE FROM `{{account_translate}}` WHERE `user_id` = {$user_id_safe});" |
||||
| 118 | ); |
||||
| 119 | } |
||||
| 120 | |||||
| 121 | } |
||||
| 122 |