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 | $this->walked = false; |
---|
25 | $this->apikill_ = false; |
---|
26 | } |
---|
27 | |
---|
28 | function execQuery() |
---|
29 | { |
---|
30 | /* Killlist philosophy |
---|
31 | * For EDK the most common uses of a killlist require date ordering |
---|
32 | * based on kb3_kills. This is then restricted by joins with other |
---|
33 | * tables. MySQL will decide on a query interpretation based on rows |
---|
34 | * returned in each step. For EDK this can be very suboptimal as the |
---|
35 | * most important restriction is by date or number of kills - both |
---|
36 | * based on kb3_kills - which is usually followed by ordering by date. |
---|
37 | * |
---|
38 | * The killlist is constructed so as to give MySQL the least opportunity |
---|
39 | * to carry out the query in a slow manner. kb3_kills is used as the |
---|
40 | * main table. Where possible it is only joined with tables that do not |
---|
41 | * restrict the output. Comment count and involved count are in an outer |
---|
42 | * query to avoid the use of distinct on the whole kb3_kills table and |
---|
43 | * the potential ordering of a query with kb3_inv_detail first. |
---|
44 | * |
---|
45 | */ |
---|
46 | $timeindex='kll_timestamp'; |
---|
47 | if (!$this->qry_->executed_) |
---|
48 | { |
---|
49 | $datefilter=$this->getDateFilter(); |
---|
50 | $this->sql_ = ''; |
---|
51 | if (!count($this->groupby_) && ($this->comments_ || $this->involved_)) |
---|
52 | { |
---|
53 | $this->sql_ .= 'SELECT list.* '; |
---|
54 | if($this->comments_) $this->sql_ .= ', count(distinct com.id) as comments'; |
---|
55 | if($this->involved_) $this->sql_ .= ', max(ind.ind_order) + 1 as inv'; |
---|
56 | $this->sql_ .= ' FROM ('; |
---|
57 | } |
---|
58 | if (!count($this->groupby_)) |
---|
59 | { |
---|
60 | if($this->summary_) |
---|
61 | { |
---|
62 | $this->sql_ .= 'select distinct kll.kll_id, kll.kll_ship_id, |
---|
63 | kll.kll_points, kll.kll_isk_loss, |
---|
64 | shp.shp_class, shp.shp_name, |
---|
65 | shp.shp_externalid, shp.shp_id, |
---|
66 | scl.scl_id, scl.scl_class, scl.scl_value'; |
---|
67 | if(count($this->systems_)) |
---|
68 | $this->sql_ .= ', sys.sys_name, sys.sys_sec'; |
---|
69 | } |
---|
70 | else |
---|
71 | { |
---|
72 | $this->sql_ .= 'select distinct kll.kll_id, kll.kll_timestamp, kll.kll_external_id, |
---|
73 | plt.plt_name, crp.crp_name, crp.crp_id, |
---|
74 | ali.all_name, ali.all_id, |
---|
75 | kll.kll_system_id, kll.kll_ship_id, |
---|
76 | kll.kll_victim_id, plt.plt_externalid, |
---|
77 | kll.kll_crp_id, kll.kll_points, kll.kll_isk_loss, |
---|
78 | shp.shp_class, shp.shp_name, |
---|
79 | shp.shp_externalid, shp.shp_id, |
---|
80 | scl.scl_id, scl.scl_class, scl.scl_value, |
---|
81 | sys.sys_name, sys.sys_sec, |
---|
82 | fbplt.plt_name as fbplt_name, |
---|
83 | fbplt.plt_externalid as fbplt_externalid, |
---|
84 | fbcrp.crp_name as fbcrp_name, |
---|
85 | fbali.all_name as fball_name'; |
---|
86 | } |
---|
87 | } |
---|
88 | |
---|
89 | |
---|
90 | if (count($this->groupby_)) |
---|
91 | { |
---|
92 | $this->sql_ .= "SELECT COUNT(1) as cnt, ".implode(",", $this->groupby_); |
---|
93 | } |
---|
94 | if (config::get('ship_values')) |
---|
95 | { |
---|
96 | $this->sql_ .= ', ksv.shp_value'; |
---|
97 | } |
---|
98 | |
---|
99 | $this->sql_ .= " FROM kb3_kills kll "; |
---|
100 | // MySQL tends to pick an index for this query poorly so specify one. |
---|
101 | //if($this->ordered_ && !$this->orderby_) $this->sql_ .= "use index (".$timeindex.") "; |
---|
102 | |
---|
103 | $this->sql_ .= "INNER JOIN kb3_ships shp |
---|
104 | ON ( shp.shp_id = kll.kll_ship_id ) |
---|
105 | INNER JOIN kb3_ship_classes scl |
---|
106 | ON ( scl.scl_id = shp.shp_class )"; |
---|
107 | if (config::get('ship_values')) |
---|
108 | { |
---|
109 | $this->sql_ .= ' left join kb3_ships_values ksv ON (kll.kll_ship_id = ksv.shp_id) '; |
---|
110 | } |
---|
111 | |
---|
112 | if (!$this->summary_) $this->sql_ .= "INNER JOIN kb3_pilots plt |
---|
113 | ON ( plt.plt_id = kll.kll_victim_id ) |
---|
114 | INNER JOIN kb3_corps crp |
---|
115 | ON ( crp.crp_id = kll.kll_crp_id ) |
---|
116 | INNER JOIN kb3_alliances ali |
---|
117 | ON ( ali.all_id = kll.kll_all_id ) |
---|
118 | INNER JOIN kb3_pilots fbplt |
---|
119 | ON ( fbplt.plt_id = kll.kll_fb_plt_id ) |
---|
120 | INNER JOIN kb3_inv_detail fb |
---|
121 | ON ( fb.ind_kll_id = kll.kll_id AND fb.ind_plt_id = kll.kll_fb_plt_id ) |
---|
122 | INNER JOIN kb3_corps fbcrp |
---|
123 | ON ( fbcrp.crp_id = fb.ind_crp_id ) |
---|
124 | INNER JOIN kb3_alliances fbali |
---|
125 | ON ( fbali.all_id = fb.ind_all_id ) |
---|
126 | "; |
---|
127 | if(!$this->summary_ || count($this->systems_)) |
---|
128 | $this->sql_ .= " INNER JOIN kb3_systems sys |
---|
129 | ON ( sys.sys_id = kll.kll_system_id )"; |
---|
130 | |
---|
131 | // regions |
---|
132 | if (count($this->regions_)) |
---|
133 | { |
---|
134 | $this->sql_ .= " INNER JOIN kb3_constellations con |
---|
135 | ON ( con.con_id = sys.sys_con_id and |
---|
136 | con.con_reg_id in ( ".implode($this->regions_, ",")." ) )"; |
---|
137 | } |
---|
138 | |
---|
139 | if( $datefilter == "" && ( $this->inv_plt_ || $this->inv_crp_ || $this->inv_all_)) |
---|
140 | { |
---|
141 | $this->sql_ .= " INNER JOIN kb3_inv_detail ind ON (kll.kll_id = ind.ind_kll_id AND ("; |
---|
142 | $invop = ""; |
---|
143 | if($this->inv_plt_ ) |
---|
144 | { |
---|
145 | $this->sql_ .= " ind.ind_plt_id IN (". |
---|
146 | implode(',', $this->inv_plt_)." ) "; |
---|
147 | $invop = "OR"; |
---|
148 | } |
---|
149 | if($this->inv_crp_ ) |
---|
150 | { |
---|
151 | $this->sql_ .= $invop." ind.ind_crp_id IN (". |
---|
152 | implode(',', $this->inv_crp_)." ) "; |
---|
153 | } |
---|
154 | if($this->inv_all_ ) |
---|
155 | { |
---|
156 | $this->sql_ .= $invop." ind.ind_all_id IN (". |
---|
157 | implode(',', $this->inv_all_)." ) "; |
---|
158 | } |
---|
159 | $this->sql_ .= ") ) "; |
---|
160 | /* Faster on <50k mails, much slower on >500k |
---|
161 | $this->sql_ .= " INNER JOIN "; |
---|
162 | if($this->inv_plt_ && !($this->inv_crp_ || $this->inv_all_)) |
---|
163 | { |
---|
164 | $this->sql_ .= " kb3_inv_detail ind ". |
---|
165 | "ON (kll.kll_id = ind.ind_kll_id AND ind.ind_plt_id IN (". |
---|
166 | implode(',', $this->inv_plt_)." ) ) "; |
---|
167 | } |
---|
168 | else |
---|
169 | { |
---|
170 | $unionop = " ( "; |
---|
171 | if($this->inv_plt_) |
---|
172 | { |
---|
173 | $indsqlp .= $unionop." SELECT DISTINCT ind_kll_id ". |
---|
174 | "FROM kb3_inv_detail ". |
---|
175 | "WHERE ind_plt_id IN (".implode(',', $this->inv_plt_)." ) "; |
---|
176 | $unionop = " UNION "; |
---|
177 | } |
---|
178 | if($this->inv_crp_) |
---|
179 | { |
---|
180 | $this->sql_ .= $unionop." SELECT DISTINCT ind_kll_id ". |
---|
181 | "FROM kb3_inv_detail WHERE ind_crp_id IN (". |
---|
182 | implode(',', $this->inv_crp_)." ) "; |
---|
183 | $unionop = " UNION "; |
---|
184 | } |
---|
185 | if($this->inv_all_) $this->sql_ .= $unionop." SELECT DISTINCT ind_kll_id FROM kb3_inv_detail WHERE ind_all_id IN (". |
---|
186 | implode(',', $this->inv_all_).") "; |
---|
187 | $this->sql_ .= ") ind ON (kll.kll_id = ind.ind_kll_id) "; |
---|
188 | } |
---|
189 | */ |
---|
190 | } |
---|
191 | // The first argument after WHERE affects sql optimisation so check |
---|
192 | // each possible argument to see whether it should use AND or WHERE |
---|
193 | // rather than start with WHERE 1 |
---|
194 | $sqlwhereop = ' WHERE '; |
---|
195 | // Date filter |
---|
196 | if($datefilter != "") |
---|
197 | { |
---|
198 | $this->sql_ .= $sqlwhereop.$datefilter; |
---|
199 | $sqlwhereop = ' AND '; |
---|
200 | } |
---|
201 | |
---|
202 | if($this->apikill_) |
---|
203 | { |
---|
204 | $this->sql_ .= $sqlwhereop." kll.kll_external_id IS NOT NULL "; |
---|
205 | $sqlwhereop = ' AND '; |
---|
206 | } |
---|
207 | |
---|
208 | // System filter |
---|
209 | if (count($this->systems_)) |
---|
210 | { |
---|
211 | $this->sql_ .= $sqlwhereop." kll.kll_system_id in ( ".implode($this->systems_, ",").")"; |
---|
212 | $sqlwhereop = ' AND '; |
---|
213 | } |
---|
214 | // victim filter |
---|
215 | if($this->vic_plt_ || $this->vic_crp_ || $this->vic_all_) |
---|
216 | { |
---|
217 | $this->sql_ .= $sqlwhereop." ( "; |
---|
218 | $sqlwhereop = ""; |
---|
219 | |
---|
220 | if ($this->vic_plt_) |
---|
221 | {$this->sql_ .= " ".$sqlwhereop." kll.kll_victim_id in ( ".implode(',', $this->vic_plt_)." )"; $sqlwhereop = " OR ";} |
---|
222 | if ($this->vic_crp_) |
---|
223 | {$this->sql_ .= " ".$sqlwhereop." kll.kll_crp_id in ( ".implode(',', $this->vic_crp_)." )"; $sqlwhereop = " OR ";} |
---|
224 | if ($this->vic_all_) |
---|
225 | {$this->sql_ .= " ".$sqlwhereop." kll.kll_all_id in ( ".implode(',', $this->vic_all_)." )"; $sqlwhereop = " OR ";} |
---|
226 | |
---|
227 | $sqlwhereop = ' AND '; |
---|
228 | $this->sql_ .= " ) "; |
---|
229 | } |
---|
230 | |
---|
231 | // related kills |
---|
232 | if ($this->related_) |
---|
233 | { |
---|
234 | $rqry = new DBQuery(); |
---|
235 | $rsql = "select kll_timestamp, kll_system_id from kb3_kills where kll_id = ".$this->related_; |
---|
236 | |
---|
237 | $rqry->execute($rsql); |
---|
238 | $rrow = $rqry->getRow(); |
---|
239 | |
---|
240 | $this->sql_ .= $sqlwhereop."kll.kll_timestamp <= |
---|
241 | ".(date('Y-m-d H:i:s',strtotime($rrow['kll_timestamp']) + 60 * 60)). |
---|
242 | " and kll.kll_timestamp >= |
---|
243 | ".(date('Y-m-d H:i:s',strtotime($rrow['kll_timestamp']) - 60 * 60)). |
---|
244 | " and kll.kll_system_id = ".$rrow['kll_system_id']; |
---|
245 | $sqlwhereop = " AND "; |
---|
246 | } |
---|
247 | // Get all kills after given kill id (used for feed syndication) |
---|
248 | if ($this->minkllid_) |
---|
249 | { |
---|
250 | $this->sql_ .= $sqlwhereop.'kll.kll_id >= '.$this->minkllid_.' '; |
---|
251 | $sqlwhereop = ' AND '; |
---|
252 | } |
---|
253 | |
---|
254 | // Get all kills before given kill id (used for feed syndication) |
---|
255 | if ($this->maxkllid_) |
---|
256 | { |
---|
257 | $this->sql_ .= $sqlwhereop.'kll.kll_id <= '.$this->maxkllid_.' '; |
---|
258 | $sqlwhereop = ' AND '; |
---|
259 | } |
---|
260 | |
---|
261 | // excluded ship filter |
---|
262 | if (count($this->exclude_scl_)) |
---|
263 | { |
---|
264 | $this->sql_ .= $sqlwhereop." shp.shp_class not in ( ".implode(",", $this->exclude_scl_)." )"; |
---|
265 | $sqlwhereop = ' AND '; |
---|
266 | } |
---|
267 | // included ship filter |
---|
268 | if (count($this->vic_scl_id_)) |
---|
269 | { |
---|
270 | $this->sql_ .= $sqlwhereop." shp.shp_class in ( ".implode(",", $this->vic_scl_id_)." ) "; |
---|
271 | $sqlwhereop = ' AND '; |
---|
272 | } |
---|
273 | // involved filter |
---|
274 | // involved parties who aren't also the victim |
---|
275 | // Only use a join if no other limits are used. |
---|
276 | if($this->inv_plt_ || $this->inv_crp_ || $this->inv_all_) |
---|
277 | { |
---|
278 | if($this->inv_all_ && $this->inv_crp_) |
---|
279 | { |
---|
280 | $this->sql_ .= $sqlwhereop." ( "; |
---|
281 | $sqlwhereop = ''; |
---|
282 | } |
---|
283 | // No need to check the involved pilot since they can't shoot themself and get a killmail. |
---|
284 | if ($this->inv_all_) |
---|
285 | { |
---|
286 | $this->sql_ .= $sqlwhereop." kll.kll_all_id NOT IN ( ".implode(',', $this->inv_all_)." )"; |
---|
287 | $sqlwhereop = ' AND '; |
---|
288 | } |
---|
289 | if ($this->inv_crp_) |
---|
290 | { |
---|
291 | $this->sql_ .= $sqlwhereop." kll.kll_crp_id NOT IN ( ".implode(',', $this->inv_crp_)." )"; |
---|
292 | $sqlwhereop = ' AND '; |
---|
293 | } |
---|
294 | if($this->inv_all_ && $this->inv_crp_) $this->sql_ .= ") "; |
---|
295 | if( $datefilter != "") |
---|
296 | { |
---|
297 | $this->sql_ .= $sqlwhereop." EXISTS (SELECT 1 FROM kb3_inv_detail exind ". |
---|
298 | "WHERE kll.kll_id = exind.ind_kll_id AND ("; |
---|
299 | $sqlwhereop = ""; |
---|
300 | if ($this->inv_all_) |
---|
301 | {$this->sql_ .= $sqlwhereop." exind.ind_all_id in ( ".implode(',', $this->inv_all_)." ) ";$sqlwhereop = " OR ";} |
---|
302 | if ($this->inv_crp_) |
---|
303 | {$this->sql_ .= $sqlwhereop." exind.ind_crp_id in ( ".implode(',', $this->inv_crp_)." ) ";$sqlwhereop = " OR ";} |
---|
304 | if ($this->inv_plt_) |
---|
305 | $this->sql_ .= $sqlwhereop." exind.ind_plt_id in ( ".implode(',', $this->inv_plt_)." ) "; |
---|
306 | $this->sql_ .= " ) ) "; |
---|
307 | $sqlwhereop = " AND "; |
---|
308 | } |
---|
309 | } |
---|
310 | // This may scan the entire table if LIMIT or a date filter are not used. |
---|
311 | // Some queries combining groups will be slow on mysql versions < 5 without index merge. |
---|
312 | if($this->comb_plt_ || $this->comb_crp_ || $this->comb_all_) |
---|
313 | { |
---|
314 | $this->sql_ .= $sqlwhereop." ( "; |
---|
315 | $sqlwhereop = " OR "; |
---|
316 | $sqlexistop = "EXISTS ( SELECT 1 FROM kb3_inv_detail cind WHERE kll.kll_id = cind.ind_kll_id AND ("; |
---|
317 | if($this->comb_plt_) |
---|
318 | { |
---|
319 | $this->sql_ .= $sqlexistop." cind.ind_plt_id in ( ".implode(',', $this->comb_plt_)." )"; |
---|
320 | $sqlexistop = " OR "; |
---|
321 | } |
---|
322 | if($this->comb_crp_) |
---|
323 | { |
---|
324 | $this->sql_ .= $sqlexistop." cind.ind_crp_id in ( ".implode(',', $this->comb_crp_)." )"; |
---|
325 | $sqlexistop = " OR "; |
---|
326 | } |
---|
327 | if($this->comb_all_) |
---|
328 | { |
---|
329 | $this->sql_ .= $sqlexistop." cind.ind_all_id in ( ".implode(',', $this->comb_all_)." )"; |
---|
330 | } |
---|
331 | $this->sql_ .= " ) )"; |
---|
332 | if($this->comb_plt_) |
---|
333 | { |
---|
334 | $this->sql_ .= $sqlwhereop."kll.kll_victim_id in ( ".implode(',', $this->comb_plt_)." ) "; |
---|
335 | $sqlwhereop = " OR "; |
---|
336 | } |
---|
337 | if($this->comb_crp_) |
---|
338 | { |
---|
339 | $this->sql_ .= $sqlwhereop."kll.kll_crp_id in ( ".implode(',', $this->comb_crp_)." ) "; |
---|
340 | $sqlwhereop = " OR "; |
---|
341 | } |
---|
342 | if($this->comb_all_) |
---|
343 | { |
---|
344 | $this->sql_ .= $sqlwhereop."kll.kll_all_id in ( ".implode(',', $this->comb_all_)." ) "; |
---|
345 | } |
---|
346 | $this->sql_ .= " )"; |
---|
347 | $sqlwhereop = " AND "; |
---|
348 | } |
---|
349 | |
---|
350 | // GROUP BY |
---|
351 | if ($this->groupby_) $this->sql_ .= " GROUP BY ".implode(",", $this->groupby_); |
---|
352 | // order/limit |
---|
353 | if ($this->ordered_) |
---|
354 | { |
---|
355 | if (!$this->orderby_) $this->sql_ .= " order by kll_timestamp desc"; |
---|
356 | else $this->sql_ .= " order by ".$this->orderby_; |
---|
357 | } |
---|
358 | if ($this->limit_) $this->sql_ .= " limit ".$this->limit_." OFFSET ".$this->offset_; |
---|
359 | // Enclose query in another to fetch comments and involved parties |
---|
360 | if(!count($this->groupby_) && ($this->comments_ || $this->involved_)) |
---|
361 | { |
---|
362 | $this->sql_ .= ") list"; |
---|
363 | if($this->involved_) $this->sql_ .= ' join kb3_inv_detail ind ON (ind.ind_kll_id = list.kll_id)'; |
---|
364 | if($this->comments_) $this->sql_ .= ' left join kb3_comments com ON (list.kll_id = com.kll_id)'; |
---|
365 | $this->sql_ .= " group by list.kll_id"; |
---|
366 | // Outer query also needs to be ordered, if there's an order |
---|
367 | if ($this->ordered_) |
---|
368 | { |
---|
369 | if (!$this->orderby_) $this->sql_ .= " order by kll_timestamp desc"; |
---|
370 | else $this->sql_ .= " order by ".$this->orderby_; |
---|
371 | } |
---|
372 | } |
---|
373 | $this->sql_ .= " -- kill list"; |
---|
374 | $this->qry_->execute($this->sql_); |
---|
375 | } |
---|
376 | } |
---|
377 | |
---|
378 | function getRow() |
---|
379 | { |
---|
380 | $this->execQuery(); |
---|
381 | if ($this->plimit_ && $this->killcounter_ >= $this->plimit_) |
---|
382 | { |
---|
383 | // echo $this->plimit_." ".$this->killcounter_; |
---|
384 | return null; |
---|
385 | } |
---|
386 | |
---|
387 | $skip = $this->poffset_ - $this->killpointer_; |
---|
388 | if ($skip > 0) |
---|
389 | { |
---|
390 | for ($i = 0; $i < $skip; $i++) |
---|
391 | { |
---|
392 | $this->killpointer_++; |
---|
393 | $row = $this->qry_->getRow(); |
---|
394 | } |
---|
395 | } |
---|
396 | |
---|
397 | $row = $this->qry_->getRow(); |
---|
398 | |
---|
399 | return $row; |
---|
400 | } |
---|
401 | |
---|
402 | function getKill() |
---|
403 | { |
---|
404 | $this->execQuery(); |
---|
405 | if ($this->plimit_ && $this->killcounter_ >= $this->plimit_) |
---|
406 | { |
---|
407 | // echo $this->plimit_." ".$this->killcounter_; |
---|
408 | return null; |
---|
409 | } |
---|
410 | |
---|
411 | $skip = $this->poffset_ - $this->killpointer_; |
---|
412 | if ($skip > 0) |
---|
413 | { |
---|
414 | for ($i = 0; $i < $skip; $i++) |
---|
415 | { |
---|
416 | $this->killpointer_++; |
---|
417 | $row = $this->qry_->getRow(); |
---|
418 | } |
---|
419 | } |
---|
420 | |
---|
421 | $row = $this->qry_->getRow(); |
---|
422 | if ($row) |
---|
423 | { |
---|
424 | $this->killcounter_++; |
---|
425 | if ($row['scl_class'] != 2 && $row['scl_class'] != 3 && $row['scl_class'] != 11) |
---|
426 | $this->realkillcounter_++; |
---|
427 | |
---|
428 | if (config::get('ship_values')) |
---|
429 | { |
---|
430 | if ($row['shp_value']) |
---|
431 | { |
---|
432 | $row['scl_value'] = $row['shp_value']; |
---|
433 | } |
---|
434 | } |
---|
435 | |
---|
436 | if ($this->walked == false) |
---|
437 | { |
---|
438 | $this->killisk_ += $row['kll_isk_loss']; |
---|
439 | $this->killpoints_ += $row['kll_points']; |
---|
440 | } |
---|
441 | |
---|
442 | $kill = new Kill($row['kll_id']); |
---|
443 | $kill->setTimeStamp($row['kll_timestamp']); |
---|
444 | $kill->setSolarSystemName($row['sys_name']); |
---|
445 | $kill->setSolarSystemSecurity($row['sys_sec']); |
---|
446 | $kill->setVictimName($row['plt_name']); |
---|
447 | $kill->setVictimCorpName($row['crp_name']); |
---|
448 | $kill->setVictimCorpID($row['crp_id']); |
---|
449 | $kill->setVictimAllianceName($row['all_name']); |
---|
450 | $kill->setVictimAllianceID($row['all_id']); |
---|
451 | $kill->setVictimShipName($row['shp_name']); |
---|
452 | $kill->setVictimShipExternalID($row['shp_externalid']); |
---|
453 | $kill->setVictimShipClassName($row['scl_class']); |
---|
454 | $kill->setVictimShipValue($row['scl_value']); |
---|
455 | $kill->setVictimID($row['kll_victim_id']); |
---|
456 | $kill->setFBPilotName($row['fbplt_name']); |
---|
457 | $kill->setFBCorpName($row['fbcrp_name']); |
---|
458 | $kill->setFBAllianceName($row['fbcrp_name']); |
---|
459 | $kill->setKillPoints($row['kll_points']); |
---|
460 | $kill->setExternalID($row['kll_external_id']); |
---|
461 | $kill->setISKLoss($row['kll_isk_loss']); |
---|
462 | $kill->plt_ext_ = $row['plt_externalid']; |
---|
463 | $kill->fbplt_ext_ = $row['fbplt_externalid']; |
---|
464 | $kill->_sclid = $row['scl_id']; |
---|
465 | $kill->_shpid = $row['shp_id']; |
---|
466 | //Set the involved party count if it is known |
---|
467 | if($this->involved_) $kill->setInvolvedPartyCount($row['inv']); |
---|
468 | //Set the comment count if it is known |
---|
469 | if($this->comments_) $kill->setCommentCount($row['comments']); |
---|
470 | if ($this->_tag) |
---|
471 | { |
---|
472 | $kill->_tag = $this->_tag; |
---|
473 | } |
---|
474 | if (config::get('kill_classified')) |
---|
475 | { |
---|
476 | if ($kill->isClassified()) |
---|
477 | { |
---|
478 | $kill->setSolarSystemName('Classified'); |
---|
479 | $kill->setSolarSystemSecurity('0.0'); |
---|
480 | } |
---|
481 | } |
---|
482 | |
---|
483 | return $kill; |
---|
484 | } |
---|
485 | else |
---|
486 | { |
---|
487 | $this->walked = true; |
---|
488 | return null; |
---|
489 | } |
---|
490 | } |
---|
491 | |
---|
492 | function getAllKills() |
---|
493 | { |
---|
494 | while ($this->getKill()) |
---|
495 | { |
---|
496 | } |
---|
497 | $this->rewind(); |
---|
498 | } |
---|
499 | |
---|
500 | function addInvolvedPilot($pilot) |
---|
501 | { |
---|
502 | if(is_numeric($pilot)) $this->inv_plt_[] = $pilot; |
---|
503 | else $this->inv_plt_[] = $pilot->getID(); |
---|
504 | } |
---|
505 | |
---|
506 | function addInvolvedCorp($corp) |
---|
507 | { |
---|
508 | if(is_numeric($corp)) $this->inv_crp_[] = $corp; |
---|
509 | else $this->inv_crp_[] = $corp->getID(); |
---|
510 | } |
---|
511 | |
---|
512 | function addInvolvedAlliance($alliance) |
---|
513 | { |
---|
514 | if(is_numeric($alliance)) $this->inv_all_[] = $alliance; |
---|
515 | else $this->inv_all_[] = $alliance->getID(); |
---|
516 | } |
---|
517 | |
---|
518 | function addVictimPilot($pilot) |
---|
519 | { |
---|
520 | if(is_numeric($pilot)) $this->vic_plt_[] = $pilot; |
---|
521 | else $this->vic_plt_[] = $pilot->getID(); |
---|
522 | } |
---|
523 | |
---|
524 | function addVictimCorp($corp) |
---|
525 | { |
---|
526 | if(is_numeric($corp)) $this->vic_crp_[] = $corp; |
---|
527 | else $this->vic_crp_[] = $corp->getID(); |
---|
528 | } |
---|
529 | |
---|
530 | function addVictimAlliance($alliance) |
---|
531 | { |
---|
532 | if(is_numeric($alliance)) $this->vic_all_[] = $alliance; |
---|
533 | else $this->vic_all_[] = $alliance->getID(); |
---|
534 | } |
---|
535 | |
---|
536 | function addCombinedPilot($pilot) |
---|
537 | { |
---|
538 | if(is_numeric($pilot)) $this->comb_plt_[] = $pilot; |
---|
539 | else $this->comb_plt_[] = $pilot->getID(); |
---|
540 | } |
---|
541 | |
---|
542 | function addCombinedCorp($corp) |
---|
543 | { |
---|
544 | if(is_numeric($corp)) $this->comb_crp_[] = $corp; |
---|
545 | else $this->comb_crp_[] = $corp->getID(); |
---|
546 | } |
---|
547 | |
---|
548 | function addCombinedAlliance($alliance) |
---|
549 | { |
---|
550 | if(is_numeric($alliance)) $this->comb_all_[] = $alliance; |
---|
551 | else $this->comb_all_[] = $alliance->getID(); |
---|
552 | } |
---|
553 | |
---|
554 | function addVictimShipClass($shipclass) |
---|
555 | { |
---|
556 | if(is_numeric($shipclass)) $this->vic_scl_id_[] = $shipclass; |
---|
557 | else $this->vic_scl_id_[] = $shipclass->getID(); |
---|
558 | } |
---|
559 | |
---|
560 | function addVictimShip($ship) |
---|
561 | { |
---|
562 | } |
---|
563 | |
---|
564 | function addItemDestroyed($item) |
---|
565 | { |
---|
566 | } |
---|
567 | |
---|
568 | function addRegion($region) |
---|
569 | { |
---|
570 | if(is_numeric($region)) $this->regions_[] = $region; |
---|
571 | else $this->regions_[] = $region->getID(); |
---|
572 | } |
---|
573 | |
---|
574 | function addSystem($system) |
---|
575 | { |
---|
576 | if(is_numeric($system)) $this->systems_[] = $system; |
---|
577 | else $this->systems_[] = $system->getID(); |
---|
578 | } |
---|
579 | |
---|
580 | function addGroupBy($groupby) |
---|
581 | { |
---|
582 | array_push($this->groupby_, $groupby); |
---|
583 | } |
---|
584 | |
---|
585 | function setPageSplitter($pagesplitter) |
---|
586 | { |
---|
587 | if (isset($_GET['page'])) $page = $_GET['page']; |
---|
588 | else $page = 1; |
---|
589 | $this->plimit_ = $pagesplitter->getSplit(); |
---|
590 | $this->poffset_ = ($page * $this->plimit_) - $this->plimit_; |
---|
591 | } |
---|
592 | |
---|
593 | //! Filter results by week. Requires the year to also be set. |
---|
594 | function setWeek($weekno) |
---|
595 | { |
---|
596 | $weekno=intval($weekno); |
---|
597 | if($weekno <1) $this->weekno_ = 1; |
---|
598 | if($weekno >53) $this->weekno_ = 53; |
---|
599 | else $this->weekno_ = $weekno; |
---|
600 | } |
---|
601 | |
---|
602 | //! Filter results by year. |
---|
603 | function setYear($yearno) |
---|
604 | { |
---|
605 | // 1970-2038 is the allowable range for the timestamp code used |
---|
606 | // Needs to be revisited in the next 30 years |
---|
607 | $yearno = intval($yearno); |
---|
608 | if($yearno < 1970) $this->yearno_ = 1970; |
---|
609 | if($yearno > 2038) $this->yearno_ = 2038; |
---|
610 | else $this->yearno_ = $yearno; |
---|
611 | } |
---|
612 | |
---|
613 | //! Filter results by starting week. Requires the year to also be set. |
---|
614 | function setStartWeek($weekno) |
---|
615 | { |
---|
616 | $weekno=intval($weekno); |
---|
617 | if($weekno <1) $this->startweekno_ = 1; |
---|
618 | if($weekno >53) $this->startweekno_ = 53; |
---|
619 | else $this->startweekno_ = $weekno; |
---|
620 | } |
---|
621 | |
---|
622 | //! Filter results by starting date/time. |
---|
623 | function setStartDate($timestamp) |
---|
624 | { |
---|
625 | // Check timestamp is valid before adding |
---|
626 | if(strtotime($timestamp)) $this->startDate_ = $timestamp; |
---|
627 | } |
---|
628 | |
---|
629 | //! Filter results by ending date/time. |
---|
630 | function setEndDate($timestamp) |
---|
631 | { |
---|
632 | // Check timestamp is valid before adding |
---|
633 | if(strtotime($timestamp)) $this->endDate_ = $timestamp; |
---|
634 | } |
---|
635 | |
---|
636 | //! Convert given date ranges to SQL date range. |
---|
637 | |
---|
638 | //! \return string containing SQL date filter. |
---|
639 | function getDateFilter() |
---|
640 | { |
---|
641 | $qstartdate = makeStartDate($this->weekno_, $this->yearno_, $this->monthno_, $this->startweekno_, $this->startDate_); |
---|
642 | $qenddate = makeEndDate($this->weekno_, $this->yearno_, $this->monthno_, $this->endDate_); |
---|
643 | if($qstartdate) $sql .= " kll.kll_timestamp >= '".gmdate('Y-m-d H:i',$qstartdate)."' "; |
---|
644 | if($qstartdate && $qenddate) $sql .= " AND "; |
---|
645 | if($qenddate) $sql .= " kll.kll_timestamp <= '".gmdate('Y-m-d H:i',$qenddate)."' "; |
---|
646 | return $sql; |
---|
647 | } |
---|
648 | |
---|
649 | function setRelated($killid) |
---|
650 | { |
---|
651 | $this->related_ = $killid; |
---|
652 | } |
---|
653 | |
---|
654 | function setLimit($limit) |
---|
655 | { |
---|
656 | $this->limit_ = $limit; |
---|
657 | } |
---|
658 | //! Only return kills with an external id set. |
---|
659 | function setAPIKill($hasid = true) |
---|
660 | { |
---|
661 | $this->apikill_ = $hasid; |
---|
662 | } |
---|
663 | |
---|
664 | function setOrderBy($orderby) |
---|
665 | { |
---|
666 | $this->orderby_ = $orderby; |
---|
667 | } |
---|
668 | |
---|
669 | function setMinKllID($id) |
---|
670 | { |
---|
671 | $this->minkllid_ = $id; |
---|
672 | } |
---|
673 | |
---|
674 | function setMaxKllID($id) |
---|
675 | { |
---|
676 | $this->maxkllid_ = $id; |
---|
677 | } |
---|
678 | |
---|
679 | function setSummary($summary = false) |
---|
680 | { |
---|
681 | $this->summary_ = $summary; |
---|
682 | } |
---|
683 | |
---|
684 | function getCount() |
---|
685 | { |
---|
686 | $this->execQuery(); |
---|
687 | return $this->qry_->recordCount(); |
---|
688 | } |
---|
689 | |
---|
690 | function getRealCount() |
---|
691 | { |
---|
692 | $this->execQuery(); |
---|
693 | return $this->qry_->recordCount(); |
---|
694 | } |
---|
695 | |
---|
696 | function getISK() |
---|
697 | { |
---|
698 | $this->execQuery(); |
---|
699 | return $this->killisk_; |
---|
700 | } |
---|
701 | |
---|
702 | function getPoints() |
---|
703 | { |
---|
704 | return $this->killpoints_; |
---|
705 | } |
---|
706 | |
---|
707 | function rewind() |
---|
708 | { |
---|
709 | $this->qry_->rewind(); |
---|
710 | $this->killcounter_ = 0; |
---|
711 | } |
---|
712 | |
---|
713 | function setPodsNoobShips($flag) |
---|
714 | { |
---|
715 | if (!$flag) |
---|
716 | { |
---|
717 | array_push($this->exclude_scl_, 2); |
---|
718 | array_push($this->exclude_scl_, 3); |
---|
719 | array_push($this->exclude_scl_, 11); |
---|
720 | } |
---|
721 | } |
---|
722 | |
---|
723 | function setOrdered($flag) |
---|
724 | { |
---|
725 | $this->ordered_ = $flag; |
---|
726 | } |
---|
727 | |
---|
728 | function tag($string) |
---|
729 | { |
---|
730 | if ($string == '') |
---|
731 | { |
---|
732 | $this->_tag = null; |
---|
733 | } |
---|
734 | else |
---|
735 | { |
---|
736 | $this->_tag = $string; |
---|
737 | } |
---|
738 | } |
---|
739 | |
---|
740 | // Add a comment count to the killlist SQL |
---|
741 | function setCountComments($comments = true) |
---|
742 | { |
---|
743 | $this->comments_ = $comments; |
---|
744 | } |
---|
745 | |
---|
746 | // Add an involved party count to the killlist SQL |
---|
747 | function setCountInvolved($setinv = true) |
---|
748 | { |
---|
749 | $this->involved_ = $setinv; |
---|
750 | } |
---|
751 | } |
---|
752 | |
---|
753 | class CombinedKillList extends KillList |
---|
754 | { |
---|
755 | function CombinedKillList() |
---|
756 | { |
---|
757 | // please only load killlists here |
---|
758 | $this->lists = func_get_args(); |
---|
759 | if (!is_array($this->lists)) |
---|
760 | { |
---|
761 | trigger_error('No killlists given to CombinedKillList', E_USER_ERROR); |
---|
762 | } |
---|
763 | $this->kills = false; |
---|
764 | } |
---|
765 | |
---|
766 | function buildKillArray() |
---|
767 | { |
---|
768 | $this->kills = array(); |
---|
769 | foreach ($this->lists as $killlist) |
---|
770 | { |
---|
771 | // reset the list |
---|
772 | $killlist->rewind(); |
---|
773 | |
---|
774 | // load all kills and store them in an array |
---|
775 | while ($kill = $killlist->getKill()) |
---|
776 | { |
---|
777 | // take sure that if there are multiple kills all are stored |
---|
778 | if (isset($this->kills[$kill->timestamp_])) |
---|
779 | { |
---|
780 | $this->kills[$kill->timestamp_.rand()] = $kill; |
---|
781 | } |
---|
782 | else |
---|
783 | { |
---|
784 | $this->kills[$kill->timestamp_] = $kill; |
---|
785 | } |
---|
786 | } |
---|
787 | } |
---|
788 | |
---|
789 | // sort the kills by time |
---|
790 | krsort($this->kills); |
---|
791 | } |
---|
792 | |
---|
793 | function getKill() |
---|
794 | { |
---|
795 | // on the first request we load up our kills |
---|
796 | if ($this->kills === false) |
---|
797 | { |
---|
798 | $this->buildKillArray(); |
---|
799 | if (is_numeric($this->poffset_) && is_numeric($this->plimit_)) |
---|
800 | $this->kills = array_slice($this->kills, $this->poffset_, $this->plimit_); |
---|
801 | } |
---|
802 | |
---|
803 | // once all kills are out this will return null so we're fine |
---|
804 | return array_shift($this->kills); |
---|
805 | } |
---|
806 | |
---|
807 | function rewind() |
---|
808 | { |
---|
809 | // intentionally left empty to overload the standard handle |
---|
810 | } |
---|
811 | |
---|
812 | function getCount() |
---|
813 | { |
---|
814 | $count = 0; |
---|
815 | foreach ($this->lists as $killlist) |
---|
816 | { |
---|
817 | $count += $killlist->getCount(); |
---|
818 | } |
---|
819 | return $count; |
---|
820 | } |
---|
821 | |
---|
822 | function getRealCount() |
---|
823 | { |
---|
824 | $count = 0; |
---|
825 | foreach ($this->lists as $killlist) |
---|
826 | { |
---|
827 | $count += $killlist->getRealCount(); |
---|
828 | } |
---|
829 | return $count; |
---|
830 | } |
---|
831 | |
---|
832 | function getISK() |
---|
833 | { |
---|
834 | $sum = 0; |
---|
835 | foreach ($this->lists as $killlist) |
---|
836 | { |
---|
837 | $sum += $killlist->getISK(); |
---|
838 | } |
---|
839 | return $sum; |
---|
840 | } |
---|
841 | |
---|
842 | function getPoints() |
---|
843 | { |
---|
844 | $sum = 0; |
---|
845 | foreach ($this->lists as $killlist) |
---|
846 | { |
---|
847 | $sum += $killlist->getPoints(); |
---|
848 | } |
---|
849 | return $sum; |
---|
850 | } |
---|
851 | |
---|
852 | } |
---|
853 | ?> |
---|