OSDN Git Service

[modify]スコアページのテーブルCSS共通化
[hengband/web.git] / score / popularity_ranking.php
1 <?php
2 //ini_set('display_errors', 'On');
3
4 ini_set('log_errors', 'On');
5 ini_set('error_log', 'errors/'.pathinfo(__FILE__, PATHINFO_FILENAME).'.log');
6
7 ini_set('zlib.output_compression', 'On');
8
9 require_once "db_common.inc";
10 require_once "web_template.inc";
11
12 function print_popularity_table($fp, $stat, $id_name, $name)
13 {
14     fwrite($fp, <<<EOM
15 <div id="{$id_name}">
16 <table class="tablesorter score statistics_table">
17 <thead>
18 <tr>
19 <th>$name</th>
20
21 EOM
22     );
23     
24     foreach ([
25         '計', '男性', '女性', '勝利', '平均スコア', '最大スコア',
26     ] as $name) {
27         fwrite($fp, "<th>${name}</th>\n");
28     }
29     fwrite($fp, "</tr>\n".
30            "</thead>\n");
31
32     foreach ($stat as $k => $s) {
33         $name_link = "<a href='score_ranking.php?{$id_name}={$s['id']}'>{$s['name']}</a></td>";
34         $average_score = floor($s['average_score']);
35         fwrite($fp, <<<EOM
36 <tr>
37 <td>$name_link</td>
38 <td class="number">{$s['total_count']}</td>
39 <td class="number">{$s['male_count']}</td>
40 <td class="number">{$s['female_count']}</td>
41 <td class="number">{$s['winner_count']}</td>
42 <td class="number">$average_score</td>
43 <td class="number">{$s['max_score']}</td>
44 </tr>
45
46 EOM
47         );
48     }
49
50     fwrite($fp, "</table>\n".
51            "</div>\n");
52 }
53
54 function print_realm_popularity_table($fp, $stat, $id_name)
55 {
56     // 魔法領域の統計を職業ごとにグループ分け
57     $class_ids = array_unique(array_column($stat, "class_id"));
58     $class_realm_stat_list = array_fill_keys($class_ids, []);
59
60     foreach ($stat as $s) {
61         $class_realm_stat_list[intval($s["class_id"])][] = $s;
62     }
63
64     fwrite($fp, "<div id=\"{$id_name}\">");
65
66     // 職業ごとにテーブルを表示
67     foreach ($class_realm_stat_list as $class_id => $class_realm_stat) {
68         if (count($class_realm_stat) <= 1) continue; // 領域固定の職業は飛ばす
69
70         $class_name = $class_realm_stat[0]['class_name'];
71
72         fwrite($fp, <<<EOM
73 <table class="tablesorter score statistics_table" id="${id_name}">
74 <thead>
75 <tr>
76 <th>{$class_name}</th>
77
78 EOM
79         );
80         foreach ([
81             '計', '男性', '女性', '勝利', '平均スコア', '最大スコア',
82         ] as $th_name) {
83             fwrite($fp, "<th>${th_name}</th>\n");
84         }
85         fwrite($fp, "</tr>\n".
86                "</thead>\n");
87
88         foreach ($class_realm_stat as $realm) {
89             $name_link = "<a href='score_ranking.php?class_id={$class_id}&{$id_name}={$realm['realm_id']}'>{$realm['realm_name']}</a></td>";
90             $average_score = floor($realm['average_score']);
91             fwrite($fp, <<<EOM
92 <tr>
93 <td>$name_link</td>
94 <td class="number">{$realm['total_count']}</td>
95 <td class="number">{$realm['male_count']}</td>
96 <td class="number">{$realm['female_count']}</td>
97 <td class="number">{$realm['winner_count']}</td>
98 <td class="number">$average_score</td>
99 <td class="number">{$realm['max_score']}</td>
100 </tr>
101
102 EOM
103             );
104         }
105
106         fwrite($fp, "</table>\n");
107     }
108     fwrite($fp, "</div>\n");
109 }
110
111 $db = new ScoreDB();
112
113 $time_start = microtime(true);
114
115 $statistics = $db->get_statistics_tables('total_count');
116
117 $query_time = microtime(true) - $time_start;
118
119 $wt = new WebTemplate();
120
121 $wt->add_head_contents('<link rel="stylesheet" type="text/css" href="css/score-table.css">');
122 $wt->add_head_contents('<link rel="stylesheet" type="text/css" href="tablesorter-theme/style.css">');
123 $wt->add_head_contents(
124     <<<EOM
125 <script
126 src="https://code.jquery.com/jquery-3.3.1.min.js"
127 integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8="
128 crossorigin="anonymous"></script>
129 EOM
130 );
131 $wt->add_head_contents('<script src="jquery.tablesorter.min.js" type="text/javascript"></script>');
132 $wt->add_head_contents('<script src="popularity_ranking.js" type="text/javascript"></script>');
133 $wt->set_title("変愚蛮怒 スコアランキング 人気のある種族・職業・性格・魔法領域");
134
135 $fp = $wt->main_contents_fp();
136 fwrite($fp, "<h2>人気のある種族・職業・性格・魔法領域</h2>\n");
137 //fprintf($fp, "<small>(%.2f 秒)</small>", $query_time);
138 fwrite($fp, <<<EOM
139 <nobr>[ <a href="javascript:void(0)" class="table_select" id="race_id">種族</a> | <a href="javascript:void(0)" class="table_select" id="class_id">職業</a> | <a href="javascript:void(0)" class="table_select" id="personality_id">性格</a> ] [ <a href="javascript:void(0)" class="table_select" id="realm_id1">魔法領域1</a> | <a href="javascript:void(0)" class="table_select" id="realm_id2">魔法領域2</a> ]</nobr>
140
141 EOM
142
143 );
144
145 print_popularity_table($fp, $statistics['race'], 'race_id', "種族");
146 print_popularity_table($fp, $statistics['class'], 'class_id', "職業");
147 print_popularity_table($fp, $statistics['personality'], 'personality_id', "性格");
148 print_realm_popularity_table($fp, $statistics['realm1'], 'realm_id1');
149 print_realm_popularity_table($fp, $statistics['realm2'], 'realm_id2');
150
151 $wt->print_page();