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