Completed
Push — work-fleets ( 41da5d...c94fa6 )
by SuperNova.WS
06:35
created

DBStaticAlly::db_ally_update_by_changeset()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 2
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
ccs 0
cts 3
cp 0
crap 2
1
<?php
2
3
class DBStaticAlly {
4
5
// ALLY *************************************************************************************************************
6
  public static function db_ally_list_recalc_counts() {
7
    classSupernova::$db->doUpdateSqlNoParam(
8
      "UPDATE `{{alliance}}` AS a 
9
        LEFT JOIN (
10
          SELECT `ally_id`, count(*) AS ally_memeber_count 
11
          FROM `{{users}}`
12
          WHERE `ally_id` IS NOT NULL 
13
          GROUP BY ally_id
14
        ) AS u ON u.`ally_id` = a.`id` 
15
      SET 
16
        a.`ally_members` = u.ally_memeber_count;"
17
    );
18
  }
19
20
  public static function db_ally_request_list($ally_id) {
21
    return classSupernova::$db->doSelect("SELECT {{alliance_requests}}.*, {{users}}.username FROM {{alliance_requests}} LEFT JOIN {{users}} ON {{users}}.id = {{alliance_requests}}.id_user WHERE id_ally='{$ally_id}'");
22
  }
23
24
  public static function db_ally_request_get_by_user_id($player_id) {
25
    return classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_requests}} WHERE `id_user` ='{$player_id}' LIMIT 1;");
26
  }
27
28
  public static function db_ally_count() {
29
    $result = classSupernova::$db->doSelectFetch('SELECT COUNT(`id`) AS ally_count FROM `{{alliance}}`');
30
31
    return isset($result['ally_count']) ? $result['ally_count'] : 0;
32
  }
33
34
  /**
35
   * @param $id_ally
36
   *
37
   * @return array|bool|mysqli_result|null
38
   */
39
  public static function db_ally_get_by_id($id_ally) {
40
    $ally = classSupernova::$db->doSelectFetch("SELECT * FROM `{{alliance}}` WHERE `id` ='{$id_ally}' LIMIT 1");
41
42
    return $ally;
43
  }
44
45
  /**
46
   * @param $searchtext
47
   *
48
   * @return array|bool|mysqli_result|null
49
   */
50
  public static function db_ally_list_search($searchtext) {
51
    $search = classSupernova::$db->doSelect("SELECT ally_name, ally_tag, total_rank, ally_members FROM {{alliance}} WHERE ally_tag LIKE '%{$searchtext}%' OR ally_name LIKE '%{$searchtext}%' LIMIT 30");
52
53
    return $search;
54
  }
55
56
  /**
57
   * @param $ally_tag
58
   * @param $ally_name
59
   *
60
   * @return array|bool|mysqli_result|null
61
   */
62
  public static function db_ally_get_by_name_or_tag($ally_tag, $ally_name) {
63
    $query = classSupernova::$db->doSelectFetch("SELECT ally_tag FROM {{alliance}} WHERE `ally_tag` = '{$ally_tag}' or `ally_name` = '{$ally_name}' LIMIT 1;");
64
65
    return $query;
66
  }
67
68
  /**
69
   * @param $ally_name_unsafe
70
   * @param $ally_tag_unsafe
71
   * @param $userId
72
   */
73
  public static function db_ally_insert($ally_name_unsafe, $ally_tag_unsafe, $userId) {
74
    $ally = classSupernova::$db->doInsertSet(TABLE_ALLIANCE, array(
75
      'ally_name'          => (string)$ally_name_unsafe,
76
      'ally_tag'           => (string)$ally_tag_unsafe,
77
      'ally_owner'         => $userId,
78
      'ally_owner_range'   => (string)classLocale::$lang['ali_leaderRank'],
79
      'ally_members'       => (int)1,
80
      'ranklist'           => (string)(classLocale::$lang['ali_defaultRankName'] . ",0,0,0,0,0"),
81
      'ally_register_time' => SN_TIME_NOW,
82
    ));
83
84
    return $ally;
85
  }
86
87
  /**
88
   * @param $ally_user_id
89
   * @param $ally_id
90
   */
91
  public static function db_ally_update_ally_user($ally_user_id, $ally_id) {
92
    classSupernova::$db->doUpdateRowSet(
93
      TABLE_ALLIANCE,
94
      array(
95
        'ally_user_id' => $ally_user_id,
96
      ),
97
      array(
98
        'id' => $ally_id,
99
      )
100
    );
101
  }
102
103
  /**
104
   * @param int    $userId
105
   * @param int    $id_ally
106
   * @param string $requestTextUnsafe
107
   */
108
  public static function db_ally_request_insert($userId, $id_ally, $requestTextUnsafe) {
109
    classSupernova::$db->doInsertSet(TABLE_ALLIANCE_REQUESTS, array(
110
      'id_user'      => $userId,
111
      'id_ally'      => $id_ally,
112
      'request_text' => $requestTextUnsafe,
113
      'request_time' => SN_TIME_NOW,
114
    ));
115
  }
