public static function generateBattle(Kingboard_BattleSettings $battleSetting)
 {
     $okills = array();
     $olosses = array();
     $kills = Kingboard_Kill::find(array("killTime" => array('$gt' => $battleSetting->startdate, '$lt' => $battleSetting->enddate), "location.solarSystem" => $battleSetting->system, '$or' => array(array("attackers.corporationID" => array('$in' => array_keys($battleSetting->positives))), array("attackers.allianceID" => array('$in' => array_keys($battleSetting->positives)))), 'victim.corporationID' => array('$nin' => array_keys($battleSetting->positives)), 'victim.allianceID' => array('$nin' => array_keys($battleSetting->positives))));
     $losses = Kingboard_Kill::find(array("killTime" => array('$gt' => $battleSetting->startdate, '$lt' => $battleSetting->enddate), "location.solarSystem" => $battleSetting->system, '$or' => array(array("victim.corporationID" => array('$in' => array_keys($battleSetting->positives))), array("victim.allianceID" => array('$in' => array_keys($battleSetting->positives))))));
     $timeline = array();
     foreach ($kills as $kill) {
         $killTime = date("Y-m-d H:i:s", $kill->killTime->sec);
         if (!isset($timeline[$killTime])) {
             $timeline[$killTime] = array("kills" => array(), "losses" => array());
         }
         $timeline[$killTime]['kills'][] = $kill->toArray();
         $okills[] = $kill->toArray();
     }
     foreach ($losses as $kill) {
         $killTime = date("Y-m-d H:i:s", $kill->killTime->sec);
         if (!isset($timeline[$killTime])) {
             $timeline[$killTime] = array("kills" => array(), "losses" => array());
         }
         $timeline[$killTime]['losses'][] = $kill->toArray();
         $olosses[] = $kill->toArray();
     }
     ksort($timeline);
     return array("kills" => $okills, "losses" => $olosses, "timeline" => $timeline);
 }
 public function alliance($request)
 {
     if (!empty($request['hid'])) {
         $count = Kingboard_Kill::find(array('attackers.allianceID' => (int) $request['hid']))->count();
         $killdata = Kingboard_Kill::find(array('attackers.allianceID' => (int) $request['hid']))->sort(array('killTime' => -1))->limit(20);
         $lossdata = Kingboard_Kill::find(array('victim.allianceID' => (int) $request['hid']))->sort(array('killTime' => -1))->limit(20);
         $killstats = Kingboard_Kill_MapReduce_KillsByShipByAlliance::mapReduceKills((int) $request['hid']);
         $lossstats = Kingboard_Kill_MapReduce_KillsByShipByAlliance::mapReduceLosses((int) $request['hid']);
         $template = "alliance_home.html";
         $info = Kingboard_Kill::getAllianceInfoFromId($request['hid']);
         return $this->render($template, array('killdata' => $killdata, 'lossdata' => $lossdata, 'count' => $count, 'killstats' => $killstats, 'lossstats' => $lossstats, 'info' => $info));
     } else {
         die('no alliance id specified');
     }
 }
 public function victims(array $parameters)
 {
     $term = $_GET['term'];
     // at least 4 characters here or that will get quite slow
     if (strlen($term) < 4) {
         echo json_encode(array());
         return;
     }
     $result = Kingboard_Kill::find(array('victim.characterName' => new MongoRegex('/^' . $term . '.*/i')), array('victim.characterName' => 1))->limit(50);
     $names = array();
     foreach ($result as $res) {
         $names[$res['victim']['characterName']] = true;
     }
     $names = array_keys($names);
     echo json_encode($names);
 }
 public function testIfCollisionCanOccurWithTheCurrentIdHash()
 {
     // Comment out the next linge to enable the test
     $this->markTestSkipped('Not part of the build process');
     $found = array();
     $errors = array();
     $allKills = Kingboard_Kill::find();
     foreach ($allKills as $kill) {
         $hash = new Kingboard_KillmailHash_IdHash();
         $hash->setVictimId((int) (empty($kill['victim']['characterID']) ? $kill['victim']['corporationID'] : $kill['victim']['characterID']));
         $hash->setTime(new MongoDate(strtotime(str_replace('.', '-', $kill['killTime']))));
         $hash->setVictimShip($kill['victim']['shipTypeID']);
         foreach ($kill['attackers'] as $attacker) {
             $hash->pushAttackerData($attacker);
         }
         foreach ($kill['items'] as $item) {
             $hash->addItem($item);
         }
         try {
             $hash = $hash->generateHash();
             if (!isset($found[$hash])) {
                 $found[$hash] = array();
             }
             $found[$hash][] = $kill['killID'];
         } catch (Kingboard_KillmailHash_ErrorException $e) {
             $errors[] = "Error {$e->getMessage()}: at kill {$kill['killID']}\n";
         }
     }
     if (!empty($errors)) {
         echo implode('', $errors) . "\n";
     }
     $collisions = false;
     foreach ($found as $hash => $foundOnes) {
         if (count($foundOnes) > 1) {
             echo "Hash '{$hash}' generated for this kills: " . implode(', ', $foundOnes) . "\n";
             $collisions = true;
         }
     }
     if ($collisions) {
         $this->fail('Collisions detected');
     }
 }