/** * * @param KillList $killList * @return string KillList as XML */ public static function killListToXML($killList) { global $idfeedversion; $qry = DBFactory::getDBQuery(); $date = gmdate('Y-m-d H:i:s'); $xml = "<?xml version='1.0' encoding='UTF-8'?>\n\t\t<eveapi version='2' edkapi='" . $idfeedversion . "'>\n\t\t</eveapi>"; $sxe = new SimpleXMLElement($xml); // Let's start making the xml. $sxe->addChild('currentTime', $date); $result = $sxe->addChild('result'); $kills = $result->addChild('rowset'); $kills->addAttribute('name', 'kills'); $kills->addAttribute('key', 'killID'); $kills->addAttribute('columns', 'killID,solarSystemID,killTime,moonID,hash,trust'); $count = 0; $timing = ''; while ($kill = $killList->getKill()) { if (config::get('km_cache_enabled') && CacheHandler::exists($kill->getID() . ".xml", 'mails')) { $cachedRow = new SimpleXMLElement(CacheHandler::get($kill->getID() . ".xml", 'mails')); IDFeed::addXMLElement($kills, $cachedRow); continue; } $count++; if ($kill->isClassified()) { continue; } //$kill = Kill::getByID($kill->getID()); $row = $kills->addChild('row'); $row->addAttribute('killID', intval($kill->getExternalID())); $row->addAttribute('killInternalID', intval($kill->getID())); $row->addAttribute('solarSystemID', $kill->getSystem()->getExternalID()); $row->addAttribute('killTime', $kill->getTimeStamp()); $row->addAttribute('moonID', '0'); $row->addAttribute('hash', bin2hex(IDFeed::getHash($kill, true))); $row->addAttribute('trust', 3); $victim = Pilot::getByID($kill->getVictimID()); $victimCorp = Corporation::getByID($kill->getVictimCorpID()); $victimAlliance = Alliance::getByID($kill->getVictimAllianceID()); $victimrow = $row->addChild('victim'); if ($victim->getName() == $kill->getVictimShipName()) { $victimrow->addAttribute('characterID', "0"); $victimrow->addAttribute('characterName', ""); } else { $victimrow->addAttribute('characterID', $victim->getExternalID()); $victimrow->addAttribute('characterName', $victim->getName()); } $victimrow->addAttribute('corporationID', $victimCorp->getExternalID()); $victimrow->addAttribute('corporationName', $victimCorp->getName()); if ($victimAlliance->isFaction()) { $victimrow->addAttribute('allianceID', 0); $victimrow->addAttribute('allianceName', ''); $victimrow->addAttribute('factionID', $victimAlliance->getFactionID()); $victimrow->addAttribute('factionName', $victimAlliance->getName()); } else { $victimrow->addAttribute('allianceID', $victimAlliance->getExternalID()); $victimrow->addAttribute('allianceName', $victimAlliance->getName()); $victimrow->addAttribute('factionID', 0); $victimrow->addAttribute('factionName', ''); } $victimrow->addAttribute('damageTaken', $kill->getDamageTaken()); $victimrow->addAttribute('shipTypeID', $kill->getVictimShipExternalID()); $involved = $row->addChild('rowset'); $involved->addAttribute('name', 'attackers'); $involved->addAttribute('columns', 'characterID,characterName,corporationID,corporationName,allianceID,allianceName,factionID,factionName,securityStatus,damageDone,finalBlow,weaponTypeID,shipTypeID'); $sql = "SELECT ind_sec_status, ind_all_id, ind_crp_id,\n\t\t\t\tind_shp_id, ind_wep_id, ind_order, ind_dmgdone, plt_id, plt_name,\n\t\t\t\tplt_externalid, crp_name, crp_external_id,\n\t\t\t\twtype.typeName AS wep_name FROM kb3_inv_detail\n\t\t\t\tJOIN kb3_pilots ON (plt_id = ind_plt_id)\n\t\t\t\tJOIN kb3_corps ON (crp_id = ind_crp_id)\n\t\t\t\tJOIN kb3_invtypes wtype ON (ind_wep_id = wtype.typeID)\n\t\t\t\tWHERE ind_kll_id = " . $kill->getID() . " ORDER BY ind_order ASC"; $qry->execute($sql); while ($inv = $qry->getRow()) { $invrow = $involved->addChild('row'); if (strpos($inv['plt_name'], '- ') !== false) { $inv['plt_name'] = substr($inv['plt_name'], strpos($inv['plt_name'], '- ') + 2); } else { if (strpos($inv['plt_name'], '#') !== false) { $name = explode("#", $inv['plt_name']); $inv['plt_name'] = $name[3]; } } if ($inv['plt_name'] == $inv['wep_name']) { $invrow->addAttribute('characterID', 0); $invrow->addAttribute('characterName', ""); $invrow->addAttribute('weaponTypeID', 0); $invrow->addAttribute('shipTypeID', $inv['ind_wep_id']); } else { $invrow->addAttribute('characterID', $inv['plt_externalid']); $invrow->addAttribute('characterName', $inv['plt_name']); $invrow->addAttribute('weaponTypeID', $inv['ind_wep_id']); $invrow->addAttribute('shipTypeID', $inv['ind_shp_id']); } $invrow->addAttribute('corporationID', $inv['crp_external_id']); $invrow->addAttribute('corporationName', $inv['crp_name']); $invAlliance = Alliance::getByID($inv['ind_all_id']); if ($invAlliance->isFaction()) { $invrow->addAttribute('allianceID', 0); $invrow->addAttribute('allianceName', ''); $invrow->addAttribute('factionID', $invAlliance->getFactionID()); $invrow->addAttribute('factionName', $invAlliance->getName()); } else { if (strcasecmp($invAlliance->getName(), "None") == 0) { $invrow->addAttribute('allianceID', 0); $invrow->addAttribute('allianceName', ""); } else { $invrow->addAttribute('allianceID', $invAlliance->getExternalID()); $invrow->addAttribute('allianceName', $invAlliance->getName()); } $invrow->addAttribute('factionID', 0); $invrow->addAttribute('factionName', ''); } $invrow->addAttribute('securityStatus', number_format($inv['ind_sec_status'], 1)); $invrow->addAttribute('damageDone', $inv['ind_dmgdone']); if ($inv['plt_id'] == $kill->getFBPilotID()) { $final = 1; } else { $final = 0; } $invrow->addAttribute('finalBlow', $final); } $sql = "SELECT * FROM kb3_items_destroyed WHERE itd_kll_id = " . $kill->getID(); $qry->execute($sql); $qry2 = DBFactory::getDBQuery(); $sql = "SELECT * FROM kb3_items_dropped WHERE itd_kll_id = " . $kill->getID(); $qry2->execute($sql); if ($qry->recordCount() || $qry2->recordCount()) { $items = $row->addChild('rowset'); $items->addAttribute('name', 'items'); $items->addAttribute('columns', 'typeID,flag,qtyDropped,qtyDestroyed, singleton'); while ($iRow = $qry->getRow()) { $itemRow = $items->addChild('row'); $itemRow->addAttribute('typeID', $iRow['itd_itm_id']); $itemRow->addAttribute('flag', $iRow['itd_itl_id']); if ($iRow['itd_itl_id'] == -1) { $itemRow->addAttribute('singleton', 2); } else { $itemRow->addAttribute('singleton', 0); } $itemRow->addAttribute('qtyDropped', 0); $itemRow->addAttribute('qtyDestroyed', $iRow['itd_quantity']); } while ($iRow = $qry2->getRow()) { $itemRow = $items->addChild('row'); $itemRow->addAttribute('typeID', $iRow['itd_itm_id']); $itemRow->addAttribute('flag', $iRow['itd_itl_id']); if ($iRow['itd_itl_id'] == -1) { $itemRow->addAttribute('singleton', 2); } else { $itemRow->addAttribute('singleton', 0); } $itemRow->addAttribute('qtyDropped', $iRow['itd_quantity']); $itemRow->addAttribute('qtyDestroyed', 0); } } if (config::get('km_cache_enabled')) { CacheHandler::put($kill->getID() . ".xml", $row->asXML(), 'mails'); } $timing .= $kill->getID() . ": " . (microtime(true) - $starttime) . "<br />"; } $sxe->addChild('cachedUntil', $date); return $sxe->asXML(); }
/** * Add a new corporation to the database or update the details of an existing one. * * @param string $name The name of the new corporation. * @param Alliance $alliance The alliance this corporation belongs to. * @param string $timestamp The timestamp the corporation's details were updated. * @param integer $externalid The external CCP ID for the corporation. * @param boolean $loadExternals Whether to fetch unknown information from the API. * @return Corporation */ static function add($name, $alliance, $timestamp, $externalid = 0, $loadExternals = true) { if (!$name) { trigger_error("Attempt to add a corporation with no name. Aborting.", E_USER_ERROR); // If things are going this wrong, it's safer to die and prevent more harm die; } else { if (!$alliance->getID()) { trigger_error("Attempt to add a corporation with no alliance. Aborting.", E_USER_ERROR); // If things are going this wrong, it's safer to die and prevent more harm die; } } $name = stripslashes($name); $externalid = (int) $externalid; $qry = DBFactory::getDBQuery(true); $qry->execute("select * from kb3_corps\n\t\t where crp_name = '" . $qry->escape($name) . "'"); // If the corp name is not present in the db add it. if (!$qry->recordCount()) { // If no external id is given then look it up. if (!$externalid && $loadExternals) { $myID = new API_NametoID(); $myID->setNames($name); $myID->fetchXML(); $myNames = $myID->getNameData(); $externalid = (int) $myNames[0]['characterID']; } // If we have an external id then check it isn't already in use // If we find it then update the old corp with the new name and // return. if ($externalid) { $qry->execute("SELECT * FROM kb3_corps WHERE crp_external_id = " . $externalid); if ($qry->recordCount()) { $row = $qry->getRow(); $qry->execute("UPDATE kb3_corps SET crp_name = '" . $qry->escape($name) . "' WHERE crp_external_id = " . $externalid); $crp = Corporation::getByID((int) $row['crp_id']); Cacheable::delCache($crp); $crp->name = $name; $crp->externalid = $row['crp_external_id']; if (!is_null($row['crp_updated'])) { $crp->updated = strtotime($row['crp_updated'] . " UTC"); } else { $crp->updated = null; } // Now check if the alliance needs to be updated. if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) { $sql = 'update kb3_corps set crp_all_id = ' . $alliance->getID() . ', '; $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id; $qry->execute($sql); $crp->alliance = $alliance; } return $crp; } } // Neither corp name or external id was found so add this corp as new if ($externalid) { $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_external_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ", " . $externalid . ", date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))"); } else { $qry->execute("insert into kb3_corps " . "(crp_name, crp_all_id, crp_updated) " . "values ('" . $qry->escape($name) . "'," . $alliance->getID() . ",date_format('" . $timestamp . "','%Y.%m.%d %H:%i:%s'))"); } $crp = Corporation::getByID((int) $qry->getInsertID()); $crp->name = $name; $crp->externalid = (int) $externalid; $crp->alliance = $alliance->getID(); $crp->updated = strtotime(preg_replace("/\\./", "-", $timestamp) . " UTC"); return $crp; } else { $row = $qry->getRow(); $crp = Corporation::getByID((int) $row['crp_id']); $crp->name = $row['crp_name']; $crp->externalid = (int) $row['crp_external_id']; $crp->alliance = $row['crp_all_id']; if (!is_null($row['crp_updated'])) { $crp->updated = strtotime($row['crp_updated'] . " UTC"); } else { $crp->updated = null; } if ($row['crp_all_id'] != $alliance->getID() && $crp->isUpdatable($timestamp)) { $sql = 'update kb3_corps set crp_all_id = ' . $alliance->getID() . ', '; $sql .= "crp_updated = date_format( '" . $timestamp . "','%Y.%m.%d %H:%i:%s') " . "where crp_id = " . $crp->id; $qry->execute($sql); $crp->alliance = $alliance; } if (!$crp->externalid && $externalid) { $crp->setExternalID((int) $externalid); } return $crp; } return false; }
if ($row['sta_value'] >= -5) { $icon = 'bad'; } else { $icon = 'horrible'; } } } if ($typ == 'a') { $alliance = Alliance::getByID($id); $text = $alliance->getName(); $pid = $alliance->getUnique(); $link = edkURI::page('admin_standings', $typ . $row['sta_to'], 'del'); $permt[$typ][] = array('text' => $text, 'link' => $link, 'all_url' => $alliance->getDetailsURL(), 'all_img' => $alliance->getPortraitURL(32), 'value' => $val, 'comment' => $row['sta_comment'], 'id' => $id, 'pid' => $pid, 'typ' => $row['sta_to'], 'icon' => $icon); } else { if ($typ == 'c') { $corp = Corporation::getByID((int) $row['sta_to']); $text = $corp->getName(); $link = edkURI::page('admin_standings', $typ . $row['sta_to'], 'del'); $permt[$typ][] = array('text' => $text, 'link' => $link, 'crp_url' => $corp->getDetailsURL(), 'crp_img' => $corp->getPortraitURL(32), 'value' => $val, 'comment' => $row['sta_comment'], 'id' => $id, 'typ' => $typ, 'icon' => $icon); } } } $perm = array(); if ($permt['a']) { $perm[] = array('name' => 'Alliances', 'list' => $permt['a']); } if ($permt['c']) { $perm[] = array('name' => 'Corporations', 'list' => $permt['c']); } $smarty->assignByRef('standings', $perm); $page->setContent($smarty->fetch(get_tpl('standings')));
function involvedSetup() { global $smarty; $fetchExternalIDs = array(); // involved $i = 1; $this->involved = array(); $this->ownKill = false; $invlimit = config::get('kd_involvedlimit'); if (!is_numeric($invlimit)) { $this->nolimit = 1; } foreach ($this->kill->getInvolved() as $inv) { $corp = Corporation::getByID($inv->getCorpID()); $alliance = Alliance::getByID($inv->getAllianceID()); $ship = Ship::getByID($inv->getShipID()); $alliance_name = $alliance->getName(); if (!isset($this->invAllies[$alliance_name])) { $this->invAllies[$alliance_name] = array('quantity' => 1, 'corps' => array()); } else { $this->invAllies[$alliance_name]["quantity"] += 1; } $corp_name = $corp->getName(); if (!isset($this->invAllies[$alliance_name]["corps"][$corp_name])) { $this->invAllies[$alliance_name]["corps"][$corp_name] = 1; } else { $this->invAllies[$alliance_name]["corps"][$corp_name] += 1; } $ship_name = $ship->getName(); if (!isset($this->invShips[$ship_name])) { $this->invShips[$ship_name] = 1; } else { $this->invShips[$ship_name] += 1; } if (in_array($alliance->getID(), config::get('cfg_allianceid'))) { $this->ownKill = true; } else { if (in_array($corp->getID(), config::get('cfg_corpid'))) { $this->ownKill = true; } else { if (in_array($inv->getPilotID(), config::get('cfg_pilotid'))) { $this->ownKill = true; } } } if (!$this->nolimit && $i > $invlimit) { if ($i == $invlimit + 1) { $smarty->assign('limited', true); $smarty->assign('moreInvolved', $this->kill->getInvolvedPartyCount() - $invlimit); $smarty->assign('unlimitURL', '?' . htmlentities($_SERVER['QUERY_STRING']) . '&nolimit'); } } $pilot = Pilot::getByID($inv->getPilotID()); $weapon = Item::getByID($inv->getWeaponID()); $record = array(); $record['shipImage'] = $ship->getImage(64); $record['shipName'] = $ship->getName(); $record['shipID'] = $ship->getID(); if ($ship->getID()) { $record['shipURL'] = edkURI::page('invtype', $ship->getID()); $record['shipClass'] = $ship->getClass()->getName(); } else { $record['shipURL'] = false; $record['shipClass'] = false; } $record['corpURL'] = edkURI::build(array('a', 'corp_detail', true), array('crp_id', $corp->getID(), true)); $record['corpName'] = $corp->getName(); if ($alliance && strcasecmp($alliance->getName(), "None") != 0) { $record['alliURL'] = edkURI::build(array('a', 'alliance_detail', true), array('all_id', $alliance->getID(), true)); } else { $record['alliURL'] = false; } $record['alliName'] = $alliance->getName(); $record['damageDone'] = $inv->getDamageDone(); //detects NPC type things and runs a few conversions (Rats, Towers, Bubbles) $tpilot = $pilot->getName(); if (preg_match("/-/", $tpilot)) { // a tower or bubble. But! Since we have placed the corp name in front of the // item's name, we need to quickly check which base item it was again. $namestart = strripos($tpilot, '-') + 2; //we're interested in the last dash $tpilot = substr($tpilot, $namestart); } if (!$pilot->getID() || $tpilot == $weapon->getName()) { $record['pilotURL'] = edkURI::page('invtype', $weapon->getID()); $record['pilotName'] = $weapon->getName(); $record['secStatus'] = 0; $record['portrait'] = $corp->getPortraitURL(64); $record['externalID'] = $corp->getExternalID(true); if ($record['externalID'] == 0) { $fetchExternalIDs[] = $corp->getName(); } $record['typeID'] = 2; //type number for corporations. $record['pilotURL'] = edkURI::page('invtype', $weapon->getID()); $record['shipImage'] = imageURL::getURL('Ship', $weapon->getID(), 64); $record['shipURL'] = false; $record['shipName'] = $weapon->getName(); $record['weaponURL'] = false; $record['weaponID'] = false; $record['weaponName'] = "Unknown"; } else { if ($pilot->getExternalID(true)) { $record['pilotURL'] = edkURI::build(array('a', 'pilot_detail', true), array('plt_ext_id', $pilot->getExternalID(), true)); } else { $record['pilotURL'] = edkURI::build(array('a', 'pilot_detail', true), array('plt_id', $pilot->getID(), true)); } $record['typeID'] = 1377; //type number for characters. $record['pilotName'] = $pilot->getName(); $record['secStatus'] = $inv->getSecStatus(); $record['portrait'] = $pilot->getPortraitURL(64); $record['externalID'] = $pilot->getExternalID(true); //get the external ID from the pilot class - if not found then add it to a list of pilots //and check the api in bulk if (!$record['externalID']) { $fetchExternalIDs[] = $pilot->getName(); } if ($weapon->getName() != "Unknown" && $weapon->getName() != $ship->getName()) { $record['weaponName'] = $weapon->getName(); $record['weaponID'] = $weapon->getID(); $record['weaponURL'] = edkURI::page('invtype', $weapon->getID()); } else { $record['weaponName'] = "Unknown"; } } $setOtherInvolved = true; if ($inv->getPilotID() == $this->kill->getFBPilotID()) { //Final Blow pilot $this->finalblow = $record; $setOtherInvolved = false; } if ($inv->getPilotID() == $this->kill->getTDPilotID()) { //Top Damage pilot $this->topdamage = $record; $setOtherInvolved = false; } if ($setOtherInvolved) { //other involved pilot $this->involved[] = $record; } ++$i; } //prod CCP for the entire list of names if (count($fetchExternalIDs) > 0) { $names = new API_NametoID(); $names->setNames(implode(',', $fetchExternalIDs)); $names->fetchXML(); $nameIDPair = $names->getNameData(); //fill in the pilot external IDs.. could potentially be slow //but it beats the alternative. Do nothing if no names need loading. if (count($nameIDPair) > 0) { foreach ($nameIDPair as $idpair) { //store the IDs $invovledPilots = $this->kill->getInvolved(); if (isset($this->finalblow)) { $invovledPilots[] = $this->finalblow; } if (isset($this->topdamage)) { $invovledPilots[] = $this->topdamage; } foreach ($invovledPilots as $inv) { $pilot = Cacheable::factory('Pilot', $inv->getPilotID()); $corp = Cacheable::factory('Corporation', $inv->getCorpID()); if ($idpair['name'] == $corp->getName()) { $corp->setExternalID($idpair['characterID']); } else { if ($idpair['name'] == $pilot->getName()) { $pilot->setCharacterID($idpair['characterID']); } } } //as we've already populated the structures for the template //we need to quickly retrofit it. foreach ($this->involved as $inv) { $pname = $inv['pilotName']; $cname = $inv['corpName']; if ($cname == $idpair['name']) { $inv['externalID'] = $idpair['characterID']; } else { if ($pname == $idpair['name']) { $inv['externalID'] = $idpair['characterID']; } } } //same for Final Blow/Top Damage if ($this->finalblow['corpName'] == $idpair['name'] && isset($this->finalblow)) { $this->finalblow['externalID'] = $idpair['characterID']; } else { if ($this->topdamage['pilotName'] == $idpair['name'] && isset($this->topdamage)) { $this->topdamage['externalID'] = $idpair['characterID']; } } } } } }
/** * generate Balance of Power Table * @return String HTML for the Balance Of Power tab */ public function balanceOfPower() { global $smarty; $this->sides = array(); include $this->includeDir . "class.killlisttable.php"; $BadShips = $BadAllies = $GoodShips = $GoodAllies = array(); $numberOfFriendlyPilots = 0; $numberOfHostilePilots = 0; $pilotsCounted = array(); $involvedOwners = array(); $this->numberOfInvolvedOwners = 0; $ownerAlliances = config::get('cfg_allianceid'); $ownerCorps = config::get('cfg_corpid'); $ownerPilots = config::get('cfg_pilotid'); foreach ($this->pilots as $side => $pilotA) { foreach ($pilotA as $pilotId => $kll) { foreach ($kll as $pilota) { // determine numbers of involved Owners if (in_array($pilota["aid"], $ownerAlliances)) { $involvedOwners[$pilotId] = 1; } elseif (in_array($pilota["cid"], $ownerCorps)) { $involvedOwners[$pilotId] = 1; } elseif (in_array($pilotId, $ownerPilots)) { $involvedOwners[$pilotId] = 1; } $shippa = TestPilotName($pilota["ship"]); if ($side == 'a') { $GoodShips[$shippa]["shipClass"] = $pilota["shipClass"]; $GoodShips[$shippa]["sortWeight"] = getShipClassSortWeight($pilota["shipClassObject"]); $GoodShips[$shippa]["times"] += 1; $GoodShips[$shippa]["color"] = $pilota["color"]; if ($pilota["destroyed"] == 1) { $GoodShips[$shippa]["destroyed"] += 1; } else { $GoodShips[$shippa]["destroyed"] += 0; } // check if we already got that pilot if (in_array($pilota["name"], $pilotsCounted)) { continue; } $pilotsCounted[] = $pilota["name"]; $numberOfFriendlyPilots++; $GoodAllies[$pilota["alliance"]]["quantity"] += 1; $GoodAllies[$pilota["alliance"]]["corps"][$pilota["corp"]] += 1; // now set up sides for BR Setup tab // entity type: alliance if (strcasecmp($pilota["alliance"], "None") != 0) { $allianceName = addslashes($pilota["alliance"]); if (!isset($this->sides["a"][$pilota["alliance"]])) { $this->sides["a"][$allianceName]["type"] = "alliance"; $this->sides["a"][$allianceName]["id"] = $pilota["aid"]; $this->sides["a"][$allianceName]["numberOfPilots"] = 1; $this->sides["a"][$allianceName]["logoUrl"] = html_entity_decode(Alliance::getByID($pilota["aid"])->getPortraitURL(32)); $this->sides["a"][$allianceName]["infoUrl"] = html_entity_decode($pilota["alliance_url"]); } else { $this->sides["a"][$allianceName]["numberOfPilots"] += 1; } } else { $corpName = addslashes($pilota["corp"]); if (!isset($this->sides["a"][$pilota["corp"]])) { $this->sides["a"][$corpName]["type"] = "corp"; $this->sides["a"][$corpName]["id"] = $pilota["cid"]; $this->sides["a"][$corpName]["numberOfPilots"] = 1; $this->sides["a"][$corpName]["logoUrl"] = html_entity_decode(Corporation::getByID($pilota["cid"])->getPortraitURL(32)); $this->sides["a"][$corpName]["infoUrl"] = html_entity_decode($pilota["crp_url"]); } else { $this->sides["a"][$corpName]["numberOfPilots"] += 1; } } } else { $BadShips[$shippa]["shipClass"] = $pilota["shipClass"]; $BadShips[$shippa]["sortWeight"] = getShipClassSortWeight($pilota["shipClassObject"]); $BadShips[$shippa]["times"] += 1; $BadShips[$shippa]["color"] = $pilota["color"]; if ($pilota["destroyed"] == 1) { $BadShips[$shippa]["destroyed"] += 1; } else { $BadShips[$shippa]["destroyed"] += 0; } // check if we already got that pilot if (in_array($pilota["name"], $pilotsCounted)) { continue; } $pilotsCounted[] = $pilota["name"]; $numberOfHostilePilots++; // adjust numbers for the same pilots in different ships if ($pilota[0]["times"] > 1) { $numberOfHostilePilots -= $pilota[0]["times"] - 1; } $BadAllies[$pilota["alliance"]]["quantity"] += 1; $BadAllies[$pilota["alliance"]]["corps"][$pilota["corp"]] += 1; // now set up sides for BR Setup tab // entity type: alliance if (strcasecmp($pilota["alliance"], "None") != 0) { $allianceName = addslashes($pilota["alliance"]); if (!isset($this->sides["e"][$pilota["alliance"]])) { $this->sides["e"][$allianceName]["type"] = "alliance"; $this->sides["e"][$allianceName]["id"] = $pilota["aid"]; $this->sides["e"][$allianceName]["numberOfPilots"] = 1; $this->sides["e"][$allianceName]["logoUrl"] = html_entity_decode(Alliance::getByID($pilota["aid"])->getPortraitURL(32)); $this->sides["e"][$allianceName]["infoUrl"] = html_entity_decode($pilota["alliance_url"]); } else { $this->sides["e"][$allianceName]["numberOfPilots"] += 1; } } else { $corpName = addslashes($pilota["corp"]); if (!isset($this->sides["e"][$pilota["corp"]])) { $this->sides["e"][$corpName]["type"] = "corp"; $this->sides["e"][$corpName]["id"] = $pilota["cid"]; $this->sides["e"][$corpName]["numberOfPilots"] = 1; $this->sides["e"][$corpName]["logoUrl"] = html_entity_decode(Corporation::getByID($pilota["cid"])->getPortraitURL(32)); $this->sides["e"][$corpName]["infoUrl"] = html_entity_decode($pilota["crp_url"]); } else { $this->sides["e"][$corpName]["numberOfPilots"] += 1; } } } } } } $this->numberOfInvolvedOwners = count($involvedOwners); foreach ($involvedOwners as $involvedOwnerId => $one) { $this->involvedOwners[] = $involvedOwnerId; } // calculate percentages foreach ($GoodAllies as $name => &$info) { $info["percentage"] = round($info["quantity"] / $numberOfFriendlyPilots * 100, 1); arsort($info["corps"]); } foreach ($BadAllies as $name => &$info) { $info["percentage"] = round($info["quantity"] / $numberOfHostilePilots * 100, 1); arsort($info["corps"]); } if (!is_null($GoodShips)) { uasort($GoodShips, array($this, 'sortShipClasses')); } if (!is_null($GoodAllies)) { arsort($GoodAllies); } $smarty->assignByRef('GAlliesCount', count($GoodAllies)); $smarty->assignByRef('GoodAllies', $GoodAllies); $smarty->assignByRef('GoodShips', $GoodShips); if (!is_null($BadShips)) { uasort($BadShips, array($this, 'sortShipClasses')); } if (!is_null($BadAllies)) { arsort($BadAllies); } $smarty->assignByRef('BAlliesCount', count($BadAllies)); $smarty->assignByRef('BadAllies', $BadAllies); $smarty->assignByRef('BadShips', $BadShips); $smarty->assign("numberOfFriendlyPilots", $numberOfFriendlyPilots); $smarty->assign("numberOfHostilePilots", $numberOfHostilePilots); return $smarty->fetch($this->templateDir . "battle_balance.tpl"); }
/** * Show the overall statistics for this alliance. * * @global Smarty $smarty * @return string */ function stats() { global $smarty; if ($this->alliance->isFaction()) { $this->page->setTitle(Language::get('page_faction_det') . ' - ' . $this->alliance->getName() . " [" . $this->alliance->getshortName() . "]"); } else { $this->page->setTitle(Language::get('page_all_det') . ' - ' . $this->alliance->getName() . " [" . $this->alliance->getshortName() . "]"); } $sql = "select crp_id from kb3_corps WHERE crp_all_id=" . $this->alliance->getID(); $qry = DBFactory::getDBQuery(); $qry->execute($sql); while ($row = $qry->getRow()) { $this->allianceCorps[] = Corporation::getByID((int) $row['crp_id']); } if (!isset($this->kill_summary)) { $this->kill_summary = new KillSummaryTable(); $this->kill_summary->addInvolvedAlliance($this->alliance); $this->kill_summary->generate(); } $execcrp = Corporation::lookupByExternalID($this->alliance->GetExecutorID()); if ($execcrp !== false) { $smarty->assign('ExecutorName', $execcrp->getName()); } else { $smarty->assign('ExecutorName', ''); } $smarty->registerObject('Alliance', $this->alliance); $smarty->assign('memberCorpCount', count($this->allianceCorps)); if ($this->kill_summary->getTotalKillISK()) { $efficiency = round($this->kill_summary->getTotalKillISK() / ($this->kill_summary->getTotalKillISK() + $this->kill_summary->getTotalLossISK()) * 100, 2); } else { $efficiency = 0; } // The summary table is also used by the stats. Whichever is called // first generates the table. $smarty->assign('all_img', $this->alliance->getPortraitURL(128)); $smarty->assign('totalkills', $this->kill_summary->getTotalKills()); $smarty->assign('totallosses', $this->kill_summary->getTotalLosses()); $smarty->assign('totalkisk', round($this->kill_summary->getTotalKillISK() / 1000000000, 2)); $smarty->assign('totallisk', round($this->kill_summary->getTotalLossISK() / 1000000000, 2)); if ($this->kill_summary->getTotalKillISK()) { $smarty->assign('efficiency', round($this->kill_summary->getTotalKillISK() / ($this->kill_summary->getTotalKillISK() + $this->kill_summary->getTotalLossISK()) * 100, 2)); } else { $smarty->assign('efficiency', '0'); } return $smarty->fetch(get_tpl('alliance_detail_stats')); }