116
117
  /**
118
   * @param $userId
119
   */
120
  public static function db_ally_request_delete_own($userId, $allyId) {
121
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE_REQUESTS, array('id_user' => $userId, 'id_ally' => $allyId,));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
122
  }
123
124
125
  /**
126
   * @param $tag
127
   *
128
   * @return array|bool|mysqli_result|null
129
   */
130
  public static function db_ally_get_by_tag($tag) {
131
    $ally = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance}} WHERE ally_tag='{$tag}' LIMIT 1;");
132
133
    return $ally;
134
  }
135
136
  /**
137
   * @param $ali_search_text
138
   *
139
   * @return array|bool|mysqli_result|null
140
   */
141
  public static function db_ally_search_by_name_or_tag($ali_search_text) {
142
    $search = classSupernova::$db->doSelect("SELECT DISTINCT * FROM {{alliance}} WHERE `ally_name` LIKE '%{$ali_search_text}%' OR `ally_tag` LIKE '%{$ali_search_text}%' LIMIT 30");
143
144
    return $search;
145
  }
146
147
  /**
148
   * @param $ally
149
   *
150
   * @return array|bool|mysqli_result|null
151
   */
152
  public static function db_ally_request_count_by_id($ally) {
153
    $request = classSupernova::$db->doSelectFetch("SELECT COUNT(*) AS request_count FROM {{alliance_requests}} WHERE `id_ally` ='{$ally['id']}'");
154
155
    return $request;
156
  }
157
158
159
  /**
160
   * @param $text_unsafe
161
   * @param $allyId
162
   * @param $fieldNameUnsafe
163
   */
164
  public static function db_ally_update_texts($text_unsafe, $allyId, $fieldNameUnsafe) {
165
    classSupernova::$db->doUpdateRowSet(
166
      TABLE_ALLIANCE,
167
      array(
168
        $fieldNameUnsafe => $text_unsafe,
169
      ),
170
      array(
171
        'id' => $allyId,
172
      )
173
    );
174
  }
175
176
  /**
177
   * @param $idNewLeader
178
   * @param $userAllyId
179
   */
180
  public static function db_ally_update_owner($idNewLeader, $userAllyId) {
181
    classSupernova::$db->doUpdateRowSet(
182
      TABLE_ALLIANCE,
183
      array(
184
        'ally_owner' => $idNewLeader,
185
      ),
186
      array(
187
        'id' => $userAllyId,
188
      )
189
    );
190
  }
191
192
  /**
193
   * @param int $allyId
194
   */
195
  public static function db_ally_delete($allyId) {
196
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE, array('id' => $allyId));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
197
  }
198
199
200
  /**
201
   * @param int $userAllyId
202
   * @param int $alliance_negotiation_contr_ally_id
203
   */
204
  public static function db_ally_negotiation_delete($userAllyId, $alliance_negotiation_contr_ally_id) {
205
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE_NEGOTIATION, array(
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
206
      'alliance_negotiation_ally_id'       => $userAllyId,
207
      'alliance_negotiation_contr_ally_id' => $alliance_negotiation_contr_ally_id,
208
    ));
209
  }
210
211
  /**
212
   * @param $offer_id
213
   *
214
   * @return array|bool|mysqli_result|null
215
   */
216
  public static function db_ally_negotiation_get_by_offer_id($offer_id) {
217
    $negotiation = classSupernova::$db->doSelectFetch("SELECT * FROM {{alliance_negotiation}} WHERE alliance_negotiation_id = {$offer_id} LIMIT 1;");
218
219
    return $negotiation;
220
  }
221
222
  /**
223
   * @param $offer_id
224
   */
225
  public static function db_ally_negotiation_delete_by_offer_id($offer_id) {
226
    classSupernova::$gc->db->doDeleteRowWhere(TABLE_ALLIANCE_NEGOTIATION, array('alliance_negotiation_id' => $offer_id));
0 ignored issues
show
Bug introduced by
The method doDeleteRowWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
227
  }
228
229
  /**
230
   * @param $offer_id
231
   */
232
  public static function db_ally_negotiation_deny($offer_id) {
233
    classSupernova::$db->doUpdateRowSet(
234
      TABLE_ALLIANCE_NEGOTIATION,
235
      array(
236
        'alliance_negotiation_status' => ALLY_PROPOSE_DENIED,
237
      ),
238
      array(
239
        'alliance_negotiation_id' => $offer_id,
240
      )
241
    );
242
  }
243
244
  /**
245
   * @param $negotiatorId
246
   * @param $userAllyId
247
   */
248
  public static function db_ally_negotiation_delete_extended($negotiatorId, $userAllyId) {
249
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_NEGOTIATION, array(
0 ignored issues
show
Bug introduced by
The method doDeleteWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
250
      'alliance_negotiation_id' => $negotiatorId,
251
      'alliance_negotiation_contr_ally_id' => $userAllyId,
252
    ));
253
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_NEGOTIATION, array(
254
      'alliance_negotiation_id' => $userAllyId,
255
      'alliance_negotiation_contr_ally_id' => $negotiatorId,
256
    ));
