コード例 #1
0
ファイル: KillList.php プロジェクト: kingboard/kingboard
 /**
  * @param string $ownerType
  * @param string $ownerID
  */
 public function __construct($ownerType, $ownerID)
 {
     $this->ownerType = $ownerType;
     $this->ownerID = $ownerID;
     switch ($this->ownerType) {
         case "alliance":
             $killstats = \Kingboard\Model\MapReduce\KillsByShipByAlliance::getInstanceByAllianceId((int) $this->ownerID);
             $lossstats = \Kingboard\Model\MapReduce\LossesByShipByAlliance::getInstanceByAllianceId((int) $this->ownerID);
             $criteria = array("involvedAlliances" => (int) $this->ownerID);
             break;
         case "faction":
             $killstats = \Kingboard\Model\MapReduce\KillsByShipByFaction::getInstanceByFactionId((int) $this->ownerID);
             $lossstats = \Kingboard\Model\MapReduce\LossesByShipByFaction::getInstanceByFactionId((int) $this->ownerID);
             $criteria = array("involvedFactions" => (int) $this->ownerID);
             break;
         case "corp":
         case "corporation":
             $killstats = \Kingboard\Model\MapReduce\KillsByShipByCorporation::getInstanceByCorporationId((int) $this->ownerID);
             $lossstats = \Kingboard\Model\MapReduce\LossesByShipByCorporation::getInstanceByCorporationId((int) $this->ownerID);
             $criteria = array("involvedCorporations" => (int) $this->ownerID);
             break;
         case "char":
         case "character":
         case "pilot":
             $killstats = \Kingboard\Model\MapReduce\KillsByShipByPilot::getInstanceByPilotId((int) $this->ownerID);
             $lossstats = \Kingboard\Model\MapReduce\LossesByShipByPilot::getInstanceByPilotId((int) $this->ownerID);
             /*$criteria = array('$or' => array(
                   array('attackers.characterID' => (int) $this->ownerID),
                   array('victim.characterID' => (int) $this->ownerID)
               ));*/
             $criteria = array("involvedCharacters" => (int) $this->ownerID);
             break;
         default:
             // its not a known type of anything, so we dont need to set anything here.
             // but can return
             return;
     }
     $totalstats = array();
     $count = 0;
     if (isset($killstats['value']['ship'])) {
         foreach ($killstats['value']['ship'] as $type => $value) {
             if (!isset($totalstats[$type])) {
                 $totalstats[$type] = array('kills' => 0, 'losses' => 0);
             }
             $totalstats[$type]['kills'] = $value;
             $count += $value;
         }
     }
     if (isset($lossstats['value']['ship'])) {
         foreach ($lossstats['value']['ship'] as $type => $value) {
             if (!isset($totalstats[$type])) {
                 $totalstats[$type] = array('kills' => 0, 'losses' => 0);
             }
             $totalstats[$type]['losses'] = $value;
             $count += $value;
         }
     }
     ksort($totalstats);
     $this->killstats = $killstats;
     $this->lossstats = $lossstats;
     $this->totalstats = $totalstats;
     $this->criteria = $criteria;
     $this->count = $count;
 }