1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by Gorlum 19.08.2019 19:12 |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace Pages\Helpers; |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
use Alliance\Alliance; |
10
|
|
|
use classLocale; |
11
|
|
|
use mysqli_result; |
12
|
|
|
use SN; |
13
|
|
|
use SnTemplate; |
14
|
|
|
use template; |
15
|
|
|
|
16
|
|
|
class PageHelperAlly { |
17
|
|
|
/** |
18
|
|
|
* @param $mode |
19
|
|
|
* @param array $user |
20
|
|
|
* @param classLocale $lang |
21
|
|
|
*/ |
22
|
|
|
|
23
|
|
|
public static function pageExternalSearch($mode, array $user, classLocale $lang) { |
24
|
|
|
if (!defined('SN_IN_ALLY') || SN_IN_ALLY !== true) { |
25
|
|
|
SN::$debug->error("Attempt to call ALLIANCE page mode {$mode} directly - not from alliance.php", 'Forbidden', 403); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
$template = SnTemplate::gettemplate('ali_search', true); |
|
|
|
|
29
|
|
|
|
30
|
|
|
$ali_search_text = sys_get_param_str('searchtext'); |
31
|
|
|
|
32
|
|
|
if ($ali_search_text) { |
33
|
|
|
$template->assign_var('SEARCH_TEXT', $ali_search_text); |
34
|
|
|
|
35
|
|
|
$search = doquery("SELECT DISTINCT * FROM {{alliance}} WHERE `ally_name` LIKE '%{$ali_search_text}%' OR `ally_tag` LIKE '%{$ali_search_text}%' LIMIT 30"); |
|
|
|
|
36
|
|
|
if (db_num_rows($search)) { |
37
|
|
|
PageHelperAlly::allyFetchFromResult($template, $search, $user['total_points']); |
38
|
|
|
} |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
self::externalSearchRecommend($user, $template); |
42
|
|
|
|
43
|
|
|
SnTemplate::display($template, $lang['ali_search_title']); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param template $template |
49
|
|
|
* @param mysqli_result|null $result |
50
|
|
|
* @param int $playerPoints |
51
|
|
|
*/ |
52
|
|
|
public static function allyFetchFromResult(template $template, $result, $playerPoints = 0) { |
53
|
|
|
while ($ally_row = db_fetch($result)) { |
54
|
|
|
$perPlayer = $ally_row['total_points'] / $ally_row['ally_members']; |
55
|
|
|
$pointsDiff = round($playerPoints - $perPlayer); |
56
|
|
|
|
57
|
|
|
$pointsRate = $playerPoints / $perPlayer; |
58
|
|
|
$pointsRate = round($pointsRate, 2); |
59
|
|
|
|
60
|
|
|
// $pointsRate && $pointsRate < 1 ? $pointsRate = "1 / " . round(1 / $pointsRate, 2) : false; |
61
|
|
|
|
62
|
|
|
$template->assign_block_vars('alliances', array( |
63
|
|
|
'ID' => $ally_row['id'], |
64
|
|
|
'TAG' => $ally_row['ally_tag'], |
65
|
|
|
'NAME' => $ally_row['ally_name'], |
66
|
|
|
'MEMBERS' => $ally_row['ally_members'], |
67
|
|
|
'NO_REQUESTS' => $ally_row['ally_request_notallow'], |
68
|
|
|
'DIFF' => $pointsDiff, |
69
|
|
|
'RATE' => $pointsRate, |
70
|
|
|
)); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @param array $user |
76
|
|
|
* @param template $template |
77
|
|
|
*/ |
78
|
|
|
public static function externalSearchRecommend(array $user, template $template) { |
79
|
|
|
if (empty($user['ally_id'])) { |
80
|
|
|
$recommended = Alliance::recommend($user['total_points']); |
81
|
|
|
if (db_num_rows($recommended)) { |
82
|
|
|
$template->assign_block_vars('alliances', array( |
83
|
|
|
'ID' => -1, |
84
|
|
|
)); |
85
|
|
|
PageHelperAlly::allyFetchFromResult($template, $recommended, $user['total_points']); |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$template->assign_vars(['PAGE_HINT' => SN::$lang['ali_search_result_tip']]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
} |
93
|
|
|
|