@@ -122,30 +122,30 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | $update_cache = false; |
| 124 | 124 | |
| 125 | - if(!empty($this->to_write)) { |
|
| 126 | - foreach($this->to_write as $key => $cork) { |
|
| 125 | + if (!empty($this->to_write)) { |
|
| 126 | + foreach ($this->to_write as $key => $cork) { |
|
| 127 | 127 | $value = is_array($this->data[$key]) ? serialize($this->data[$key]) : $this->data[$key]; // Сериализация для массивов при сохранении в БД |
| 128 | - $this->to_write[$key] = "({$this->user_id}, '" . db_escape($key) . "', '" . db_escape($value) . "')"; |
|
| 128 | + $this->to_write[$key] = "({$this->user_id}, '".db_escape($key)."', '".db_escape($value)."')"; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - classSupernova::$db->doReplace("REPLACE INTO `{{player_options}}` (`player_id`, `option_id`, `value`) VALUES " . implode(',', $this->to_write)); |
|
| 131 | + classSupernova::$db->doReplace("REPLACE INTO `{{player_options}}` (`player_id`, `option_id`, `value`) VALUES ".implode(',', $this->to_write)); |
|
| 132 | 132 | |
| 133 | 133 | $this->to_write = array(); |
| 134 | 134 | $update_cache = true; |
| 135 | 135 | } |
| 136 | 136 | |
| 137 | - if(!empty($this->to_delete)) { |
|
| 138 | - foreach($this->to_delete as $key => &$value) { |
|
| 139 | - $value = is_string($key) ? "'". db_escape($key) . "'" : $key; |
|
| 137 | + if (!empty($this->to_delete)) { |
|
| 138 | + foreach ($this->to_delete as $key => &$value) { |
|
| 139 | + $value = is_string($key) ? "'".db_escape($key)."'" : $key; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - classSupernova::$db->doDelete("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (". implode(',', $this->to_delete) . ") "); |
|
| 142 | + classSupernova::$db->doDelete("DELETE FROM {{player_options}} WHERE `player_id` = {$this->user_id} AND `option_id` IN (".implode(',', $this->to_delete).") "); |
|
| 143 | 143 | |
| 144 | 144 | $this->to_delete = array(); |
| 145 | 145 | $update_cache = true; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - if($update_cache) { |
|
| 148 | + if ($update_cache) { |
|
| 149 | 149 | $field_name = $this->cached_name(); |
| 150 | 150 | classSupernova::$cache->$field_name = $this->data; |
| 151 | 151 | } |
@@ -164,11 +164,11 @@ discard block |
||
| 164 | 164 | $this->load(); |
| 165 | 165 | } |
| 166 | 166 | protected function cached_name() { |
| 167 | - return 'options_' . $this->user_id; |
|
| 167 | + return 'options_'.$this->user_id; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | protected function load() { |
| 171 | - if($this->loaded) { |
|
| 171 | + if ($this->loaded) { |
|
| 172 | 172 | return; |
| 173 | 173 | } |
| 174 | 174 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $this->to_write = array(); |
| 177 | 177 | $this->to_delete = array(); |
| 178 | 178 | |
| 179 | - if(!$this->user_id) { |
|
| 179 | + if (!$this->user_id) { |
|
| 180 | 180 | $this->loaded = true; |
| 181 | 181 | return; |
| 182 | 182 | } |
@@ -184,13 +184,13 @@ discard block |
||
| 184 | 184 | $field_name = $this->cached_name(); |
| 185 | 185 | $a_data = classSupernova::$cache->$field_name; |
| 186 | 186 | |
| 187 | - if(!empty($a_data)) { |
|
| 187 | + if (!empty($a_data)) { |
|
| 188 | 188 | $this->data = array_replace_recursive($this->data, $a_data); |
| 189 | 189 | return; |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | $query = classSupernova::$db->doSelect("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
| 193 | - while($row = db_fetch($query)) { |
|
| 193 | + while ($row = db_fetch($query)) { |
|
| 194 | 194 | // $this->data[$row['option_id']] = $row['value']; |
| 195 | 195 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
| 196 | 196 | } |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | protected function cached_name() { |
| 270 | - return 'options_' . $this->user_id; |
|
| 270 | + return 'options_'.$this->user_id; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | // TODO - serialize/unserialize options |
@@ -275,14 +275,14 @@ discard block |
||
| 275 | 275 | // Если в массиве индекса только один элемент - значит это просто индекс |
| 276 | 276 | is_array($option_id) && count($option_id) == 1 ? $option_id = reset($option_id) : false; |
| 277 | 277 | |
| 278 | - if(!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
| 278 | + if (!isset($this->data[is_array($option_id) ? reset($option_id) : $option_id])) { |
|
| 279 | 279 | $this->load(); |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - if(is_array($option_id)) { |
|
| 282 | + if (is_array($option_id)) { |
|
| 283 | 283 | $result = $this->data; |
| 284 | - foreach($option_id as $sub_key) { |
|
| 285 | - if(!isset($result) || !isset($result[$sub_key])) { |
|
| 284 | + foreach ($option_id as $sub_key) { |
|
| 285 | + if (!isset($result) || !isset($result[$sub_key])) { |
|
| 286 | 286 | $result = null; |
| 287 | 287 | break; |
| 288 | 288 | } |
@@ -300,12 +300,12 @@ discard block |
||
| 300 | 300 | * @param null|mixed $value |
| 301 | 301 | */ |
| 302 | 302 | public function __set($option, $value = null) { |
| 303 | - if(empty($option) || !$this->user_id) { |
|
| 303 | + if (empty($option) || !$this->user_id) { |
|
| 304 | 304 | return; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // Если в массиве индекса только один элемент - значит это просто индекс |
| 308 | - if(is_array($option) && count($option) == 1) { |
|
| 308 | + if (is_array($option) && count($option) == 1) { |
|
| 309 | 309 | // Разворачиваем его в индекс |
| 310 | 310 | $option = array(reset($option) => $value); |
| 311 | 311 | unset($value); |
@@ -314,13 +314,13 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | $to_write = array(); |
| 316 | 316 | // Адресация многомерного массива через массив индексов в $option |
| 317 | - if(is_array($option) && isset($value)) { |
|
| 317 | + if (is_array($option) && isset($value)) { |
|
| 318 | 318 | $a_data = &$this->data; |
| 319 | - foreach($option as $option_id) { |
|
| 319 | + foreach ($option as $option_id) { |
|
| 320 | 320 | !is_array($a_data[$option_id]) ? $a_data[$option_id] = array() : false; |
| 321 | 321 | $a_data = &$a_data[$option_id]; |
| 322 | 322 | } |
| 323 | - if($a_data != $value) { |
|
| 323 | + if ($a_data != $value) { |
|
| 324 | 324 | $a_data = $value; |
| 325 | 325 | $to_write[reset($option)] = null; |
| 326 | 326 | } |
@@ -328,11 +328,11 @@ discard block |
||
| 328 | 328 | // Пакетная запись из массива ключ -> значение |
| 329 | 329 | !is_array($option) ? $option = array($option => $value) : false; |
| 330 | 330 | |
| 331 | - foreach($option as $option_id => $option_value) { |
|
| 332 | - if($this->data[$option_id] !== $option_value) { |
|
| 331 | + foreach ($option as $option_id => $option_value) { |
|
| 332 | + if ($this->data[$option_id] !== $option_value) { |
|
| 333 | 333 | // TODO - вынести отдельно в обработчик |
| 334 | - if($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
| 335 | - sn_setcookie(SN_COOKIE . '_menu_hidden', '0', time() - PERIOD_WEEK, SN_ROOT_RELATIVE); |
|
| 334 | + if ($option_id == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON && $option_value == PLAYER_OPTION_MENU_HIDE_SHOW_BUTTON_HIDDEN) { |
|
| 335 | + sn_setcookie(SN_COOKIE.'_menu_hidden', '0', time() - PERIOD_WEEK, SN_ROOT_RELATIVE); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | $this->data[$option_id] = $option_value; |
@@ -341,40 +341,40 @@ discard block |
||
| 341 | 341 | } |
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - if(!empty($to_write)) { |
|
| 344 | + if (!empty($to_write)) { |
|
| 345 | 345 | $field_name = $this->cached_name(); |
| 346 | 346 | classSupernova::$cache->$field_name = $this->data; |
| 347 | 347 | |
| 348 | - foreach($to_write as $option_id => &$option_value) { |
|
| 348 | + foreach ($to_write as $option_id => &$option_value) { |
|
| 349 | 349 | $option_value = is_array($this->data[$option_id]) ? serialize($this->data[$option_id]) : $this->data[$option_id]; // Сериализация для массивов при сохранении в БД |
| 350 | - $to_write[$option_id] = "({$this->user_id}, '" . db_escape($option_id) . "', '" . db_escape($option_value) . "')"; |
|
| 350 | + $to_write[$option_id] = "({$this->user_id}, '".db_escape($option_id)."', '".db_escape($option_value)."')"; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | - classSupernova::$db->doReplace("REPLACE INTO `{{player_options}}` (`player_id`, `option_id`, `value`) VALUES " . implode(',', $to_write)); |
|
| 353 | + classSupernova::$db->doReplace("REPLACE INTO `{{player_options}}` (`player_id`, `option_id`, `value`) VALUES ".implode(',', $to_write)); |
|
| 354 | 354 | } |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | protected function load() { |
| 358 | - if($this->loaded) { |
|
| 358 | + if ($this->loaded) { |
|
| 359 | 359 | return; |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | $this->data = $this->defaults; |
| 363 | 363 | |
| 364 | - if(!$this->user_id) { |
|
| 364 | + if (!$this->user_id) { |
|
| 365 | 365 | return; |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | $field_name = $this->cached_name(); |
| 369 | 369 | $a_data = classSupernova::$cache->$field_name; |
| 370 | 370 | |
| 371 | - if(!empty($a_data)) { |
|
| 371 | + if (!empty($a_data)) { |
|
| 372 | 372 | $this->data = array_replace($this->data, $a_data); |
| 373 | 373 | return; |
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | $query = classSupernova::$db->doSelect("SELECT * FROM `{{player_options}}` WHERE `player_id` = {$this->user_id} FOR UPDATE"); |
| 377 | - while($row = db_fetch($query)) { |
|
| 377 | + while ($row = db_fetch($query)) { |
|
| 378 | 378 | // $this->data[$row['option_id']] = $row['value']; |
| 379 | 379 | $this->data[$row['option_id']] = is_string($row['value']) && ($temp = unserialize($row['value'])) !== false ? $temp : $row['value']; // Десериализация |
| 380 | 380 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | return $this->__get($offset); |
| 391 | 391 | } |
| 392 | 392 | public function offsetSet($offset, $value) { |
| 393 | - if(!is_null($offset)) { |
|
| 393 | + if (!is_null($offset)) { |
|
| 394 | 394 | // $this->data[$offset] = $value; |
| 395 | 395 | $this->__set($offset, $value); |
| 396 | 396 | } else { |
@@ -96,7 +96,7 @@ |
||
| 96 | 96 | $qry[] = "('{$item_name}', '{$item_value}')"; |
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | - classSupernova::$db->doReplace("REPLACE INTO `{{" . $this->table_name . "}}` (`{$this->sql_index_field}`, `{$this->sql_value_field}`) VALUES " . implode(',', $qry) . ";"); |
|
| 99 | + classSupernova::$db->doReplace("REPLACE INTO `{{".$this->table_name."}}` (`{$this->sql_index_field}`, `{$this->sql_value_field}`) VALUES ".implode(',', $qry).";"); |
|
| 100 | 100 | |
| 101 | 101 | // И только после взятия блокировок - меняем значения в кэше |
| 102 | 102 | foreach ($item_list as $item_name => $item_value) { |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | ->where('`user_as_ally` IS NULL') |
| 24 | 24 | ->orderBy(array('`id` DESC')); |
| 25 | 25 | |
| 26 | - return (string)$query->selectValue(); |
|
| 26 | + return (string) $query->selectValue(); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -48,15 +48,15 @@ discard block |
||
| 48 | 48 | static::buildDBQ() |
| 49 | 49 | ->field('id') |
| 50 | 50 | ->where("`user_as_ally` IS NULL") |
| 51 | - ->where("`user_bot` = " . USER_BOT_PLAYER) |
|
| 51 | + ->where("`user_bot` = ".USER_BOT_PLAYER) |
|
| 52 | 52 | ->setForUpdate(); |
| 53 | 53 | |
| 54 | 54 | return $query->selectIterator(); |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | public static function db_user_lock_with_target_owner_and_acs($user, $planet = array()) { |
| 58 | - $query = "SELECT 1 FROM `{{users}}` WHERE `id` = " . idval($user['id']) . |
|
| 59 | - (!empty($planet['id_owner']) ? ' OR `id` = ' . idval($planet['id_owner']) : '') |
|
| 58 | + $query = "SELECT 1 FROM `{{users}}` WHERE `id` = ".idval($user['id']). |
|
| 59 | + (!empty($planet['id_owner']) ? ' OR `id` = '.idval($planet['id_owner']) : '') |
|
| 60 | 60 | . " FOR UPDATE"; |
| 61 | 61 | |
| 62 | 62 | static::getDb()->doSelect($query); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | FROM `{{users}}` |
| 74 | 74 | WHERE |
| 75 | 75 | `user_as_ally` IS NULL" . |
| 76 | - ($online ? ' AND `onlinetime` > ' . (SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : '') |
|
| 76 | + ($online ? ' AND `onlinetime` > '.(SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : '') |
|
| 77 | 77 | )); |
| 78 | 78 | } |
| 79 | 79 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | ->fieldCount('r.id', 'referral_count') |
| 96 | 96 | ->fieldSingleFunction('sum', 'r.dark_matter', 'referral_dm') |
| 97 | 97 | ->join('LEFT JOIN {{referrals}} as r on r.id_partner = u.id') |
| 98 | - ->where($online ? "`onlinetime` >= " . intval(SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : 'user_as_ally IS NULL') |
|
| 98 | + ->where($online ? "`onlinetime` >= ".intval(SN_TIME_NOW - classSupernova::$config->game_users_online_timeout) : 'user_as_ally IS NULL') |
|
| 99 | 99 | ->groupBy('u.id') |
| 100 | 100 | ->orderBy("user_as_ally, {$sort} ASC"); |
| 101 | 101 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | ->where('(`user_birthday_celebrated` IS NULL OR DATE_ADD(`user_birthday_celebrated`, INTERVAL 1 YEAR) < CURRENT_DATE)') |
| 114 | 114 | ->where('`user_as_ally` IS NULL') |
| 115 | 115 | ->having('`days_after_birthday` >= 0') |
| 116 | - ->having('`days_after_birthday` < ' . intval($config_user_birthday_range)) |
|
| 116 | + ->having('`days_after_birthday` < '.intval($config_user_birthday_range)) |
|
| 117 | 117 | ->setForUpdate(); |
| 118 | 118 | |
| 119 | 119 | $result = $query->selectIterator(); |
@@ -195,7 +195,7 @@ discard block |
||
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | public static function db_user_list_set_mass_mail(&$owners_list, $set) { |
| 198 | - return classSupernova::db_upd_record_list(LOC_USER, !empty($owners_list) ? '`id` IN (' . implode(',', $owners_list) . ');' : '', $set); |
|
| 198 | + return classSupernova::db_upd_record_list(LOC_USER, !empty($owners_list) ? '`id` IN ('.implode(',', $owners_list).');' : '', $set); |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | public static function db_user_list_set_by_ally_and_rank($ally_id, $ally_rank_id, $set) { |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @param array $playerArray |
| 211 | 211 | */ |
| 212 | 212 | public static function renderNameAndCoordinates($playerArray) { |
| 213 | - return "{$playerArray['username']} " . uni_render_coordinates($playerArray); |
|
| 213 | + return "{$playerArray['username']} ".uni_render_coordinates($playerArray); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | // // TODO - IoC test |
@@ -448,7 +448,7 @@ discard block |
||
| 448 | 448 | public function compile_request($request) { |
| 449 | 449 | global $user; |
| 450 | 450 | |
| 451 | - if(!(classSupernova::$auth->account instanceof Account)) { |
|
| 451 | + if (!(classSupernova::$auth->account instanceof Account)) { |
|
| 452 | 452 | // TODO - throw new Exception(lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
| 453 | 453 | } |
| 454 | 454 | $this->account = classSupernova::$auth->account; |
@@ -469,15 +469,15 @@ discard block |
||
| 469 | 469 | $this->payment_currency = classSupernova::$config->payment_currency_default; |
| 470 | 470 | $this->payment_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_currency); |
| 471 | 471 | |
| 472 | - if(empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
| 472 | + if (empty($this->payment_external_currency) && !empty($this->config['currency'])) { |
|
| 473 | 473 | $this->payment_external_currency = $this->config['currency']; |
| 474 | 474 | } |
| 475 | - if(empty($this->payment_external_currency)) { |
|
| 475 | + if (empty($this->payment_external_currency)) { |
|
| 476 | 476 | throw new Exception(classLocale::$lang['pay_error_internal_no_external_currency_set'], SN_PAYMENT_ERROR_INTERNAL_NO_EXTERNAL_CURRENCY_SET); |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | $this->payment_external_amount = self::currency_convert($this->payment_dark_matter_paid, 'MM_', $this->payment_external_currency); |
| 480 | - if($this->payment_external_amount < 0.01) { |
|
| 480 | + if ($this->payment_external_amount < 0.01) { |
|
| 481 | 481 | throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'], SN_PAYMENT_REQUEST_ERROR_UNIT_AMOUNT); |
| 482 | 482 | } |
| 483 | 483 | |
@@ -486,7 +486,7 @@ discard block |
||
| 486 | 486 | $this->generate_description(); |
| 487 | 487 | |
| 488 | 488 | $this->db_insert(); |
| 489 | - if(!$this->is_exists) { |
|
| 489 | + if (!$this->is_exists) { |
|
| 490 | 490 | throw new Exception(classLocale::$lang['pay_msg_request_error_db_payment_create'], SN_PAYMENT_REQUEST_DB_ERROR_PAYMENT_CREATE); |
| 491 | 491 | } |
| 492 | 492 | } |
@@ -498,26 +498,26 @@ discard block |
||
| 498 | 498 | * @throws Exception |
| 499 | 499 | */ |
| 500 | 500 | protected function payment_request_process($options = array()) { |
| 501 | - if(!$this->manifest['active']) { |
|
| 501 | + if (!$this->manifest['active']) { |
|
| 502 | 502 | throw new Exception(classLocale::$lang['pay_msg_module_disabled'], SN_MODULE_DISABLED); |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | // Если есть payment_id - загружаем под него данные |
| 506 | - if(!empty($this->payment_params['payment_id'])) { |
|
| 506 | + if (!empty($this->payment_params['payment_id'])) { |
|
| 507 | 507 | $this->request_payment_id = sys_get_param_id($this->payment_params['payment_id']); |
| 508 | - if(!$this->request_payment_id) { |
|
| 508 | + if (!$this->request_payment_id) { |
|
| 509 | 509 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
| 510 | 510 | } |
| 511 | 511 | |
| 512 | - if(!$this->db_get_by_id($this->request_payment_id)) { |
|
| 512 | + if (!$this->db_get_by_id($this->request_payment_id)) { |
|
| 513 | 513 | throw new Exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_INTERNAL_ID_WRONG); |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | // Проверяем - был ли этот платеж обработан? |
| 517 | 517 | // TODO - Статусы бывают разные. Нужен спецфлаг payment_processed |
| 518 | - if($this->payment_status != PAYMENT_STATUS_NONE) { |
|
| 518 | + if ($this->payment_status != PAYMENT_STATUS_NONE) { |
|
| 519 | 519 | sn_db_transaction_rollback(); |
| 520 | - sys_redirect(SN_ROOT_VIRTUAL . 'metamatter.php?payment_id=' . $this->payment_id); |
|
| 520 | + sys_redirect(SN_ROOT_VIRTUAL.'metamatter.php?payment_id='.$this->payment_id); |
|
| 521 | 521 | die(); |
| 522 | 522 | } |
| 523 | 523 | } |
@@ -525,89 +525,89 @@ discard block |
||
| 525 | 525 | // Пытаемся получить из запроса ИД аккаунта |
| 526 | 526 | $request_account_id = !empty($this->payment_params['account_id']) ? sys_get_param_id($this->payment_params['account_id']) : 0; |
| 527 | 527 | // Если в запросе нет ИД аккаунта - пытаемся использовать payment_account_id |
| 528 | - if(empty($request_account_id) && !empty($this->payment_account_id)) { |
|
| 528 | + if (empty($request_account_id) && !empty($this->payment_account_id)) { |
|
| 529 | 529 | $request_account_id = $this->payment_account_id; |
| 530 | 530 | } |
| 531 | 531 | // Если теперь у нас нету ИД аккаунта ни в запросе, ни в записи таблицы - можно паниковать |
| 532 | - if(empty($request_account_id)) { |
|
| 532 | + if (empty($request_account_id)) { |
|
| 533 | 533 | // TODO - аккаунт |
| 534 | 534 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
| 535 | 535 | } |
| 536 | 536 | // Если нет записи в таблице - тогда берем payment_account_id из запроса |
| 537 | - if(empty($this->payment_account_id)) { |
|
| 537 | + if (empty($this->payment_account_id)) { |
|
| 538 | 538 | $this->payment_account_id = $request_account_id; |
| 539 | 539 | } |
| 540 | 540 | // Если у нас отличаются ИД аккаунта в запросе и ИД аккаунта в записи - тоже можно паниковать |
| 541 | - if($this->payment_account_id != $request_account_id) { |
|
| 541 | + if ($this->payment_account_id != $request_account_id) { |
|
| 542 | 542 | // TODO - Поменять сообщение об ошибке |
| 543 | 543 | throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'], $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
| 544 | 544 | } |
| 545 | 545 | // Проверяем существование аккаунта с данным ИД |
| 546 | - if(!$this->account->db_get_by_id($this->payment_account_id)) { |
|
| 547 | - throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'] . ' ID ' . $this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
|
| 546 | + if (!$this->account->db_get_by_id($this->payment_account_id)) { |
|
| 547 | + throw new Exception(classLocale::$lang['pay_msg_request_user_invalid'].' ID '.$this->payment_account_id, $this->retranslate_error(SN_PAYMENT_REQUEST_USER_NOT_FOUND, $options)); |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | // TODO Проверка на сервер_ид - как бы и не нужна, наверное? |
| 551 | - if(!empty($this->payment_params['server_id'])) { |
|
| 551 | + if (!empty($this->payment_params['server_id'])) { |
|
| 552 | 552 | $this->request_server_id = sys_get_param_str($this->payment_params['server_id']); |
| 553 | - if(SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
| 554 | - throw new Exception(classLocale::$lang['pay_msg_request_server_wrong'] . " {$this->request_server_id} вместо " . SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
|
| 553 | + if (SN_ROOT_VIRTUAL != $this->request_server_id) { |
|
| 554 | + throw new Exception(classLocale::$lang['pay_msg_request_server_wrong']." {$this->request_server_id} вместо ".SN_ROOT_VIRTUAL, SN_PAYMENT_REQUEST_SERVER_WRONG); |
|
| 555 | 555 | } |
| 556 | 556 | } |
| 557 | 557 | |
| 558 | 558 | // Сверка количества оплаченной ММ с учётом бонусов |
| 559 | - if(!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
| 559 | + if (!empty($this->payment_params['payment_dark_matter_gained'])) { |
|
| 560 | 560 | $request_mm_amount = sys_get_param_id($this->payment_params['payment_dark_matter_gained']); |
| 561 | - if($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
| 562 | - throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid'] . " пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
|
| 561 | + if ($request_mm_amount != $this->payment_dark_matter_gained && $this->is_loaded) { |
|
| 562 | + throw new Exception(classLocale::$lang['pay_msg_mm_request_amount_invalid']." пришло {$request_mm_amount} ММ вместо {$this->payment_dark_matter_gained} ММ", SN_PAYMENT_REQUEST_MM_AMOUNT_INVALID); |
|
| 563 | 563 | } |
| 564 | 564 | empty($this->payment_dark_matter_gained) ? $this->payment_dark_matter_gained = $request_mm_amount : false; |
| 565 | 565 | } |
| 566 | - if(empty($this->payment_dark_matter_paid)) { |
|
| 566 | + if (empty($this->payment_dark_matter_paid)) { |
|
| 567 | 567 | // TODO - обратный расчёт из gained |
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | // Проверка наличия внешнего ИД платежа |
| 571 | - if(!empty($this->payment_params['payment_external_id'])) { |
|
| 571 | + if (!empty($this->payment_params['payment_external_id'])) { |
|
| 572 | 572 | $request_payment_external_id = sys_get_param_id($this->payment_params['payment_external_id']); |
| 573 | - if(empty($request_payment_external_id)) { |
|
| 573 | + if (empty($request_payment_external_id)) { |
|
| 574 | 574 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
| 575 | - } elseif(!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
| 575 | + } elseif (!empty($this->payment_external_id) && $this->payment_external_id != $request_payment_external_id) { |
|
| 576 | 576 | // TODO - Может быть поменять сообщение |
| 577 | 577 | throw new exception(classLocale::$lang['pay_msg_request_payment_id_invalid'], SN_PAYMENT_REQUEST_EXTERNAL_ID_WRONG); |
| 578 | 578 | } |
| 579 | 579 | $this->payment_external_id = $request_payment_external_id; |
| 580 | 580 | } |
| 581 | 581 | // Сверка суммы, запрошенной СН к оплате |
| 582 | - if(!empty($this->payment_params['payment_external_money'])) { |
|
| 582 | + if (!empty($this->payment_params['payment_external_money'])) { |
|
| 583 | 583 | $request_money_out = sys_get_param_float($this->payment_params['payment_external_money']); |
| 584 | - if($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
| 585 | - throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 584 | + if ($request_money_out != $this->payment_external_amount && $this->is_loaded) { |
|
| 585 | + throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." пришло {$request_money_out} денег вместо {$this->payment_external_amount} денег", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 586 | 586 | } |
| 587 | 587 | empty($this->payment_external_amount) ? $this->payment_external_amount = $request_money_out : false; |
| 588 | 588 | } |
| 589 | 589 | // Заполняем поле валюты платёжной системы |
| 590 | - if(!empty($this->payment_params['payment_external_currency'])) { |
|
| 590 | + if (!empty($this->payment_params['payment_external_currency'])) { |
|
| 591 | 591 | $this->payment_external_currency = sys_get_param_str($this->payment_params['payment_external_currency']); |
| 592 | - if(empty($this->payment_external_currency)) { |
|
| 592 | + if (empty($this->payment_external_currency)) { |
|
| 593 | 593 | // TODO - поменять сообщение |
| 594 | - throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid'] . " {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 594 | + throw new Exception(classLocale::$lang['pay_msg_request_payment_amount_invalid']." {$this->payment_external_currency}", SN_PAYMENT_REQUEST_CURRENCY_AMOUNT_INVALID); |
|
| 595 | 595 | } |
| 596 | 596 | } |
| 597 | - if(empty($this->payment_external_currency)) { |
|
| 597 | + if (empty($this->payment_external_currency)) { |
|
| 598 | 598 | $this->payment_external_currency = $this->config['currency']; |
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | // Заполнение внутренней суммы и валюты из внешних данных |
| 602 | - if(empty($this->payment_currency)) { |
|
| 602 | + if (empty($this->payment_currency)) { |
|
| 603 | 603 | $this->payment_currency = classSupernova::$config->payment_currency_default; |
| 604 | 604 | } |
| 605 | - if(empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
| 605 | + if (empty($this->payment_amount) && !empty($this->payment_external_currency)) { |
|
| 606 | 606 | $this->payment_amount = self::currency_convert($this->payment_external_amount, $this->payment_external_currency, $this->payment_currency); |
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | // TODO - Тестовый режим |
| 610 | - if(!empty($this->payment_params['test'])) { |
|
| 610 | + if (!empty($this->payment_params['test'])) { |
|
| 611 | 611 | $this->payment_test = $this->config['test'] || sys_get_param_int($this->payment_params['test']); |
| 612 | 612 | } |
| 613 | 613 | |
@@ -634,21 +634,21 @@ discard block |
||
| 634 | 634 | sn_db_transaction_start(); |
| 635 | 635 | try { |
| 636 | 636 | $response = $this->payment_request_process(); |
| 637 | - } catch(Exception $e) { |
|
| 637 | + } catch (Exception $e) { |
|
| 638 | 638 | $response['result'] = $e->getCode(); |
| 639 | 639 | $response['message'] = $e->getMessage(); |
| 640 | 640 | } |
| 641 | 641 | |
| 642 | - if($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
| 642 | + if ($response['result'] == SN_PAYMENT_REQUEST_OK) { |
|
| 643 | 643 | sn_db_transaction_commit(); |
| 644 | - classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Успешный платёж', LOG_INFO_PAYMENT); |
|
| 644 | + classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Успешный платёж', LOG_INFO_PAYMENT); |
|
| 645 | 645 | } else { |
| 646 | 646 | sn_db_transaction_rollback(); |
| 647 | - classSupernova::$debug->warning('Результат операции: код ' . $response['result'] . ' сообщение "' . $response['message'] . '"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); |
|
| 647 | + classSupernova::$debug->warning('Результат операции: код '.$response['result'].' сообщение "'.$response['message'].'"', 'Ошибка платежа', LOG_INFO_PAYMENT, true); |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | // Переводим код результата из СН в код платежной системы |
| 651 | - if(is_array($this->result_translations) && !empty($this->result_translations)) { |
|
| 651 | + if (is_array($this->result_translations) && !empty($this->result_translations)) { |
|
| 652 | 652 | $response['result'] = isset($this->result_translations[$response['result']]) ? $this->result_translations[$response['result']] : $this->result_translations[SN_PAYMENT_REQUEST_UNDEFINED_ERROR]; |
| 653 | 653 | } |
| 654 | 654 | |
@@ -671,7 +671,7 @@ discard block |
||
| 671 | 671 | $currency_from = strtolower($currency_from); |
| 672 | 672 | $currency_to = strtolower($currency_to); |
| 673 | 673 | |
| 674 | - if($currency_from != $currency_to) { |
|
| 674 | + if ($currency_from != $currency_to) { |
|
| 675 | 675 | $exchange_from = get_exchange_rate($currency_from); |
| 676 | 676 | $exchange_to = get_exchange_rate($currency_to); |
| 677 | 677 | |
@@ -695,10 +695,10 @@ discard block |
||
| 695 | 695 | public static function bonus_calculate($dark_matter, $direct = true, $return_bonus = false) { |
| 696 | 696 | $bonus = 0; |
| 697 | 697 | $dark_matter_new = $dark_matter; |
| 698 | - if(!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
| 699 | - if($direct) { |
|
| 700 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 701 | - if($dm_for_bonus <= $dark_matter) { |
|
| 698 | + if (!empty(self::$bonus_table) && $dark_matter >= self::$bonus_table[0]) { |
|
| 699 | + if ($direct) { |
|
| 700 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 701 | + if ($dm_for_bonus <= $dark_matter) { |
|
| 702 | 702 | $dark_matter_new = $dark_matter * (1 + $multiplier); |
| 703 | 703 | $bonus = $multiplier; |
| 704 | 704 | } else { |
@@ -706,9 +706,9 @@ discard block |
||
| 706 | 706 | } |
| 707 | 707 | } |
| 708 | 708 | } else { |
| 709 | - foreach(self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 709 | + foreach (self::$bonus_table as $dm_for_bonus => $multiplier) { |
|
| 710 | 710 | $temp = $dm_for_bonus * (1 + $multiplier); |
| 711 | - if($dark_matter >= $temp) { |
|
| 711 | + if ($dark_matter >= $temp) { |
|
| 712 | 712 | $dark_matter_new = round($dark_matter / (1 + $multiplier)); |
| 713 | 713 | $bonus = $multiplier; |
| 714 | 714 | } else { |
@@ -762,22 +762,22 @@ discard block |
||
| 762 | 762 | ); |
| 763 | 763 | |
| 764 | 764 | $replace = false; |
| 765 | - if($this->payment_id) { |
|
| 765 | + if ($this->payment_id) { |
|
| 766 | 766 | $payment['payment_id'] = $this->payment_id; |
| 767 | 767 | $replace = true; |
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | $query = array(); |
| 771 | - foreach($payment as $key => $value) { |
|
| 772 | - $value = is_string($value) ? '"' . db_escape($value) . '"' : $value; |
|
| 771 | + foreach ($payment as $key => $value) { |
|
| 772 | + $value = is_string($value) ? '"'.db_escape($value).'"' : $value; |
|
| 773 | 773 | $query[] = "`{$key}` = {$value}"; |
| 774 | 774 | } |
| 775 | 775 | |
| 776 | - $longQuery = ' INTO `{{payment}}` SET ' . implode(',', $query) . ';'; |
|
| 777 | - if($replace) { |
|
| 778 | - $this->db->doReplace('REPLACE' . $longQuery); |
|
| 776 | + $longQuery = ' INTO `{{payment}}` SET '.implode(',', $query).';'; |
|
| 777 | + if ($replace) { |
|
| 778 | + $this->db->doReplace('REPLACE'.$longQuery); |
|
| 779 | 779 | } else { |
| 780 | - $this->db->doInsert('INSERT' . $longQuery); |
|
| 780 | + $this->db->doInsert('INSERT'.$longQuery); |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | return $this->db_get_by_id($this->db->db_insert_id()); |
@@ -785,12 +785,12 @@ discard block |
||
| 785 | 785 | |
| 786 | 786 | |
| 787 | 787 | public function payment_adjust_mm_new() { |
| 788 | - if(!$this->payment_test) { |
|
| 788 | + if (!$this->payment_test) { |
|
| 789 | 789 | // Not a test payment. Adding DM to account |
| 790 | 790 | $this->account = new Account($this->db); |
| 791 | 791 | $this->account->db_get_by_id($this->payment_account_id); |
| 792 | 792 | $result = $this->account->metamatter_change(RPG_PURCHASE, $this->payment_dark_matter_gained, $this->payment_comment); |
| 793 | - if(!$result) { |
|
| 793 | + if (!$result) { |
|
| 794 | 794 | throw new Exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
| 795 | 795 | } |
| 796 | 796 | } |
@@ -799,25 +799,25 @@ discard block |
||
| 799 | 799 | public function payment_cancel(&$payment) { |
| 800 | 800 | die('{НЕ РАБОТАЕТ! СООБЩИТЕ АДМИНИСТРАЦИИ!}'); |
| 801 | 801 | |
| 802 | - if(!isset($payment['payment_status'])) { |
|
| 802 | + if (!isset($payment['payment_status'])) { |
|
| 803 | 803 | throw new exception(classLocale::$lang['pay_msg_request_payment_not_found'], SN_PAYMENT_REQUEST_ORDER_NOT_FOUND); |
| 804 | 804 | } |
| 805 | 805 | |
| 806 | - if($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
| 807 | - $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'] .' ' . $payment['payment_comment']); |
|
| 806 | + if ($payment['payment_status'] == PAYMENT_STATUS_COMPLETE) { |
|
| 807 | + $safe_comment = db_escape($payment['payment_comment'] = classLocale::$lang['pay_msg_request_payment_cancelled'].' '.$payment['payment_comment']); |
|
| 808 | 808 | |
| 809 | - if(!$payment['payment_test']) { |
|
| 809 | + if (!$payment['payment_test']) { |
|
| 810 | 810 | $result = $this->account->metamatter_change(RPG_PURCHASE_CANCEL, -$payment['payment_dark_matter_gained'], $payment['payment_comment']); |
| 811 | - if(!$result) { |
|
| 811 | + if (!$result) { |
|
| 812 | 812 | throw new exception('Ошибка начисления ММ', SN_METAMATTER_ERROR_ADJUST); |
| 813 | 813 | } |
| 814 | 814 | } |
| 815 | 815 | $payment['payment_status'] = PAYMENT_STATUS_CANCELED; |
| 816 | 816 | db_payment_update($payment, $safe_comment); |
| 817 | 817 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_complete'], SN_PAYMENT_REQUEST_OK); |
| 818 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
| 818 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_CANCELED) { |
|
| 819 | 819 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancelled_already'], SN_PAYMENT_REQUEST_OK); |
| 820 | - } elseif($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
| 820 | + } elseif ($payment['payment_status'] == PAYMENT_STATUS_NONE) { |
|
| 821 | 821 | throw new exception(classLocale::$lang['pay_msg_request_payment_cancel_not_complete'], SN_PAYMENT_REQUEST_PAYMENT_NOT_COMPLETE); |
| 822 | 822 | } |
| 823 | 823 | } |
@@ -840,8 +840,8 @@ discard block |
||
| 840 | 840 | |
| 841 | 841 | protected function db_complete_payment() { |
| 842 | 842 | // TODO - поле payment_processed |
| 843 | - if($this->payment_status == PAYMENT_STATUS_NONE) { |
|
| 844 | - if(!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
| 843 | + if ($this->payment_status == PAYMENT_STATUS_NONE) { |
|
| 844 | + if (!defined('PAYMENT_EXPIRE_TIME') || PAYMENT_EXPIRE_TIME == 0 || empty($this->payment_date) || strtotime($this->payment_date) + PAYMENT_EXPIRE_TIME <= SN_TIME_NOW) { |
|
| 845 | 845 | $this->payment_adjust_mm_new(); |
| 846 | 846 | $this->payment_status = PAYMENT_STATUS_COMPLETE; |
| 847 | 847 | } else { |
@@ -888,7 +888,7 @@ discard block |
||
| 888 | 888 | protected function db_assign_payment($payment = null) { |
| 889 | 889 | $this->payment_reset(); |
| 890 | 890 | |
| 891 | - if(is_array($payment) && isset($payment['payment_id'])) { |
|
| 891 | + if (is_array($payment) && isset($payment['payment_id'])) { |
|
| 892 | 892 | $this->payment_id = $payment['payment_id']; |
| 893 | 893 | $this->payment_status = $payment['payment_status']; |
| 894 | 894 | $this->payment_date = $payment['payment_date']; |
@@ -930,11 +930,11 @@ discard block |
||
| 930 | 930 | protected function generate_description() { |
| 931 | 931 | // TODO - системная локализация |
| 932 | 932 | $this->description_generated = array( |
| 933 | - PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на " . SN_ROOT_VIRTUAL, 0, 100), |
|
| 934 | - PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL, 0, 250), |
|
| 935 | - PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : '') . |
|
| 936 | - "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере " . SN_ROOT_VIRTUAL . |
|
| 937 | - " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)" . |
|
| 933 | + PAYMENT_DESCRIPTION_100 => substr("{$this->payment_dark_matter_gained} ММ аккаунт [{$this->account->account_name}] ID {$this->account->account_id} на ".SN_ROOT_VIRTUAL, 0, 100), |
|
| 934 | + PAYMENT_DESCRIPTION_250 => substr("Оплата {$this->payment_dark_matter_gained} ММ для аккаунта [{$this->payment_user_name}] ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL, 0, 250), |
|
| 935 | + PAYMENT_DESCRIPTION_MAX => ($this->payment_test ? "ТЕСТОВЫЙ ПЛАТЕЖ! " : ''). |
|
| 936 | + "Платеж от аккаунта '{$this->payment_account_name}' ID {$this->payment_account_id} игрока '{$this->payment_user_name}' ID {$this->payment_user_id} на сервере ".SN_ROOT_VIRTUAL. |
|
| 937 | + " сумма {$this->payment_amount} {$this->payment_currency} за {$this->payment_dark_matter_paid} ММ (начислено {$this->payment_dark_matter_gained} ММ)". |
|
| 938 | 938 | " через '{$this->manifest['name']}' сумма {$this->payment_external_amount} {$this->payment_external_currency}", |
| 939 | 939 | ); |
| 940 | 940 | } |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param $note_id_edit |
| 37 | 37 | */ |
| 38 | 38 | public static function db_note_update_by_id($note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky, $note_id_edit) { |
| 39 | - classSupernova::$db->doUpdate("UPDATE {{notes}} SET `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}', |
|
| 39 | + classSupernova::$db->doUpdate("UPDATE {{notes}} SET `time` = ".SN_TIME_NOW.", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}', |
|
| 40 | 40 | `galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky} |
| 41 | 41 | WHERE `id` = {$note_id_edit} LIMIT 1;"); |
| 42 | 42 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @param $note_sticky |
| 54 | 54 | */ |
| 55 | 55 | public static function db_note_insert($user, $note_priority, $note_title, $note_text, $note_galaxy, $note_system, $note_planet, $note_planet_type, $note_sticky) { |
| 56 | - classSupernova::$db->doInsert("INSERT INTO {{notes}} SET `owner` = {$user['id']}, `time` = " . SN_TIME_NOW . ", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}', |
|
| 56 | + classSupernova::$db->doInsert("INSERT INTO {{notes}} SET `owner` = {$user['id']}, `time` = ".SN_TIME_NOW.", `priority` = {$note_priority}, `title` = '{$note_title}', `text` = '{$note_text}', |
|
| 57 | 57 | `galaxy` = {$note_galaxy}, `system` = {$note_system}, `planet` = {$note_planet}, `planet_type` = {$note_planet_type}, `sticky` = {$note_sticky};"); |
| 58 | 58 | } |
| 59 | 59 | |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | ->setIdField($entity->getIdFieldName()) |
| 19 | 19 | ->field('*') |
| 20 | 20 | ->from($entity->getTableName()) |
| 21 | - ->where($entity->getIdFieldName() . ' = "' . $entity->dbId . '"'); |
|
| 21 | + ->where($entity->getIdFieldName().' = "'.$entity->dbId.'"'); |
|
| 22 | 22 | |
| 23 | 23 | return $stmt->selectRow(); |
| 24 | 24 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | public function deleteById($entity) { |
| 30 | 30 | $db = $entity->getDbStatic(); |
| 31 | 31 | |
| 32 | - $db->doDelete("DELETE FROM `{{" . $entity->getTableName() . "}}` WHERE `{$entity->getIdFieldName()}` = '{$entity->dbId}' LIMIT 1;"); |
|
| 32 | + $db->doDelete("DELETE FROM `{{".$entity->getTableName()."}}` WHERE `{$entity->getIdFieldName()}` = '{$entity->dbId}' LIMIT 1;"); |
|
| 33 | 33 | |
| 34 | 34 | return $db->db_affected_rows(); |
| 35 | 35 | } |
@@ -43,8 +43,8 @@ discard block |
||
| 43 | 43 | $query = array(); |
| 44 | 44 | foreach ($entity->exportRowWithoutId() as $fieldName => $fieldValue) { |
| 45 | 45 | // TODO: MORE type detection |
| 46 | - if(!is_numeric($fieldValue)) { |
|
| 47 | - $fieldValue = "'" . $db->db_escape($fieldValue) . "'"; |
|
| 46 | + if (!is_numeric($fieldValue)) { |
|
| 47 | + $fieldValue = "'".$db->db_escape($fieldValue)."'"; |
|
| 48 | 48 | } |
| 49 | 49 | $query[] = "`{$fieldName}` = {$fieldValue}"; |
| 50 | 50 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | return 0; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - $db->doInsert("INSERT INTO `{{" . $entity->getTableName() . "}}` SET " . $query); |
|
| 58 | + $db->doInsert("INSERT INTO `{{".$entity->getTableName()."}}` SET ".$query); |
|
| 59 | 59 | |
| 60 | 60 | // TODO Exceptiion if db_insert_id() is empty |
| 61 | 61 | return $entity->dbId = $db->db_insert_id(); |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | * @param db_mysql|null $db |
| 87 | 87 | */ |
| 88 | 88 | public static function setDb($db = null) { |
| 89 | - if(empty($db) || !($db instanceof db_mysql)) { |
|
| 89 | + if (empty($db) || !($db instanceof db_mysql)) { |
|
| 90 | 90 | $db = null; |
| 91 | 91 | } |
| 92 | 92 | static::$db = !empty($db) || !class_exists('classSupernova', false) ? $db : classSupernova::$db; |
@@ -149,7 +149,7 @@ discard block |
||
| 149 | 149 | public function dbLoad($dbId, $lockSkip = false) { |
| 150 | 150 | $dbId = idval($dbId); |
| 151 | 151 | if ($dbId <= 0) { |
| 152 | - classSupernova::$debug->error(get_called_class() . '::' . __METHOD__ . ' $dbId not positive = ' . $dbId); |
|
| 152 | + classSupernova::$debug->error(get_called_class().'::'.__METHOD__.' $dbId not positive = '.$dbId); |
|
| 153 | 153 | |
| 154 | 154 | return; |
| 155 | 155 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | $this->dbGetLockById($this->_dbId); |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - $db_row = classSupernova::$db->doSelectFetch("SELECT * FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId . " LIMIT 1 FOR UPDATE;"); |
|
| 164 | + $db_row = classSupernova::$db->doSelectFetch("SELECT * FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId." LIMIT 1 FOR UPDATE;"); |
|
| 165 | 165 | if (empty($db_row)) { |
| 166 | 166 | return; |
| 167 | 167 | } |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | if ($this->isNew()) { |
| 194 | 194 | // No DB_ID - new unit |
| 195 | 195 | if ($this->isEmpty()) { |
| 196 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - object is empty on ' . get_called_class() . '::dbSave'); |
|
| 196 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - object is empty on '.get_called_class().'::dbSave'); |
|
| 197 | 197 | } |
| 198 | 198 | $this->dbInsert(); |
| 199 | 199 | } else { |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $this->dbDelete(); |
| 203 | 203 | } else { |
| 204 | 204 | if (!sn_db_transaction_check(false)) { |
| 205 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - transaction should always be started on ' . get_called_class() . '::dbUpdate'); |
|
| 205 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - transaction should always be started on '.get_called_class().'::dbUpdate'); |
|
| 206 | 206 | } |
| 207 | 207 | $this->dbUpdate(); |
| 208 | 208 | } |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | // TODO - protected |
| 231 | 231 | public function dbInsert() { |
| 232 | 232 | if (!$this->isNew()) { |
| 233 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - record db_id is not empty on ' . get_called_class() . '::dbInsert'); |
|
| 233 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - record db_id is not empty on '.get_called_class().'::dbInsert'); |
|
| 234 | 234 | } |
| 235 | 235 | $this->_dbId = $this->db_field_set_create($this->dbMakeFieldSet()); |
| 236 | 236 | |
| 237 | 237 | if (empty($this->_dbId)) { |
| 238 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - error saving record ' . get_called_class() . '::dbInsert'); |
|
| 238 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - error saving record '.get_called_class().'::dbInsert'); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | return $this->_dbId; |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | public function dbUpdate() { |
| 249 | 249 | // TODO - Update |
| 250 | 250 | if ($this->isNew()) { |
| 251 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbUpdate'); |
|
| 251 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbUpdate'); |
|
| 252 | 252 | } |
| 253 | 253 | $this->db_field_update($this->dbMakeFieldSet(true)); |
| 254 | 254 | } |
@@ -259,9 +259,9 @@ discard block |
||
| 259 | 259 | // TODO - protected |
| 260 | 260 | public function dbDelete() { |
| 261 | 261 | if ($this->isNew()) { |
| 262 | - classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbDelete'); |
|
| 262 | + classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbDelete'); |
|
| 263 | 263 | } |
| 264 | - classSupernova::$db->doDelete("DELETE FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId); |
|
| 264 | + classSupernova::$db->doDelete("DELETE FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId); |
|
| 265 | 265 | $this->_dbId = 0; |
| 266 | 266 | // Обо всём остальном должен позаботиться контейнер |
| 267 | 267 | } |
@@ -414,7 +414,7 @@ discard block |
||
| 414 | 414 | $fields = implode(',', array_keys($field_set)); |
| 415 | 415 | |
| 416 | 416 | $result = 0; |
| 417 | - if (classSupernova::$db->doInsert("INSERT INTO `{{" . static::$_table . "}}` ({$fields}) VALUES ({$values});")) { |
|
| 417 | + if (classSupernova::$db->doInsert("INSERT INTO `{{".static::$_table."}}` ({$fields}) VALUES ({$values});")) { |
|
| 418 | 418 | $result = classSupernova::$db->db_insert_id(); |
| 419 | 419 | } |
| 420 | 420 | |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | return empty($set_string) |
| 452 | 452 | ? true |
| 453 | - : classSupernova::$db->doUpdate("UPDATE `{{" . static::$_table . "}}` SET {$set_string} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId); |
|
| 453 | + : classSupernova::$db->doUpdate("UPDATE `{{".static::$_table."}}` SET {$set_string} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId); |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | } |
@@ -66,9 +66,9 @@ discard block |
||
| 66 | 66 | `ally_name` = '{$ally_name}', |
| 67 | 67 | `ally_tag` = '{$ally_tag}', |
| 68 | 68 | `ally_owner` = '{$user['id']}', |
| 69 | - `ally_owner_range` = '" . classLocale::$lang['ali_leaderRank'] . "', |
|
| 69 | + `ally_owner_range` = '".classLocale::$lang['ali_leaderRank']."', |
|
| 70 | 70 | `ally_members` = 1, |
| 71 | - `ranklist` = '" . classLocale::$lang['ali_defaultRankName'] . ",0,0,0,0,0', |
|
| 71 | + `ranklist` = '" . classLocale::$lang['ali_defaultRankName'].",0,0,0,0,0', |
|
| 72 | 72 | `ally_register_time`= " . SN_TIME_NOW |
| 73 | 73 | ); |
| 74 | 74 | |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @param $POST_text |
| 90 | 90 | */ |
| 91 | 91 | public static function db_ally_request_insert($user, $id_ally, $POST_text) { |
| 92 | - classSupernova::$db->doInsert("INSERT INTO {{alliance_requests}} SET `id_user` = {$user['id']}, `id_ally`='{$id_ally}', request_text ='{$POST_text}', request_time=" . SN_TIME_NOW . ";"); |
|
| 92 | + classSupernova::$db->doInsert("INSERT INTO {{alliance_requests}} SET `id_user` = {$user['id']}, `id_ally`='{$id_ally}', request_text ='{$POST_text}', request_time=".SN_TIME_NOW.";"); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @param $ally |
| 140 | 140 | */ |
| 141 | 141 | public static function db_ally_update_by_changeset($ally_changeset, $ally) { |
| 142 | - classSupernova::$db->doUpdate("UPDATE {{alliance}} SET " . implode(',', $ally_changeset) . " WHERE `id`='{$ally['id']}' LIMIT 1;"); |
|
| 142 | + classSupernova::$db->doUpdate("UPDATE {{alliance}} SET ".implode(',', $ally_changeset)." WHERE `id`='{$ally['id']}' LIMIT 1;"); |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * @param $d |
| 251 | 251 | */ |
| 252 | 252 | public static function db_ally_request_deny($d) { |
| 253 | - classSupernova::$db->doUpdate("UPDATE {{alliance_requests}} SET `request_denied` = 1, `request_text` = '" . classLocale::$lang['ali_req_deny_reason'] . "' WHERE `id_user`= {$d} LIMIT 1;"); |
|
| 253 | + classSupernova::$db->doUpdate("UPDATE {{alliance_requests}} SET `request_denied` = 1, `request_text` = '".classLocale::$lang['ali_req_deny_reason']."' WHERE `id_user`= {$d} LIMIT 1;"); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | JOIN {{users}} AS u ON u.id = cp.chat_player_player_id |
| 13 | 13 | WHERE |
| 14 | 14 | `chat_player_refresh_last` >= '{$sql_date}' |
| 15 | - AND (`banaday` IS NULL OR `banaday` <= " . SN_TIME_NOW . ") |
|
| 15 | + AND (`banaday` IS NULL OR `banaday` <= ".SN_TIME_NOW.") |
|
| 16 | 16 | {$ally_add} |
| 17 | 17 | ORDER BY authlevel DESC, `username`"); |
| 18 | 18 | } |
@@ -35,7 +35,7 @@ discard block |
||
| 35 | 35 | `user` = '{$nick}', |
| 36 | 36 | `ally_id` = '{$ally_id}', |
| 37 | 37 | `message` = '{$message}', |
| 38 | - `timestamp` = " . SN_TIME_NOW . ", |
|
| 38 | + `timestamp` = ".SN_TIME_NOW.", |
|
| 39 | 39 | `chat_message_sender_name` = '{$chat_message_sender_name}', |
| 40 | 40 | `chat_message_recipient_id` = {$chat_message_recipient_id}, |
| 41 | 41 | `chat_message_recipient_name` = '{$chat_message_recipient_name}'" |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | * @param $user |
| 142 | 142 | */ |
| 143 | 143 | public static function db_chat_player_update($user) { |
| 144 | - classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_refresh_last` = " . SN_TIME_NOW . " WHERE `chat_player_player_id` = {$user['id']} LIMIT 1;"); |
|
| 144 | + classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_refresh_last` = ".SN_TIME_NOW." WHERE `chat_player_player_id` = {$user['id']} LIMIT 1;"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | * @param $user |
| 213 | 213 | */ |
| 214 | 214 | public static function db_chat_player_update_activity($user) { |
| 215 | - classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_activity` = '" . classSupernova::$db->db_escape(SN_TIME_SQL) . "' WHERE `chat_player_player_id` = {$user['id']} LIMIT 1"); |
|
| 215 | + classSupernova::$db->doUpdate("UPDATE {{chat_player}} SET `chat_player_activity` = '".classSupernova::$db->db_escape(SN_TIME_SQL)."' WHERE `chat_player_player_id` = {$user['id']} LIMIT 1"); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | } |
| 219 | 219 | \ No newline at end of file |