/**
  * Generate the output html from the template file.
  */
 function generate()
 {
     global $smarty;
     $rows = array();
     $max = 0;
     for ($i = 1; $i <= $this->length_; $i++) {
         $row = $this->toplist_->getRow();
         if ($row) {
             $rows[] = $row;
         }
         if ($row['cnt'] > $max) {
             $max = $row['cnt'];
         }
     }
     if (empty($rows)) {
         return;
     }
     $pilot = new Pilot($rows[0]['plt_id']);
     $smarty->assign('title', $this->title_);
     $smarty->assign('pilot_portrait', $pilot->getPortraitURL(64));
     $smarty->assign('award_img', config::get('cfg_img') . "/awards/" . $this->award_ . ".png");
     $smarty->assign('url', edkURI::build(array('a', 'pilot_detail', true), array('plt_id', $rows[0]['plt_id'], true)));
     $smarty->assign('name', $pilot->getName());
     $bar = new BarGraph($rows[0]['cnt'], $max);
     $smarty->assign('bar', $bar->generate());
     $smarty->assign('cnt', $rows[0]['cnt']);
     for ($i = 2; $i < $this->length_ + 1; $i++) {
         if (!$rows[$i - 1]['plt_id']) {
             break;
         } else {
             if (!$rows[$i - 1]['plt_name']) {
                 $pilot = new Pilot($rows[$i - 1]['plt_id']);
                 $pilotname = $pilot->getName();
             } else {
                 $pilotname = $rows[$i - 1]['plt_name'];
             }
         }
         $bar = new BarGraph($rows[$i - 1]['cnt'], $max);
         $top[$i] = array('url' => edkURI::build(array('a', 'pilot_detail', true), array('plt_id', $rows[$i - 1]['plt_id'], true)), 'name' => $pilotname, 'bar' => $bar->generate(), 'cnt' => $rows[$i - 1]['cnt']);
     }
     $smarty->assign('top', $top);
     $smarty->assign('comment', $this->comment_);
     return $smarty->fetch(get_tpl('award_box'));
 }
