1 | <?php |
---|
2 | require_once('common/includes/class.kill.php'); |
---|
3 | require_once('common/includes/class.ship.php'); |
---|
4 | |
---|
5 | class allianceSummary |
---|
6 | { |
---|
7 | function allianceSummary($all_id) |
---|
8 | { |
---|
9 | $this->all_id_ = intval($all_id); |
---|
10 | $this->executed_ = false; |
---|
11 | } |
---|
12 | //! Get the complete summary for this alliance. |
---|
13 | |
---|
14 | //! \return an array of ship id by kill/loss count/isk. |
---|
15 | function getSummary() |
---|
16 | { |
---|
17 | if(!$this->executed_) $this->execute(); |
---|
18 | return $this->summary; |
---|
19 | } |
---|
20 | //! Return total ISK killed. |
---|
21 | function getTotalKillISK() |
---|
22 | { |
---|
23 | if(!$this->executed_) $this->execute(); |
---|
24 | foreach($this->summary as $value) |
---|
25 | $totalisk .= $value['killisk']; |
---|
26 | return $totalisk; |
---|
27 | } |
---|
28 | //! Return total ISK lost. |
---|
29 | function getTotalLossISK() |
---|
30 | { |
---|
31 | if(!$this->executed_) $this->execute(); |
---|
32 | foreach($this->summary as $value) |
---|
33 | $totalisk .= $value['lossisk']; |
---|
34 | return $totalisk; |
---|
35 | } |
---|
36 | //! Return the number of kills for the given ship class. |
---|
37 | function getKillCount($shp_class) |
---|
38 | { |
---|
39 | if(!$this->executed_) $this->execute(); |
---|
40 | return intval($this->summary[$ship_class]['killcount']); |
---|
41 | } |
---|
42 | //! Return the ISK value of kills for the given ship class. |
---|
43 | function getKillISK($shp_class) |
---|
44 | { |
---|
45 | if(!$this->executed_) $this->execute(); |
---|
46 | return intval($this->summary[$ship_class]['killisk']); |
---|
47 | } |
---|
48 | //! Return the number of losses for the given ship class. |
---|
49 | function getLossCount($shp_class) |
---|
50 | { |
---|
51 | if(!$this->executed_) $this->execute(); |
---|
52 | return intval($this->summary[$ship_class]['losscount']); |
---|
53 | } |
---|
54 | //! Return the ISK value of losses for the given ship class. |
---|
55 | function getLossISK($shp_class) |
---|
56 | { |
---|
57 | if(!$this->executed_) $this->execute(); |
---|
58 | return intval($this->summary[$ship_class]['lossisk']); |
---|
59 | } |
---|
60 | //! Fetch the summary information. |
---|
61 | function execute() |
---|
62 | { |
---|
63 | if($this->executed_) return; |
---|
64 | if(!$this->all_id_) |
---|
65 | { |
---|
66 | $this->executed_ = true; |
---|
67 | return false; |
---|
68 | } |
---|
69 | |
---|
70 | $qry = new DBQuery(); |
---|
71 | $qry->execute("SELECT 1 FROM kb3_sum_alliance WHERE asm_all_id = ".$this->all_id_); |
---|
72 | if(!$qry->recordCount()) |
---|
73 | $this->buildSummary($this->all_id_); |
---|
74 | |
---|
75 | $sql = "SELECT scl_class, scl_id, kb3_sum_alliance.* |
---|
76 | FROM kb3_ship_classes left join kb3_sum_alliance |
---|
77 | ON (asm_shp_id = scl_id AND asm_all_id = ".$this->all_id_.") |
---|
78 | WHERE scl_class not in ('Drone','Unknown') |
---|
79 | ORDER BY scl_class"; |
---|
80 | $qry->execute($sql); |
---|
81 | while($row = $qry->getRow()) |
---|
82 | { |
---|
83 | $this->summary[$row['scl_id']]['class_name'] = $row['scl_class']; |
---|
84 | $this->summary[$row['scl_id']]['killcount'] = intval($row['asm_kill_count']); |
---|
85 | $this->summary[$row['scl_id']]['killisk'] = floatval($row['asm_kill_isk']); |
---|
86 | $this->summary[$row['scl_id']]['losscount'] = intval($row['asm_loss_count']); |
---|
87 | $this->summary[$row['scl_id']]['lossisk'] = floatval($row['asm_loss_isk']); |
---|
88 | } |
---|
89 | $this->executed_ = true; |
---|
90 | } |
---|
91 | //! Build a new summary table for an alliance. |
---|
92 | function buildSummary($all_id) |
---|
93 | { |
---|
94 | $all_id = intval($all_id); |
---|
95 | if(!$all_id) return false; |
---|
96 | $qry = new DBQuery(); |
---|
97 | $sql = 'INSERT INTO kb3_sum_alliance (asm_all_id, asm_shp_id, asm_kill_count, asm_kill_isk) |
---|
98 | SELECT '.$all_id.', shp_class, COUNT(distinct kll.kll_id) AS knb, |
---|
99 | sum(kll_isk_loss) AS kisk |
---|
100 | FROM kb3_kills kll |
---|
101 | INNER JOIN kb3_ships shp |
---|
102 | ON ( shp.shp_id = kll.kll_ship_id ) |
---|
103 | INNER JOIN (SELECT distinct c.ind_kll_id, c.ind_all_id |
---|
104 | FROM kb3_inv_detail c |
---|
105 | WHERE c.ind_all_id ='.$all_id.' ) ind |
---|
106 | ON (ind.ind_kll_id = kll.kll_id |
---|
107 | AND kll.kll_all_id <> '.$all_id.') |
---|
108 | GROUP BY shp_class'; |
---|
109 | $qry->execute($sql); |
---|
110 | $sql = "CREATE TEMPORARY TABLE tmp_summary (shp_id INT NOT NULL DEFAULT '0', |
---|
111 | loss_count INT NOT NULL DEFAULT '0', |
---|
112 | loss_isk FLOAT NOT NULL DEFAULT '0') |
---|
113 | ENGINE = MEMORY"; |
---|
114 | $qry->execute($sql); |
---|
115 | |
---|
116 | $sql = 'INSERT INTO tmp_summary (shp_id, loss_count, loss_isk) |
---|
117 | SELECT shp_class, count(distinct kll_id) AS lnb, sum(kll_isk_loss) AS lisk |
---|
118 | FROM kb3_kills kll |
---|
119 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id ) |
---|
120 | WHERE kll.kll_all_id = '.$all_id.' |
---|
121 | AND EXISTS (SELECT 1 |
---|
122 | FROM kb3_inv_detail ind |
---|
123 | WHERE kll.kll_id = ind_kll_id |
---|
124 | AND ind.ind_all_id <> '.$all_id.' limit 0,1) |
---|
125 | GROUP BY shp_class'; |
---|
126 | $qry->execute($sql); |
---|
127 | $qry->execute("INSERT INTO kb3_sum_alliance (asm_all_id, asm_shp_id, asm_loss_count, asm_loss_isk) |
---|
128 | SELECT ".$all_id.", shp_id, loss_count, loss_isk FROM tmp_summary |
---|
129 | ON DUPLICATE KEY UPDATE asm_loss_count = loss_count, asm_loss_isk = loss_isk"); |
---|
130 | $qry->execute("DROP TEMPORARY TABLE tmp_summary"); |
---|
131 | } |
---|
132 | //! Add a Kill and its value to the summary. |
---|
133 | function addKill($kill) |
---|
134 | { |
---|
135 | $alls = array(); |
---|
136 | $qry = new DBQuery(); |
---|
137 | $qry->execute("SELECT 1 FROM kb3_sum_alliance WHERE asm_all_id = ".$kill->getVictimAllianceID()); |
---|
138 | // Causes big slowdowns for feeds so just return and leave summary creation until the page is viewed. |
---|
139 | // if(!$qry->recordCount()) allianceSummary::buildSummary($kill->getVictimAllianceID()); |
---|
140 | if($qry->recordCount()) |
---|
141 | { |
---|
142 | $sql = "INSERT INTO kb3_sum_alliance (asm_all_id, asm_shp_id, asm_loss_count, asm_loss_isk) ". |
---|
143 | "VALUES ( ".$kill->getVictimAllianceID().", ".$kill->getVictimShip()->getClass()->getID().", 1, ". |
---|
144 | $kill->getISKLoss().") ON DUPLICATE KEY UPDATE ". |
---|
145 | "asm_loss_count = asm_loss_count + 1, ". |
---|
146 | "asm_loss_isk = asm_loss_isk + ".$kill->getISKLoss(); |
---|
147 | $qry->execute($sql); |
---|
148 | } |
---|
149 | foreach($kill->involvedparties_ as $inv) |
---|
150 | { |
---|
151 | if(intval($alls[$inv->getAllianceID()])) continue; |
---|
152 | $alls[$inv->getAllianceID()] = 1; |
---|
153 | $qry->execute("SELECT 1 FROM kb3_sum_alliance WHERE asm_all_id = ".$inv->getAllianceID()); |
---|
154 | //if(!$qry->recordCount()) allianceSummary::buildSummary($inv->getAllianceID()); |
---|
155 | if(!$qry->recordCount()) continue; |
---|
156 | $sql = "INSERT INTO kb3_sum_alliance (asm_all_id, asm_shp_id, asm_kill_count, asm_kill_isk) ". |
---|
157 | "VALUES ( ".$inv->getAllianceID().", ".$kill->getVictimShip()->getClass()->getID().", 1, ". |
---|
158 | $kill->getISKLoss().") ON DUPLICATE KEY UPDATE ". |
---|
159 | "asm_kill_count = asm_kill_count + 1, ". |
---|
160 | "asm_kill_isk = asm_kill_isk + ".$kill->getISKLoss(); |
---|
161 | $qry->execute($sql); |
---|
162 | } |
---|
163 | } |
---|
164 | //! Add a Kill and its value to the summary. |
---|
165 | function delKill($kill) |
---|
166 | { |
---|
167 | $alls = array(); |
---|
168 | $qry = new DBQuery(); |
---|
169 | $qry->execute("SELECT 1 FROM kb3_sum_alliance WHERE asm_all_id = ".$kill->getVictimAllianceID()); |
---|
170 | // No summary table to remove kill from so skip. |
---|
171 | if($qry->recordCount()) |
---|
172 | { |
---|
173 | $sql = "UPDATE kb3_sum_alliance SET asm_loss_count = asm_loss_count - 1, ". |
---|
174 | " asm_loss_isk = asm_loss_isk - ".$kill->getISKLoss(). |
---|
175 | " WHERE asm_all_id = ".$kill->getVictimAllianceID(). |
---|
176 | " AND asm_shp_id = ".$kill->getVictimShip()->getClass()->getID(); |
---|
177 | $qry->execute($sql); |
---|
178 | } |
---|
179 | foreach($kill->involvedparties_ as $inv) |
---|
180 | { |
---|
181 | if(intval($alls[$inv->getAllianceID()])) continue; |
---|
182 | $alls[$inv->getAllianceID()] = 1; |
---|
183 | $qry->execute("SELECT 1 FROM kb3_sum_alliance WHERE asm_all_id = ".$inv->getAllianceID()); |
---|
184 | if(!$qry->recordCount()) continue; |
---|
185 | $sql = "UPDATE kb3_sum_alliance SET asm_kill_count = asm_kill_count - 1, ". |
---|
186 | " asm_kill_isk = asm_kill_isk - ".$kill->getISKLoss(). |
---|
187 | " WHERE asm_all_id = ".$inv->getAllianceID(). |
---|
188 | " AND asm_shp_id = ".$kill->getVictimShip()->getClass()->getID(); |
---|
189 | $qry->execute($sql); |
---|
190 | } |
---|
191 | } |
---|
192 | } |
---|
193 | |
---|
194 | class corpSummary extends allianceSummary |
---|
195 | { |
---|
196 | function corpSummary($crp_id) |
---|
197 | { |
---|
198 | $this->crp_id_ = intval($crp_id); |
---|
199 | $this->executed_ = false; |
---|
200 | } |
---|
201 | //! Fetch the summary information. |
---|
202 | function execute() |
---|
203 | { |
---|
204 | if($this->executed_) return; |
---|
205 | if(!$this->crp_id_) |
---|
206 | { |
---|
207 | $this->executed_ = true; |
---|
208 | return false; |
---|
209 | } |
---|
210 | |
---|
211 | $qry = new DBQuery(); |
---|
212 | $qry->execute("SELECT 1 FROM kb3_sum_corp WHERE csm_crp_id = ".$this->crp_id_); |
---|
213 | if(!$qry->recordCount()) |
---|
214 | $this->buildSummary($this->crp_id_); |
---|
215 | |
---|
216 | $sql = "SELECT scl_class, scl_id, kb3_sum_corp.* |
---|
217 | FROM kb3_ship_classes left join kb3_sum_corp |
---|
218 | ON (csm_shp_id = scl_id AND csm_crp_id = ".$this->crp_id_.") |
---|
219 | WHERE scl_class not in ('Drone','Unknown') |
---|
220 | ORDER BY scl_class"; |
---|
221 | $qry->execute($sql); |
---|
222 | while($row = $qry->getRow()) |
---|
223 | { |
---|
224 | $this->summary[$row['scl_id']]['class_name'] = $row['scl_class']; |
---|
225 | $this->summary[$row['scl_id']]['killcount'] = intval($row['csm_kill_count']); |
---|
226 | $this->summary[$row['scl_id']]['killisk'] = floatval($row['csm_kill_isk']); |
---|
227 | $this->summary[$row['scl_id']]['losscount'] = intval($row['csm_loss_count']); |
---|
228 | $this->summary[$row['scl_id']]['lossisk'] = floatval($row['csm_loss_isk']); |
---|
229 | } |
---|
230 | $this->executed_ = true; |
---|
231 | } |
---|
232 | //! Build a new summary table for an corp. |
---|
233 | function buildSummary($crp_id) |
---|
234 | { |
---|
235 | $crp_id = intval($crp_id); |
---|
236 | if(!$crp_id) return false; |
---|
237 | $qry = new DBQuery(); |
---|
238 | $sql = 'INSERT INTO kb3_sum_corp (csm_crp_id, csm_shp_id, csm_kill_count, csm_kill_isk) |
---|
239 | SELECT '.$crp_id.', shp_class, COUNT(distinct kll.kll_id) AS knb, |
---|
240 | sum(kll_isk_loss) AS kisk |
---|
241 | FROM kb3_kills kll |
---|
242 | INNER JOIN kb3_ships shp |
---|
243 | ON ( shp.shp_id = kll.kll_ship_id ) |
---|
244 | INNER JOIN (SELECT distinct c.ind_kll_id, c.ind_crp_id |
---|
245 | FROM kb3_inv_detail c |
---|
246 | WHERE c.ind_crp_id ='.$crp_id.' ) ind |
---|
247 | ON (ind.ind_kll_id = kll.kll_id |
---|
248 | AND kll.kll_crp_id <> '.$crp_id.') |
---|
249 | GROUP BY shp_class'; |
---|
250 | $qry->execute($sql); |
---|
251 | $sql = "CREATE TEMPORARY TABLE tmp_summary (shp_id INT NOT NULL DEFAULT '0', |
---|
252 | loss_count INT NOT NULL DEFAULT '0', |
---|
253 | loss_isk FLOAT NOT NULL DEFAULT '0') |
---|
254 | ENGINE = MEMORY"; |
---|
255 | $qry->execute($sql); |
---|
256 | |
---|
257 | $sql = 'INSERT INTO tmp_summary (shp_id, loss_count, loss_isk) |
---|
258 | SELECT shp_class, count(distinct kll_id) AS lnb, sum(kll_isk_loss) AS lisk |
---|
259 | FROM kb3_kills kll |
---|
260 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id ) |
---|
261 | WHERE kll.kll_crp_id = '.$crp_id.' |
---|
262 | AND EXISTS (SELECT 1 |
---|
263 | FROM kb3_inv_detail ind |
---|
264 | WHERE kll.kll_id = ind_kll_id |
---|
265 | AND ind.ind_crp_id <> '.$crp_id.' limit 0,1) |
---|
266 | GROUP BY shp_class'; |
---|
267 | $qry->execute($sql); |
---|
268 | $qry->execute("INSERT INTO kb3_sum_corp (csm_crp_id, csm_shp_id, csm_loss_count, csm_loss_isk) |
---|
269 | SELECT ".$crp_id.", shp_id, loss_count, loss_isk FROM tmp_summary |
---|
270 | ON DUPLICATE KEY UPDATE csm_loss_count = loss_count, csm_loss_isk = loss_isk"); |
---|
271 | $qry->execute("DROP TEMPORARY TABLE tmp_summary"); |
---|
272 | } |
---|
273 | //! Add a Kill and its value to the summary. |
---|
274 | function addKill($kill) |
---|
275 | { |
---|
276 | $alls = array(); |
---|
277 | $qry = new DBQuery(); |
---|
278 | $qry->execute("SELECT 1 FROM kb3_sum_corp WHERE csm_crp_id = ".$kill->getVictimcorpID()); |
---|
279 | if(!$qry->recordCount()) |
---|
280 | { |
---|
281 | $sql = "INSERT INTO kb3_sum_corp (csm_crp_id, csm_shp_id, csm_loss_count, csm_loss_isk) ". |
---|
282 | "VALUES ( ".$kill->getVictimcorpID().", ".$kill->getVictimShip()->getClass()->getID().", 1, ". |
---|
283 | $kill->getISKLoss().") ON DUPLICATE KEY UPDATE ". |
---|
284 | "csm_loss_count = csm_loss_count + 1, ". |
---|
285 | "csm_loss_isk = csm_loss_isk + ".$kill->getISKLoss(); |
---|
286 | $qry->execute($sql); |
---|
287 | } |
---|
288 | foreach($kill->involvedparties_ as $inv) |
---|
289 | { |
---|
290 | if(intval($alls[$inv->getcorpID()])) continue; |
---|
291 | $alls[$inv->getcorpID()] = 1; |
---|
292 | $qry->execute("SELECT 1 FROM kb3_sum_corp WHERE csm_crp_id = ".$inv->getcorpID()); |
---|
293 | //if(!$qry->recordCount()) corpSummary::buildSummary($inv->getcorpID()); |
---|
294 | if(!$qry->recordCount()) continue; |
---|
295 | $sql = "INSERT INTO kb3_sum_corp (csm_crp_id, csm_shp_id, csm_kill_count, csm_kill_isk) ". |
---|
296 | "VALUES ( ".$inv->getcorpID().", ".$kill->getVictimShip()->getClass()->getID().", 1, ". |
---|
297 | $kill->getISKLoss().") ON DUPLICATE KEY UPDATE ". |
---|
298 | "csm_kill_count = csm_kill_count + 1, ". |
---|
299 | "csm_kill_isk = csm_kill_isk + ".$kill->getISKLoss(); |
---|
300 | $qry->execute($sql); |
---|
301 | } |
---|
302 | } |
---|
303 | //! Add a Kill and its value to the summary. |
---|
304 | function delKill($kill) |
---|
305 | { |
---|
306 | $alls = array(); |
---|
307 | $qry = new DBQuery(); |
---|
308 | $qry->execute("SELECT 1 FROM kb3_sum_corp WHERE csm_crp_id = ".$kill->getVictimCorpID()); |
---|
309 | // No summary table to remove kill from so skip. |
---|
310 | if($qry->recordCount()) |
---|
311 | { |
---|
312 | $sql = "UPDATE kb3_sum_corp SET csm_loss_count = csm_loss_count - 1, ". |
---|
313 | " csm_loss_isk = csm_loss_isk - ".$kill->getISKLoss(). |
---|
314 | " WHERE csm_crp_id = ".$kill->getVictimCorpID(). |
---|
315 | " AND csm_shp_id = ".$kill->getVictimShip()->getClass()->getID(); |
---|
316 | $qry->execute($sql); |
---|
317 | } |
---|
318 | foreach($kill->involvedparties_ as $inv) |
---|
319 | { |
---|
320 | if(intval($alls[$inv->getCorpID()])) continue; |
---|
321 | $alls[$inv->getCorpID()] = 1; |
---|
322 | $qry->execute("SELECT 1 FROM kb3_sum_corp WHERE csm_crp_id = ".$inv->getCorpID()); |
---|
323 | if(!$qry->recordCount()) continue; |
---|
324 | $sql = "UPDATE kb3_sum_corp SET csm_kill_count = csm_kill_count - 1, ". |
---|
325 | " csm_kill_isk = csm_kill_isk - ".$kill->getISKLoss(). |
---|
326 | " WHERE csm_crp_id = ".$inv->getCorpID(). |
---|
327 | " AND csm_shp_id = ".$kill->getVictimShip()->getClass()->getID(); |
---|
328 | $qry->execute($sql); |
---|
329 | } |
---|
330 | } |
---|
331 | } |
---|
332 | |
---|
333 | class pilotSummary extends allianceSummary |
---|
334 | { |
---|
335 | function pilotSummary($plt_id) |
---|
336 | { |
---|
337 | $this->plt_id_ = intval($plt_id); |
---|
338 | $this->executed_ = false; |
---|
339 | } |
---|
340 | //! Fetch the summary information. |
---|
341 | function execute() |
---|
342 | { |
---|
343 | if($this->executed_) return; |
---|
344 | if(!$this->plt_id_) |
---|
345 | { |
---|
346 | $this->executed_ = true; |
---|
347 | return false; |
---|
348 | } |
---|
349 | |
---|
350 | $qry = new DBQuery(); |
---|
351 | $qry->execute("SELECT 1 FROM kb3_sum_pilot WHERE psm_plt_id = ".$this->plt_id_); |
---|
352 | if(!$qry->recordCount()) |
---|
353 | $this->buildSummary($this->plt_id_); |
---|
354 | |
---|
355 | $sql = "SELECT scl_class, scl_id, kb3_sum_pilot.* |
---|
356 | FROM kb3_ship_classes left join kb3_sum_pilot |
---|
357 | ON (psm_shp_id = scl_id AND psm_plt_id = ".$this->plt_id_.") |
---|
358 | WHERE scl_class not in ('Drone','Unknown') |
---|
359 | ORDER BY scl_class"; |
---|
360 | $qry->execute($sql); |
---|
361 | while($row = $qry->getRow()) |
---|
362 | { |
---|
363 | $this->summary[$row['scl_id']]['class_name'] = $row['scl_class']; |
---|
364 | $this->summary[$row['scl_id']]['killcount'] = intval($row['psm_kill_count']); |
---|
365 | $this->summary[$row['scl_id']]['killisk'] = floatval($row['psm_kill_isk']); |
---|
366 | $this->summary[$row['scl_id']]['losscount'] = intval($row['psm_loss_count']); |
---|
367 | $this->summary[$row['scl_id']]['lossisk'] = floatval($row['psm_loss_isk']); |
---|
368 | } |
---|
369 | $this->executed_ = true; |
---|
370 | } |
---|
371 | //! Build a new summary table for an pilot. |
---|
372 | function buildSummary($plt_id) |
---|
373 | { |
---|
374 | $plt_id = intval($plt_id); |
---|
375 | if(!$plt_id) return false; |
---|
376 | $qry = new DBQuery(); |
---|
377 | $sql = 'INSERT INTO kb3_sum_pilot (psm_plt_id, psm_shp_id, psm_kill_count, psm_kill_isk) |
---|
378 | SELECT '.$plt_id.', shp_class, COUNT(distinct kll.kll_id) AS knb, |
---|
379 | sum(kll_isk_loss) AS kisk |
---|
380 | FROM kb3_kills kll |
---|
381 | INNER JOIN kb3_ships shp |
---|
382 | ON ( shp.shp_id = kll.kll_ship_id ) |
---|
383 | INNER JOIN (SELECT distinct c.ind_kll_id, c.ind_plt_id |
---|
384 | FROM kb3_inv_detail c |
---|
385 | WHERE c.ind_plt_id ='.$plt_id.' ) ind |
---|
386 | ON (ind.ind_kll_id = kll.kll_id |
---|
387 | AND kll.kll_victim_id <> '.$plt_id.') |
---|
388 | GROUP BY shp_class'; |
---|
389 | $qry->execute($sql); |
---|
390 | $sql = "CREATE TEMPORARY TABLE tmp_summary (shp_id INT NOT NULL DEFAULT '0', |
---|
391 | loss_count INT NOT NULL DEFAULT '0', |
---|
392 | loss_isk FLOAT NOT NULL DEFAULT '0') |
---|
393 | ENGINE = MEMORY"; |
---|
394 | $qry->execute($sql); |
---|
395 | |
---|
396 | $sql = 'INSERT INTO tmp_summary (shp_id, loss_count, loss_isk) |
---|
397 | SELECT shp_class, count(distinct kll_id) AS lnb, sum(kll_isk_loss) AS lisk |
---|
398 | FROM kb3_kills kll |
---|
399 | INNER JOIN kb3_ships shp ON ( shp.shp_id = kll.kll_ship_id ) |
---|
400 | WHERE kll.kll_victim_id = '.$plt_id.' |
---|
401 | AND EXISTS (SELECT 1 |
---|
402 | FROM kb3_inv_detail ind |
---|
403 | WHERE kll.kll_id = ind_kll_id |
---|
404 | AND ind.ind_plt_id <> '.$plt_id.' limit 0,1) |
---|
405 | GROUP BY shp_class'; |
---|
406 | $qry->execute($sql); |
---|
407 | $qry->execute("INSERT INTO kb3_sum_pilot (psm_plt_id, psm_shp_id, psm_loss_count, psm_loss_isk) |
---|
408 | SELECT ".$plt_id.", shp_id, loss_count, loss_isk FROM tmp_summary |
---|
409 | ON DUPLICATE KEY UPDATE psm_loss_count = loss_count, psm_loss_isk = loss_isk"); |
---|
410 | $qry->execute("DROP TEMPORARY TABLE tmp_summary"); |
---|
411 | } |
---|
412 | //! Add a Kill and its value to the summary. |
---|
413 | function addKill($kill) |
---|
414 | { |
---|
415 | $alls = array(); |
---|
416 | $qry = new DBQuery(); |
---|
417 | $qry->execute("SELECT 1 FROM kb3_sum_pilot WHERE psm_plt_id = ".$kill->getVictimID()); |
---|
418 | // if(!$qry->recordCount()) pilotSummary::buildSummary($kill->getVictimpilotID()); |
---|
419 | if(!$qry->recordCount()) |
---|
420 | { |
---|
421 | $sql = "INSERT INTO kb3_sum_pilot (psm_plt_id, psm_shp_id, psm_loss_count, psm_loss_isk) ". |
---|
422 | "VALUES ( ".$kill->getVictimID().", ".$kill->getVictimShip()->getClass()->getID().", 1, ". |
---|
423 | $kill->getISKLoss().") ON DUPLICATE KEY UPDATE ". |
---|
424 | "psm_loss_count = psm_loss_count + 1, ". |
---|
425 | "psm_loss_isk = psm_loss_isk + ".$kill->getISKLoss(); |
---|
426 | $qry->execute($sql); |
---|
427 | } |
---|
428 | foreach($kill->involvedparties_ as $inv) |
---|
429 | { |
---|
430 | if(intval($alls[$inv->getPilotID()])) continue; |
---|
431 | $alls[$inv->getPilotID()] = 1; |
---|
432 | $qry->execute("SELECT 1 FROM kb3_sum_pilot WHERE psm_plt_id = ".$inv->getPilotID()); |
---|
433 | if(!$qry->recordCount()) continue; |
---|
434 | //if(!$qry->recordCount())pilotSummary::buildSummary($inv->getpilotID()); |
---|
435 | $sql = "INSERT INTO kb3_sum_pilot (psm_plt_id, psm_shp_id, psm_kill_count, psm_kill_isk) ". |
---|
436 | "VALUES ( ".$inv->getPilotID().", ".$kill->getVictimShip()->getClass()->getID().", 1, ". |
---|
437 | $kill->getISKLoss().") ON DUPLICATE KEY UPDATE ". |
---|
438 | "psm_kill_count = psm_kill_count + 1, ". |
---|
439 | "psm_kill_isk = psm_kill_isk + ".$kill->getISKLoss(); |
---|
440 | $qry->execute($sql); |
---|
441 | } |
---|
442 | } |
---|
443 | //! Add a Kill and its value to the summary. |
---|
444 | function delKill($kill) |
---|
445 | { |
---|
446 | $alls = array(); |
---|
447 | $qry = new DBQuery(); |
---|
448 | $qry->execute("SELECT 1 FROM kb3_sum_pilot WHERE psm_plt_id = ".$kill->getVictimID()); |
---|
449 | // No summary table to remove kill from so skip. |
---|
450 | if($qry->recordCount()) |
---|
451 | { |
---|
452 | $sql = "UPDATE kb3_sum_pilot SET psm_loss_count = psm_loss_count - 1, ". |
---|
453 | " psm_loss_isk = psm_loss_isk - ".$kill->getISKLoss(). |
---|
454 | " WHERE psm_plt_id = ".$kill->getVictimID(). |
---|
455 | " AND psm_shp_id = ".$kill->getVictimShip()->getClass()->getID(); |
---|
456 | $qry->execute($sql); |
---|
457 | } |
---|
458 | foreach($kill->involvedparties_ as $inv) |
---|
459 | { |
---|
460 | if(intval($alls[$inv->getPilotID()])) continue; |
---|
461 | $alls[$inv->getPilotID()] = 1; |
---|
462 | $qry->execute("SELECT 1 FROM kb3_sum_pilot WHERE psm_plt_id = ".$inv->getPilotID()); |
---|
463 | if(!$qry->recordCount()) continue; |
---|
464 | $sql = "UPDATE kb3_sum_pilot SET psm_kill_count = psm_kill_count - 1, ". |
---|
465 | " psm_kill_isk = psm_kill_isk - ".$kill->getISKLoss(). |
---|
466 | " WHERE psm_plt_id = ".$inv->getPilotID(). |
---|
467 | " AND psm_shp_id = ".$kill->getVictimShip()->getClass()->getID(); |
---|
468 | $qry->execute($sql); |
---|
469 | } |
---|
470 | } |
---|
471 | } |
---|
472 | ?> |
---|