1 | <?php |
---|
2 | require_once("class.kill.php"); |
---|
3 | require_once("class.profiler.php"); |
---|
4 | require_once("class.pagesplitter.php"); |
---|
5 | |
---|
6 | class KillList |
---|
7 | { |
---|
8 | function KillList() |
---|
9 | { |
---|
10 | $this->qry_ = new DBQuery(); |
---|
11 | $this->killpointer_ = 0; |
---|
12 | $this->kills_ = 0; |
---|
13 | $this->losses_ = 0; |
---|
14 | $this->killisk_ = 0; |
---|
15 | $this->lossisk_ = 0; |
---|
16 | $this->exclude_scl_ = array(); |
---|
17 | $this->vic_scl_id_ = array(); |
---|
18 | $this->regions_ = array(); |
---|
19 | $this->groupby_ = array(); |
---|
20 | $this->offset_ = 0; |
---|
21 | $this->killcounter_ = 0; |
---|
22 | $this->realkillcounter_ = 0; |
---|
23 | $this->ordered_ = false; |
---|
24 | } |
---|
25 | |
---|
26 | function execQuery() |
---|
27 | { |
---|
28 | if (!$this->qry_->executed_) |
---|
29 | { |
---|
30 | if (!count($this->groupby_)) |
---|
31 | $this->sql_ = "select distinct kll.kll_id, kll.kll_timestamp, plt.plt_name, |
---|
32 | crp.crp_name, ali.all_name, kll.kll_ship_id, |
---|
33 | kll.kll_system_id, kll.kll_ship_id, |
---|
34 | kll.kll_victim_id, plt.plt_externalid, |
---|
35 | kll.kll_crp_id, kll.kll_points, |
---|
36 | shp.shp_class, shp.shp_name, |
---|
37 | shp.shp_externalid, |
---|
38 | scl.scl_id, scl.scl_class, scl.scl_value, |
---|
39 | sys.sys_name, sys.sys_sec, |
---|
40 | fbplt.plt_name as fbplt_name, |
---|
41 | fbcrp.crp_name as fbcrp_name"; |
---|
42 | |
---|
43 | global $config; |
---|
44 | if ($config->getConfig('ship_values')) |
---|
45 | { |
---|
46 | $this->sql_ .= ', ksv.shp_value'; |
---|
47 | } |
---|
48 | if (count($this->groupby_)) |
---|
49 | { |
---|
50 | $this->sql_ .= "select count(*) as cnt, " . implode(",", $this->groupby_); |
---|
51 | } |
---|
52 | |
---|
53 | $this->sql_ .= " from kb3_kills kll |
---|
54 | inner join kb3_ships shp |
---|
55 | on ( shp.shp_id = kll.kll_ship_id ) |
---|
56 | inner join kb3_ship_classes scl |
---|
57 | on ( scl.scl_id = shp.shp_class )"; |
---|
58 | if ($config->getConfig('ship_values')) |
---|
59 | { |
---|
60 | $this->sql_ .= ' left join kb3_ships_values ksv on (shp.shp_id = ksv.shp_id)'; |
---|
61 | } |
---|
62 | |
---|
63 | $this->sql_ .= "inner join kb3_pilots plt |
---|
64 | on ( plt.plt_id = kll.kll_victim_id ) |
---|
65 | inner join kb3_corps crp |
---|
66 | on ( crp.crp_id = kll.kll_crp_id ) |
---|
67 | inner join kb3_alliances ali |
---|
68 | on ( ali.all_id = kll.kll_all_id ) |
---|
69 | inner join kb3_pilots fbplt |
---|
70 | on ( fbplt.plt_id = kll.kll_fb_plt_id ) |
---|
71 | inner join kb3_corps fbcrp |
---|
72 | on ( fbcrp.crp_id = kll.kll_fb_crp_id ) |
---|
73 | inner join kb3_systems sys |
---|
74 | on ( sys.sys_id = kll.kll_system_id )"; |
---|
75 | |
---|
76 | // involved filter |
---|
77 | if (! $this->mixedinvolved_) |
---|
78 | { |
---|
79 | if ($this->inv_plt_) |
---|
80 | $this->sql_ .= " inner join kb3_inv_plt inp |
---|
81 | on ( inp.inp_plt_id in ( " . substr($this->inv_plt_, 0, strlen($this->inv_plt_) - 2) . " ) and kll.kll_id = inp.inp_kll_id ) "; |
---|
82 | if ($this->inv_crp_) |
---|
83 | $this->sql_ .= " inner join kb3_inv_crp inc |
---|
84 | on ( inc.inc_crp_id in ( " . substr($this->inv_crp_, 0, strlen($this->inv_crp_) - 2) . " ) and kll.kll_id = inc.inc_kll_id ) "; |
---|
85 | if ($this->inv_all_) |
---|
86 | $this->sql_ .= " inner join kb3_inv_all ina |
---|
87 | on ( ina.ina_all_id in ( " . substr($this->inv_all_, 0, strlen($this->inv_all_) - 2) . " ) and kll.kll_id = ina.ina_kll_id ) "; |
---|
88 | } |
---|
89 | else |
---|
90 | { |
---|
91 | $this->sql_ .= " <ph> "; |
---|
92 | } |
---|
93 | // echo $this->sql_; |
---|
94 | // regions |
---|
95 | if (count($this->regions_)) |
---|
96 | { |
---|
97 | $this->sql_ .= " inner join kb3_constellations con |
---|
98 | on ( con.con_id = sys.sys_con_id ) |
---|
99 | inner join kb3_regions reg |
---|
100 | on ( reg.reg_id = con.con_reg_id |
---|
101 | and reg.reg_id in ( " . implode($this->regions_, ",") . " ) )"; |
---|
102 | } |
---|
103 | // victim filter |
---|
104 | if ($this->mixedvictims_) |
---|
105 | { |
---|
106 | $this->sql_ .= " and ( 1 = 0 "; |
---|
107 | $op = "or"; |
---|
108 | } |
---|
109 | else $op = "and"; |
---|
110 | |
---|
111 | if ($this->vic_plt_) |
---|
112 | $this->sql_ .= " " . $op . " kll.kll_victim_id in ( " . substr($this->vic_plt_, 0, strlen($this->vic_plt_) - 2) . " )"; |
---|
113 | if ($this->vic_crp_) |
---|
114 | $this->sql_ .= " " . $op . " kll.kll_crp_id in ( " . substr($this->vic_crp_, 0, strlen($this->vic_crp_) - 2) . " )"; |
---|
115 | if ($this->vic_all_) |
---|
116 | $this->sql_ .= " " . $op . " kll.kll_all_id in ( " . substr($this->vic_all_, 0, strlen($this->vic_all_) - 2) . " )"; |
---|
117 | |
---|
118 | if ($this->mixedvictims_) |
---|
119 | $this->sql_ .= " ) "; |
---|
120 | // echo $this->sql_; |
---|
121 | // ship filter |
---|
122 | if (count($this->exclude_scl_)) |
---|
123 | { |
---|
124 | $this->sql_ .= " and scl.scl_id not in ( " . implode(",", $this->exclude_scl_) . " )"; |
---|
125 | } |
---|
126 | if (count($this->vic_scl_id_)) |
---|
127 | { |
---|
128 | $this->sql_ .= " and scl.scl_id in ( " . implode(",", $this->vic_scl_id_) . " )"; |
---|
129 | } |
---|
130 | // related |
---|
131 | if ($this->related_) |
---|
132 | { |
---|
133 | $rqry = new DBQuery(); |
---|
134 | $rsql = "select kll_timestamp, kll_system_id |
---|
135 | from kb3_kills |
---|
136 | where kll_id = " . $this->related_; |
---|
137 | |
---|
138 | $rqry->execute($rsql) or die($rqry->getErrorMsg()); |
---|
139 | $rrow = $rqry->getRow(); |
---|
140 | |
---|
141 | $this->sql_ .= " and kll.kll_system_id = " . $rrow['kll_system_id'] . " |
---|
142 | and kll.kll_timestamp <= |
---|
143 | date_add( '" . $rrow['kll_timestamp'] . "', INTERVAL '15:0' MINUTE_SECOND ) |
---|
144 | and kll.kll_timestamp >= |
---|
145 | date_sub( '" . $rrow['kll_timestamp'] . "', INTERVAL '15:0' MINUTE_SECOND )"; |
---|
146 | } |
---|
147 | // timeframe |
---|
148 | if ($this->timeframe_) |
---|
149 | $this->sql_ .= $this->timeframe_; |
---|
150 | |
---|
151 | if (!strpos($this->sql_, " join ") && !$this->mixedinvolved_) |
---|
152 | $this->sqlhead_ .= " where 1 = 1"; |
---|
153 | |
---|
154 | if ($this->mixedinvolved_) |
---|
155 | { |
---|
156 | if ($this->inv_plt_) |
---|
157 | { |
---|
158 | $replace = " inner join kb3_inv_plt inp |
---|
159 | on ( inp.inp_plt_id in ( " . substr($this->inv_plt_, 0, strlen($this->inv_plt_) - 2) . " ) and kll.kll_id = inp.inp_kll_id ) "; |
---|
160 | $psql = str_replace("<ph>", $replace, $this->sql_); |
---|
161 | } |
---|
162 | if ($this->inv_crp_) |
---|
163 | { |
---|
164 | $replace = " inner join kb3_inv_crp inc |
---|
165 | on ( inc.inc_crp_id in ( " . substr($this->inv_crp_, 0, strlen($this->inv_crp_) - 2) . " ) and kll.kll_id = inc.inc_kll_id ) "; |
---|
166 | $csql = str_replace("<ph>", $replace, $this->sql_); |
---|
167 | } |
---|
168 | if ($this->inv_all_) |
---|
169 | { |
---|
170 | $replace = " inner join kb3_inv_all ina |
---|
171 | on ( ina.ina_all_id in ( " . substr($this->inv_all_, 0, strlen($this->inv_all_) - 2) . " ) and kll.kll_id = ina.ina_kll_id ) "; |
---|
172 | $asql = str_replace("<ph>", $replace, $this->sql_); |
---|
173 | } |
---|
174 | |
---|
175 | if ($psql) |
---|
176 | $nsql = $psql . " union "; |
---|
177 | if ($csql) |
---|
178 | $nsql .= $csql . " union "; |
---|
179 | if ($asql) |
---|
180 | $nsql .= $asql; |
---|
181 | |
---|
182 | $this->sql_ = $nsql; |
---|
183 | } |
---|
184 | // group by |
---|
185 | if ($this->groupby_) $this->sql_ .= " group by " . implode(",", $this->groupby_); |
---|
186 | // order/limit |
---|
187 | if ($this->ordered_) |
---|
188 | { |
---|
189 | if (!$this->orderby_) $this->sql_ .= " order by kll_timestamp desc"; |
---|
190 | else $this->sql_ .= " order by " . $this->orderby_; |
---|
191 | } |
---|
192 | if ($this->limit_) $this->sql_ .= " limit " . $this->offset_ . ", " . $this->limit_; |
---|
193 | // echo '<p>'.$this->sql_."</p>"; |
---|
194 | $this->qry_->execute($this->sql_); |
---|
195 | } |
---|
196 | } |
---|
197 | |
---|
198 | function getRow() |
---|
199 | { |
---|
200 | $this->execQuery(); |
---|
201 | if ($this->plimit_ && $this->killcounter_ >= $this->plimit_) |
---|
202 | { |
---|
203 | // echo $this->plimit_." ".$this->killcounter_; |
---|
204 | return null; |
---|
205 | } |
---|
206 | |
---|
207 | $skip = $this->poffset_ - $this->killpointer_; |
---|
208 | if ($skip > 0) |
---|
209 | { |
---|
210 | for ($i = 0; $i < $skip; $i++) |
---|
211 | { |
---|
212 | $this->killpointer_++; |
---|
213 | $row = $this->qry_->getRow(); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | $row = $this->qry_->getRow(); |
---|
218 | |
---|
219 | return $row; |
---|
220 | } |
---|
221 | |
---|
222 | function getKill() |
---|
223 | { |
---|
224 | $this->execQuery(); |
---|
225 | if ($this->plimit_ && $this->killcounter_ >= $this->plimit_) |
---|
226 | { |
---|
227 | // echo $this->plimit_." ".$this->killcounter_; |
---|
228 | return null; |
---|
229 | } |
---|
230 | |
---|
231 | $skip = $this->poffset_ - $this->killpointer_; |
---|
232 | if ($skip > 0) |
---|
233 | { |
---|
234 | for ($i = 0; $i < $skip; $i++) |
---|
235 | { |
---|
236 | $this->killpointer_++; |
---|
237 | $row = $this->qry_->getRow(); |
---|
238 | } |
---|
239 | } |
---|
240 | |
---|
241 | $row = $this->qry_->getRow(); |
---|
242 | if ($row) |
---|
243 | { |
---|
244 | $this->killcounter_++; |
---|
245 | if ($row['scl_class'] != 2 && $row['scl_class'] != 3 && $row['scl_class'] != 11) |
---|
246 | $this->realkillcounter_++; |
---|
247 | |
---|
248 | global $config; |
---|
249 | if ($config->getConfig('ship_values')) |
---|
250 | { |
---|
251 | if ($row['shp_value']) |
---|
252 | { |
---|
253 | $row['scl_value'] = $row['shp_value']; |
---|
254 | } |
---|
255 | } |
---|
256 | |
---|
257 | $this->killisk_ += $row['scl_value'] / 1000000; |
---|
258 | $this->killpoints_ += $row['kll_points']; |
---|
259 | |
---|
260 | $kill = new Kill($row['kll_id']); |
---|
261 | $kill->setTimeStamp($row['kll_timestamp']); |
---|
262 | $kill->setSolarSystemName($row['sys_name']); |
---|
263 | $kill->setSolarSystemSecurity($row['sys_sec']); |
---|
264 | $kill->setVictimName($row['plt_name']); |
---|
265 | $kill->setVictimCorpName($row['crp_name']); |
---|
266 | $kill->setVictimAllianceName($row['ali_name']); |
---|
267 | $kill->setVictimShipName($row['shp_name']); |
---|
268 | $kill->setVictimShipExternalID($row['shp_externalid']); |
---|
269 | $kill->setVictimShipClassName($row['scl_class']); |
---|
270 | $kill->setVictimShipValue(round($row['scl_value'] / 1000000, 2)); |
---|
271 | $kill->setFBPilotName($row['fbplt_name']); |
---|
272 | $kill->setFBCorpName($row['fbcrp_name']); |
---|
273 | $kill->setKillPoints($row['kll_points']); |
---|
274 | return $kill; |
---|
275 | } |
---|
276 | else return null; |
---|
277 | } |
---|
278 | |
---|
279 | function getAllKills() |
---|
280 | { |
---|
281 | while ($this->getKill()) |
---|
282 | { |
---|
283 | } |
---|
284 | $this->rewind(); |
---|
285 | } |
---|
286 | |
---|
287 | function addInvolvedPilot($pilot) |
---|
288 | { |
---|
289 | $this->inv_plt_ .= $pilot->getID() . ", "; |
---|
290 | if ($this->inv_crp_ || $this->inv_all_) |
---|
291 | $this->mixedinvolved_ = true; |
---|
292 | } |
---|
293 | |
---|
294 | function addInvolvedCorp($corp) |
---|
295 | { |
---|
296 | $this->inv_crp_ .= $corp->getID() . ", "; |
---|
297 | if ($this->inv_plt_ || $this->inv_all_) |
---|
298 | $this->mixedinvolved_ = true; |
---|
299 | } |
---|
300 | |
---|
301 | function addInvolvedAlliance($alliance) |
---|
302 | { |
---|
303 | $this->inv_all_ .= $alliance->getID() . ", "; |
---|
304 | if ($this->inv_plt_ || $this->inv_crp_) |
---|
305 | $this->mixedinvolved_ = true; |
---|
306 | } |
---|
307 | |
---|
308 | function addVictimPilot($pilot) |
---|
309 | { |
---|
310 | $this->vic_plt_ .= $pilot->getID() . ", "; |
---|
311 | if ($this->vic_crp_ || $this->vic_all_) |
---|
312 | $this->mixedvictims_ = true; |
---|
313 | } |
---|
314 | |
---|
315 | function addVictimCorp($corp) |
---|
316 | { |
---|
317 | $this->vic_crp_ .= $corp->getID() . ", "; |
---|
318 | if ($this->vic_plt_ || $this->vic_all_) |
---|
319 | $this->mixedvictims_ = true; |
---|
320 | } |
---|
321 | |
---|
322 | function addVictimAlliance($alliance) |
---|
323 | { |
---|
324 | $this->vic_all_ .= $alliance->getID() . ", "; |
---|
325 | if ($this->vic_plt_ || $this->vic_crp_) |
---|
326 | $this->mixedvictims_ = true; |
---|
327 | } |
---|
328 | |
---|
329 | function addVictimShipClass($shipclass) |
---|
330 | { |
---|
331 | array_push($this->vic_scl_id_, $shipclass->getID()); |
---|
332 | } |
---|
333 | |
---|
334 | function addVictimShip($ship) |
---|
335 | { |
---|
336 | } |
---|
337 | |
---|
338 | function addItemDestroyed($item) |
---|
339 | { |
---|
340 | } |
---|
341 | |
---|
342 | function addRegion($region) |
---|
343 | { |
---|
344 | array_push($this->regions_, $region->getID()); |
---|
345 | } |
---|
346 | |
---|
347 | function addGroupBy($groupby) |
---|
348 | { |
---|
349 | array_push($this->groupby_, $groupby); |
---|
350 | } |
---|
351 | |
---|
352 | function setPageSplitter($pagesplitter) |
---|
353 | { |
---|
354 | if (isset($_GET['page'])) $page = $_GET['page']; |
---|
355 | else $page = 1; |
---|
356 | $this->plimit_ = $pagesplitter->getSplit(); |
---|
357 | $this->poffset_ = ($page * $this->plimit_) - $this->plimit_; |
---|
358 | // echo $this->offset_; |
---|
359 | // echo $this->limit_; |
---|
360 | } |
---|
361 | |
---|
362 | function setWeek($weekno) |
---|
363 | { |
---|
364 | $this->timeframe_ .= " and date_format( kll.kll_timestamp, \"%u\" ) = "; |
---|
365 | $this->timeframe_ .= $weekno; |
---|
366 | } |
---|
367 | |
---|
368 | function setYear($yearno) |
---|
369 | { |
---|
370 | $this->timeframe_ .= " and date_format( kll.kll_timestamp, \"%Y\" ) = "; |
---|
371 | $this->timeframe_ .= $yearno; |
---|
372 | } |
---|
373 | |
---|
374 | function setStartWeek($weekno) |
---|
375 | { |
---|
376 | $this->timeframe_ .= " and date_format( kll.kll_timestamp, \"%u\" ) >= "; |
---|
377 | $this->timeframe_ .= $weekno; |
---|
378 | } |
---|
379 | |
---|
380 | function setStartDate($timestamp) |
---|
381 | { |
---|
382 | $this->timeframe_ .= " and kll.kll_timestamp >= '" . $timestamp . "'"; |
---|
383 | } |
---|
384 | |
---|
385 | function setEndDate($timestamp) |
---|
386 | { |
---|
387 | $this->timeframe_ .= " and kll.kll_timestamp <= '" . $timestamp . "'"; |
---|
388 | } |
---|
389 | |
---|
390 | function setRelated($killid) |
---|
391 | { |
---|
392 | $this->related_ = $killid; |
---|
393 | } |
---|
394 | |
---|
395 | function setLimit($limit) |
---|
396 | { |
---|
397 | $this->limit_ = $limit; |
---|
398 | } |
---|
399 | |
---|
400 | function setOrderBy($orderby) |
---|
401 | { |
---|
402 | $this->orderby_ = $orderby; |
---|
403 | } |
---|
404 | |
---|
405 | function getCount() |
---|
406 | { |
---|
407 | $this->execQuery(); |
---|
408 | return $this->qry_->recordCount(); |
---|
409 | } |
---|
410 | |
---|
411 | function getRealCount() |
---|
412 | { |
---|
413 | $this->execQuery(); |
---|
414 | return $this->qry_->recordCount(); |
---|
415 | } |
---|
416 | |
---|
417 | function getISK() |
---|
418 | { |
---|
419 | $this->execQuery(); |
---|
420 | return $this->killisk_; |
---|
421 | } |
---|
422 | |
---|
423 | function getPoints() |
---|
424 | { |
---|
425 | return $this->killpoints_; |
---|
426 | } |
---|
427 | |
---|
428 | function rewind() |
---|
429 | { |
---|
430 | $this->qry_->rewind(); |
---|
431 | $this->killcounter_ = 0; |
---|
432 | } |
---|
433 | |
---|
434 | function setPodsNoobShips($flag) |
---|
435 | { |
---|
436 | if (!$flag) |
---|
437 | { |
---|
438 | array_push($this->exclude_scl_, 2); |
---|
439 | array_push($this->exclude_scl_, 3); |
---|
440 | array_push($this->exclude_scl_, 11); |
---|
441 | } |
---|
442 | } |
---|
443 | |
---|
444 | function setOrdered($flag) |
---|
445 | { |
---|
446 | $this->ordered_ = $flag; |
---|
447 | } |
---|
448 | } |
---|
449 | ?> |
---|