Example #2
0
 /**
  *  Build the killlists that are needed for the options selected.
  */
 function killList()
 {
     if (isset($this->viewList[$this->view])) {
         return call_user_func_array($this->viewList[$this->view], array(&$this));
     }
     $scl_id = (int) edkURI::getArg('scl_id');
     global $smarty;
     $html = '';
     $smarty->assign('view', $this->view);
     switch ($this->view) {
         case "":
             $targets = array();
             $curtarget = array();
             while ($target =& $this->contract->getContractTarget()) {
                 $kl =& $target->getKillList();
                 $ll =& $target->getLossList();
                 $summary = new KillSummaryTable($kl, $ll);
                 $summary->setVerbose(true);
                 $summary->setView('combined');
                 $curtargets['type'] = $target->getType();
                 $curtargets['id'] = $target->getID();
                 $curtargets['name'] = $target->getName();
                 $curtargets['summary'] = $summary->generate();
                 if ($summary->getTotalKillISK()) {
                     $curtargets['efficiency'] = round($summary->getTotalKillISK() / ($summary->getTotalKillISK() + $summary->getTotalLossISK()) * 100, 2);
                 } else {
                     $curtargets['efficiency'] = 0;
                 }
                 $curtargets['total_kills'] = $summary->getTotalKills();
                 $curtargets['total_losses'] = $summary->getTotalLosses();
                 $curtargets['total_kill_isk'] = round($summary->getTotalKillISK() / 1000000000, 2);
                 $curtargets['total_loss_isk'] = round($summary->getTotalLossISK() / 1000000000, 2);
                 $bar = new BarGraph($curtargets['efficiency'], 100, 120);
                 $curtargets['bar'] = $bar->generate();
                 $targets[] = $curtargets;
             }
             $smarty->assignByRef('targets', $targets);
             $smarty->assign('akey', session::isAdmin() ? session::makeKey() : false);
             $html .= $smarty->fetch(get_tpl('cc_detail_lists'));
             break;
         case "recent_activity":
             $this->contract = new Contract($this->ctr_id);
             $klist = $this->contract->getKillList();
             $klist->setOrdered(true);
             if ($scl_id) {
                 $klist->addVictimShipClass($scl_id);
             } else {
                 $klist->setPodsNoobShips(config::get('podnoobs'));
             }
             $table = new KillListTable($klist);
             $table->setLimit(10);
             $smarty->assign('killtable', $table->generate());
             $llist = $this->contract->getLossList();
             $llist->setOrdered(true);
             if ($scl_id) {
                 $llist->addVictimShipClass($scl_id);
             } else {
                 $llist->setPodsNoobShips(config::get('podnoobs'));
             }
             $table = new KillListTable($llist);
             $table->setLimit(10);
             $smarty->assign('losstable', $table->generate());
             $smarty->assign('akey', session::isAdmin() ? session::makeKey() : false);
             $html .= $smarty->fetch(get_tpl('cc_detail_lists'));
             break;
         case "kills":
             $this->contract = new Contract($this->ctr_id);
             $list = $this->contract->getKillList();
             $list->setOrdered(true);
             if ($scl_id) {
                 $list->addVictimShipClass($scl_id);
             } else {
                 $list->setPodsNoobShips(config::get('podnoobs'));
             }
             $list->setPageSplit(config::get('killcount'));
             $pagesplitter = new PageSplitter($list->getCount(), config::get('killcount'));
             $table = new KillListTable($list);
             $smarty->assign('killtable', $table->generate());
             $smarty->assign('splitter', $pagesplitter->generate());
             $smarty->assign('akey', session::isAdmin() ? session::makeKey() : false);
             $html .= $smarty->fetch(get_tpl('cc_detail_lists'));
             break;
         case "losses":
             $this->contract = new Contract($this->ctr_id);
             $llist = $this->contract->getLossList();
             $llist->setOrdered(true);
             if ($scl_id) {
                 $llist->addVictimShipClass($scl_id);
             } else {
                 $llist->setPodsNoobShips(config::get('podnoobs'));
             }
             $llist->setPageSplit(config::get('killcount'));
             $pagesplitter = new PageSplitter($llist->getCount(), config::get('killcount'));
             $table = new KillListTable($llist);
             $smarty->assign('losstable', $table->generate());
             $smarty->assign('splitter', $pagesplitter->generate());
             $smarty->assign('akey', session::isAdmin() ? session::makeKey() : false);
             $html .= $smarty->fetch(get_tpl('cc_detail_lists'));
             break;
     }
     return $html;
 }
 function getTableStats()
 {
     // Don't use caching to save memory. These queries are once only.
     $qry = new DBQuery(true);
     $this->metric_total = $this->contractlist_->getCount();
     for ($i = 0; $i < $this->contractlist_->getCount(); $i++) {
         $contract = $this->contractlist_->getBattle($i);
         if (!($contract->getKillISK() + $contract->getLossISK() > config::get('fleet_battles_mod_minisk') * 1000000)) {
             $this->metric_total = $this->metric_total - 1;
             continue 1;
         }
         // generate all necessary objects within the contract
         $contract->execQuery();
         for ($j = 0; $j < 2; $j++) {
             if ($j == 0) {
                 $list =& $contract->llist_;
             } else {
                 $list =& $contract->klist_;
             }
             $isk = $list->getISK();
             if ($j == 0) {
                 $ldata = array('losses' => $list->getCount(), 'lossisk' => $isk / 1000);
                 $this->lss_isk_all_time += $isk;
             } else {
                 $kdata = array('kills' => $list->getCount(), 'killisk' => $isk / 1000);
                 $this->kll_isk_all_time += $isk;
             }
         }
         if ($kdata['killisk']) {
             $efficiency = round($kdata['killisk'] / ($kdata['killisk'] + $ldata['lossisk']) * 100, 2);
         } else {
             $efficiency = 0;
         }
         $bar = new BarGraph($efficiency, 100);
         if (!config::get('fleet_battles_mod_cache')) {
             $this->inv_all_time += $contract->getInvolved();
             $this->kll_all_time += $contract->getKills();
             $this->lss_all_time += $contract->getLosses();
         }
         $battle = array_merge(array('name' => $contract->getName(), 'startdate' => $contract->getStartDate(), 'enddate' => $contract->getEndDate(), 'bar' => $bar->generate(), 'endtime' => date('H:i:s', strtotime($contract->getEndDate())), 'efficiency' => $efficiency, 'involved' => $contract->getInvolved(), 'kll_id' => $contract->getKillID(), 'id' => $contract->getID(), 'numberOfOwnersInvolved' => $contract->getNumberOfOwnersInvolved(), 'ownerPilotIds' => $contract->getOwnersInvolved()), $kdata, $ldata);
         if (config::get('fleet_battles_mod_cache')) {
             $this->cacheBattle($battle);
         } else {
             $tbldata[] = $battle;
         }
     }
     if (config::get('fleet_battles_mod_cache')) {
         $cacheq = DBFactory::getDBQuery();
         $whereSql = "";
         if ($this->isFiltered) {
             $filterTerms = $this->getFilterArgumentsWhereSql();
             // build filter-string
             if (!empty($filterTerms)) {
                 $whereSql = "WHERE " . implode(" AND ", $filterTerms);
             }
         }
         $sql = "SELECT * \n                                    FROM kb3_battles_cache bc\n                                        INNER JOIN kb3_systems sys ON sys.sys_name = bc.system\n                                        INNER JOIN kb3_constellations con ON con.con_id = sys.sys_con_id\n                                        INNER JOIN kb3_regions reg ON reg.reg_id = con.con_reg_id\n                                    {$whereSql} \n                                    ORDER BY end DESC";
         $cacheq->execute($sql);
         while ($cb = $cacheq->getRow()) {
             $args = array();
             $args[] = array('a', 'kill_related', true);
             $tbldata[] = array('name' => $cb['system'], 'kll_id' => $cb['kll_id'], 'id' => $cb['battle_id'], 'enddate' => $cb['end'], 'startdate' => $cb['start'], 'endtime' => date('H:i:s', strtotime($cb['end'])), 'kills' => $cb['kills'], 'losses' => $cb['losses'], 'efficiency' => $cb['efficiency'], 'involved' => $cb['involved'], 'killisk' => $cb['killisk'], 'lossisk' => $cb['lossisk'], 'bar' => $cb['bar'], 'numberOfOwnersInvolved' => $cb['ownersInvolved'], 'battle_url' => edkURI::build($args, array('kll_id', $cb['kll_id'], true), array('battle', true, true)));
         }
     }
     return $tbldata;
 }
    /**
     * Get the statistics for this table.
     * @return array Array of table statistics.
     */
    function getTableStats()
    {
        $qry = DBFactory::getDBQuery();
        while ($contract = $this->contractlist->getContract()) {
            // Losses
            // Outer query adds up the ships and cost.
            $sql = 'SELECT COUNT(kll_id) AS ships, SUM(kll_isk_loss) AS isk FROM (';
            $invcount = count($contract->getAlliances()) + count($contract->getCorps());
            // Inner query does the hard work of picking which kills to count.
            // Only use DISTINCT if we have to.
            if ($invcount > 1) {
                $sql .= 'SELECT DISTINCT kll_id, kll_isk_loss FROM kb3_kills kll ';
            } else {
                $sql .= 'SELECT kll_id, kll_isk_loss FROM kb3_kills kll ';
            }
            if ($contract->getRegions()) {
                $sql .= ' INNER JOIN kb3_systems sys ON ( sys.sys_id = kll.kll_system_id )
						INNER JOIN kb3_constellations con ON ( con.con_id = sys.sys_con_id)';
            }
            if ($contract->getCorps()) {
                $sql .= ' INNER JOIN kb3_inv_crp inc ON ( kll.kll_id = inc.inc_kll_id ) ';
            }
            if ($contract->getAlliances()) {
                $sql .= ' INNER JOIN kb3_inv_all ina ON ( kll.kll_id = ina.ina_kll_id ) ';
            }
            $andargs = array();
            if ($contract->getStartDate()) {
                $andargs[] = "kll.kll_timestamp >= '" . $contract->getStartDate() . "' ";
                if ($contract->getCorps()) {
                    $andargs[] = "inc.inc_timestamp >= '" . $contract->getStartDate() . "' ";
                }
                if ($contract->getAlliances()) {
                    $andargs[] = "ina.ina_timestamp >= '" . $contract->getStartDate() . "' ";
                }
            }
            if ($contract->getEndDate()) {
                $andargs[] = "kll.kll_timestamp < '" . $contract->getEndDate() . "' ";
                if ($contract->getCorps()) {
                    $andargs[] = "inc.inc_timestamp < '" . $contract->getEndDate() . "' ";
                }
                if ($contract->getAlliances()) {
                    $andargs[] = "ina.ina_timestamp < '" . $contract->getEndDate() . "' ";
                }
            }
            // Who are we shooting?
            $orargs = array();
            if ($contract->getCorps()) {
                $orargs[] = 'inc.inc_crp_id in ( ' . join(',', $contract->getCorps()) . ')';
            }
            if ($contract->getAlliances()) {
                $orargs[] = 'ina.ina_all_id in ( ' . join(',', $contract->getAlliances()) . ')';
            }
            if (count($orargs)) {
                $andargs[] = '(' . join(' OR ', $orargs) . ')';
            }
            // Who are we?
            $orargs = array();
            if (count(config::get('cfg_allianceid'))) {
                $orargs[] = 'kll.kll_all_id IN (' . implode(",", config::get('cfg_allianceid')) . ") ";
            }
            if (count(config::get('cfg_corpid'))) {
                $orargs[] = 'kll.kll_crp_id IN (' . implode(",", config::get('cfg_corpid')) . ") ";
            }
            if (count(config::get('cfg_pilotid'))) {
                $orargs[] = 'kll.kll_victim_id IN (' . implode(",", config::get('cfg_pilotid')) . ") ";
            }
            if (count($orargs)) {
                $andargs[] = '(' . join(' OR ', $orargs) . ')';
            }
            $orargs = array();
            if ($contract->getSystems()) {
                $orargs[] = 'kll.kll_system_id in ( ' . join(',', $contract->getSystems()) . ')';
            }
            if ($contract->getRegions()) {
                $orargs[] = 'con.con_reg_id in ( ' . join(',', $contract->getRegions()) . ' )';
            }
            if (count($orargs)) {
                $andargs[] = '(' . join(' OR ', $orargs) . ')';
            }
            if (count($andargs)) {
                $sql .= 'WHERE ' . join(' AND ', $andargs);
            }
            $sql .= ') as kb3_shadow';
            $sql .= " /* contract: getTableStats '{$invcount}:losses */";
            $result = $qry->execute($sql);
            $row = $qry->getRow($result);
            $ldata = array('losses' => $row['ships'], 'lossisk' => $row['isk'] / 1000);
            // Kills
            $sql = 'SELECT COUNT(kll_id) AS ships, sum(kll_isk_loss) AS isk FROM (';
            $invcount = count(config::get('cfg_pilotid')) + count(config::get('cfg_corpid')) + count(config::get('cfg_allianceid'));
            if ($invcount > 1) {
                $sql .= 'SELECT DISTINCT kll_id, kll_isk_loss FROM kb3_kills kll ';
            } else {
                $sql .= 'SELECT kll_id, kll_isk_loss FROM kb3_kills kll ';
            }
            if ($contract->getRegions()) {
                $sql .= ' INNER JOIN kb3_systems sys ON ( sys.sys_id = kll.kll_system_id )
						INNER JOIN kb3_constellations con ON ( con.con_id = sys.sys_con_id)';
            }
            if (count(config::get('cfg_pilotid'))) {
                $sql .= ' INNER JOIN kb3_inv_detail ind ON ( kll.kll_id = ind.ind_kll_id ) ';
            }
            if (count(config::get('cfg_corpid'))) {
                $sql .= ' INNER JOIN kb3_inv_crp inc ON ( kll.kll_id = inc.inc_kll_id ) ';
            }
            if (count(config::get('cfg_allianceid'))) {
                $sql .= ' INNER JOIN kb3_inv_all ina ON ( kll.kll_id = ina.ina_kll_id ) ';
            }
            $andargs = array();
            if ($contract->getStartDate()) {
                $andargs[] = "kll.kll_timestamp >= '" . $contract->getStartDate() . "' ";
                if (count(config::get('cfg_corpid'))) {
                    $andargs[] = "inc.inc_timestamp >= '" . $contract->getStartDate() . "' ";
                }
                if (count(config::get('cfg_allianceid'))) {
                    $andargs[] = "ina.ina_timestamp >= '" . $contract->getStartDate() . "' ";
                }
            }
            if ($contract->getEndDate()) {
                $andargs[] = "kll.kll_timestamp < '" . $contract->getEndDate() . "' ";
                if (count(config::get('cfg_corpid'))) {
                    $andargs[] = "inc.inc_timestamp < '" . $contract->getEndDate() . "' ";
                }
                if (count(config::get('cfg_allianceid'))) {
                    $andargs[] = "ina.ina_timestamp < '" . $contract->getEndDate() . "' ";
                }
            }
            $orargs = array();
            if ($contract->getCorps()) {
                $orargs[] = 'kll.kll_crp_id in ( ' . join(',', $contract->getCorps()) . ' )';
            }
            if ($contract->getAlliances()) {
                $orargs[] = 'kll.kll_all_id in ( ' . join(',', $contract->getAlliances()) . ' )';
            }
            if (count($orargs)) {
                $andargs[] = '(' . join(' OR ', $orargs) . ')';
            }
            $orargs = array();
            if (count(config::get('cfg_allianceid'))) {
                $orargs[] = '  ina.ina_all_id IN (' . implode(",", config::get('cfg_allianceid')) . ") ";
            }
            if (count(config::get('cfg_corpid'))) {
                $orargs[] = ' inc.inc_crp_id IN (' . implode(",", config::get('cfg_corpid')) . ") ";
            }
            if (count(config::get('cfg_pilotid'))) {
                $orargs[] = ' ind.ind_plt_id IN (' . implode(",", config::get('cfg_pilotid')) . ") ";
            }
            if (count($orargs)) {
                $andargs[] = '(' . join(' OR ', $orargs) . ')';
            }
            $orargs = array();
            if ($contract->getSystems()) {
                $orargs[] = 'kll.kll_system_id in ( ' . join(',', $contract->getSystems()) . ')';
            }
            if ($contract->getRegions()) {
                $orargs[] = 'con.con_reg_id in ( ' . join(',', $contract->getRegions()) . ' )';
            }
            if (count($orargs)) {
                $andargs[] = '(' . join(' OR ', $orargs) . ')';
            }
            if (count($andargs)) {
                $sql .= 'WHERE ' . join(' AND ', $andargs);
            }
            $sql .= ') as kb3_shadow';
            $sql .= " /* contract: getTableStats '{$invcount}':kills' */";
            $result = $qry->execute($sql);
            $row = $qry->getRow($result);
            $kdata = array('kills' => $row['ships'], 'killisk' => $row['isk'] / 1000);
            if ($kdata['killisk']) {
                $efficiency = round($kdata['killisk'] / ($kdata['killisk'] + $ldata['lossisk']) * 100, 2);
            } else {
                $efficiency = 0;
            }
            $bar = new BarGraph($efficiency, 100);
            $tbldata[] = array_merge(array('name' => $contract->getName(), 'startdate' => $contract->getStartDate(), 'bar' => $bar->generate(), 'enddate' => $contract->getEndDate(), 'efficiency' => $efficiency, 'id' => $contract->getID(), 'url' => edkURI::page('cc_detail', $contract->getID(), 'ctr_id')), $kdata, $ldata);
        }
        $this->contractlist->rewind();
        return $tbldata;
    }