257
  }
258
259
  /**
260
   * @param $user
261
   *
262
   * @return array|bool|mysqli_result|null
263
   */
264
  public static function db_ally_list_get_by_not_user_ally($user) {
265
    $query = classSupernova::$db->doSelect("SELECT id, ally_name, ally_tag FROM {{alliance}} WHERE `id` != {$user['ally_id']} ORDER BY ally_name;");
266
267
    return $query;
268
  }
269
270
  /**
271
   * @param $user
272
   *
273
   * @return array|bool|mysqli_result|null
274
   */
275
  public static function db_ally_negotiation_list($user) {
276
    $query = classSupernova::$db->doSelect(
277
      "SELECT
278
        *,
279
        if(alliance_negotiation_ally_id = {$user['ally_id']}, 1, 0) AS owner,
280
        if(alliance_negotiation_ally_id = {$user['ally_id']}, alliance_negotiation_contr_ally_name, alliance_negotiation_ally_name) AS ally_name
281
      FROM
282
        {{alliance_negotiation}}
283
      WHERE
284
        alliance_negotiation_ally_id = {$user['ally_id']} OR alliance_negotiation_contr_ally_id = {$user['ally_id']};"
285
    );
286
287
    return $query;
288
  }
289
290
  /**
291
   * @param $id
292
   */
293
  public static function db_ally_request_deny($id) {
294
    classSupernova::$db->doUpdateRowSet(
295
      TABLE_ALLIANCE_REQUESTS,
296
      array(
297
        'request_denied' => ALLY_REQUEST_DENIED,
298
        'request_text' => classLocale::$lang['ali_req_deny_reason'],
299
      ),
300
      array(
301
        'id_user' => $id,
302
      )
303
    );
304
305
  }
306
307
  /**
308
   * @param $i
309
   * @param $allyId
310
   */
311
  public static function db_ally_update_member_set($i, $allyId) {
312
    classSupernova::$db->doUpdateRowSet(
313
      TABLE_ALLIANCE,
314
      array(
315
        'ally_members' => $i,
316
      ),
317
      array(
318
        'id' => $allyId,
319
      )
320
    );
321
  }
322
323
  /**
324
   * @param $id_user
325
   */
326
  public static function db_ally_request_delete_all_when_accepted($id_user) {
327
    classSupernova::$gc->db->doDeleteWhere(TABLE_ALLIANCE_REQUESTS, array('id_user' => $id_user));
0 ignored issues
show
Bug introduced by
The method doDeleteWhere does only exist in db_mysql, but not in Closure.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
328
  }
329
330
331
  /**
332
   * @param $user
333
   *
334
   * @return array|bool|mysqli_result|null
335
   */
336
  public static function db_ally_get_members_by_user_as_ally(&$user) {
337
    $alliance = classSupernova::$db->doSelectFetch("SELECT `ally_members` FROM {{alliance}} WHERE `ally_user_id` = {$user['id']}");
338
339
    return $alliance;
340
  }
341
342
  /**
343
   * @param $ranklist
344
   * @param $userAllyId
345
   */
346
  public static function db_ally_update_ranklist($ranklist, $userAllyId) {
347
    classSupernova::$db->doUpdateRowSet(
348
      TABLE_ALLIANCE,
349
      array(
350
        'ranklist' => $ranklist,
351
      ),
352
      array(
353
        'id' => $userAllyId,
354
      )
355
    );
356
  }
357
358
  /**
359
   * @param $ally_from
360
   * @param $ally_to
361
   *
362
   * @return array|bool|mysqli_result|null
363
   */
364
  public static function db_ally_diplomacy_get_relations($ally_from, $ally_to) {
365
    $query = classSupernova::$db->doSelect(
366
      "SELECT b.*
367
      FROM
368
        {{alliance_diplomacy}} AS b,
369
        (SELECT alliance_diplomacy_contr_ally_id, MAX(alliance_diplomacy_time) AS alliance_diplomacy_time
370
          FROM {{alliance_diplomacy}}
371
          WHERE alliance_diplomacy_ally_id = {$ally_from}  {$ally_to}
372
          GROUP BY alliance_diplomacy_ally_id, alliance_diplomacy_contr_ally_id
373
        ) AS m
374
      WHERE b.alliance_diplomacy_contr_ally_id = m.alliance_diplomacy_contr_ally_id
375
        AND b.alliance_diplomacy_time = m.alliance_diplomacy_time AND b.alliance_diplomacy_ally_id = {$ally_from}
376
      ORDER BY alliance_diplomacy_time, alliance_diplomacy_id;"
377
    );
378
379
    return $query;
380
  }
381
382
  /**
383
   * @param $user
384
   *
385
   * @return array|bool|mysqli_result|null
386
   */
387
  public static function db_ally_get_ally_count(&$user) {
388
    $lab_level = classSupernova::$db->doSelectFetch("SELECT ally_members AS effective_level FROM {{alliance}} WHERE id = {$user['user_as_ally']} LIMIT 1");
389
390
    return $lab_level;
391
  }
392
393
}