Passed
Push — trunk ( 1c4b6b...c0c172 )
by SuperNova.WS
04:01
created

PlayerStatic::getPlayerProduction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 16
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 16
ccs 0
cts 16
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 05.03.2018 20:42
4
 */
5
6
namespace Player;
7
8
use SN;
9
use DBStaticPlanet;
10
11
/**
12
 * Class PlayerStatic
13
 * @package Player
14
 *
15
 * @deprecated
16
 */
17
class PlayerStatic {
18
19
  public static function getPlayerProduction($userId) {
20
    return doquery("       
21
       SELECT
22
         sum(metal_perhour) + sum(crystal_perhour) * 2 + sum(deuterium_perhour) * 4 AS `total`,
23
         sum(metal_perhour)                                                         AS `metal`,
24
         sum(crystal_perhour)                                                       AS `crystal`,
25
         sum(deuterium_perhour)                                                     AS `deuterium`,
26
         avg(metal_mine_porcent) AS `avg_metal_percent`,
27
         avg(crystal_mine_porcent) AS `avg_crystal_percent`,
28
         avg(deuterium_sintetizer_porcent) AS `avg_deuterium_percent`
29
       FROM
30
         `{{planets}}` AS p
31
       WHERE
32
         p.`id_owner` = {$userId}
33
       GROUP BY
34
         id_owner", true);
35
  }
36
37
  /**
38
   * @param $UserID
39
   *
40
   * @deprecated
41
   *
42
   * TODO: Full rewrite
43
   */
44
  public static function DeleteSelectedUser($UserID) {
45
    $internalTransaction = false;
46
    if (!sn_db_transaction_check(false)) {
47
      sn_db_transaction_start();
48
49
      $internalTransaction = true;
50
    }
51
52
    $TheUser = db_user_by_id($UserID);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

52
    $TheUser = /** @scrutinizer ignore-deprecated */ db_user_by_id($UserID);
Loading history...
53
54
    if (!empty($TheUser['ally_id'])) {
55
      $TheAlly = doquery("SELECT * FROM `{{alliance}}` WHERE `id` = '" . $TheUser['ally_id'] . "';", '', true);
56
      $TheAlly['ally_members'] -= 1;
57
      doquery("UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';");
58
59
//      if ( $TheAlly['ally_members'] > 0 ) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
46% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
60
//        doquery ( "UPDATE `{{alliance}}` SET `ally_members` = '" . $TheAlly['ally_members'] . "' WHERE `id` = '" . $TheAlly['id'] . "';");
61
//      } else {
62
//        doquery ( "DELETE FROM `{{alliance}}` WHERE `id` = '" . $TheAlly['id'] . "';");
63
//        doquery ( "DELETE FROM `{{statpoints}}` WHERE `stat_type` = '2' AND `id_owner` = '" . $TheAlly['id'] . "';");
64
//      }
65
    }
66
67
    // Deleting all fleets
68
    db_fleet_list_delete_by_owner($UserID);
69
70
    // Deleting all planets
71
    DBStaticPlanet::db_planet_list_delete_by_owner($UserID);
72
73
    // TEMPORARY player messages not deleted
74
//    doquery("DELETE FROM `{{messages}}` WHERE `message_sender` = '" . $UserID . "';");
75
//    doquery("DELETE FROM `{{messages}}` WHERE `message_owner` = '" . $UserID . "';");
76
77
    doquery("DELETE FROM `{{notes}}` WHERE `owner` = '" . $UserID . "';");
78
79
    doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_SENDER_ID` = '" . $UserID . "';");
80
    doquery("DELETE FROM `{{buddy}}` WHERE `BUDDY_OWNER_ID` = '" . $UserID . "';");
81
82
    doquery("DELETE FROM `{{referrals}}` WHERE (`id` = '{$UserID}') OR (`id_partner` = '{$UserID}');");
83
84
    doquery("DELETE FROM `{{statpoints}}` WHERE `stat_type` = '1' AND `id_owner` = '" . $UserID . "';");
85
86
    // Deleting all units
87
    SN::db_del_record_list(LOC_UNIT, "`unit_location_type` = " . LOC_PLAYER . " AND `unit_player_id` = " . $UserID);
88
89
    // Deleting player's record
90
    SN::db_del_record_by_id(LOC_USER, $UserID);
91
    SN::$config->pass()->users_amount = SN::$config->pass()->users_amount - 1;
92
93
    if ($internalTransaction) {
94
      sn_db_transaction_commit();
95
    }
96
  }
97
98
}
99