public function parseKills($kills) { $oldkills = 0; $newkills = 0; $errors = 0; $lastID = 0; $lastIntID = 0; foreach ($kills as $kill) { try { // this needs to be run before exit of loop, otherwise having all kills of this run // will cause the lastID not being updated if (!is_null($kill->killID) && $kill->killID > 0) { $lastID = $kill->killID; } if (!is_null(@$kill->killInternalID) && @$kill->killInternalID > 0) { $lastIntID = $kill->killInternalID; } /*if(!is_null(Kingboard_Kill::getByKillId($kill->killID))) { $oldkills++; continue; }*/ $killdata = array("killID" => $kill->killID, "solarSystemID" => $kill->solarSystemID, "location" => array("solarSystem" => Kingboard_EveSolarSystem::getBySolarSystemId($kill->solarSystemID)->itemName, "security" => Kingboard_EveSolarSystem::getBySolarSystemId($kill->solarSystemID)->security, "region" => Kingboard_EveSolarSystem::getBySolarSystemId($kill->solarSystemID)->Region['itemName']), "killTime" => new MongoDate(strtotime($kill->killTime)), "moonID" => $kill->moonID, "victim" => array("characterID" => $this->ensureCharacterID($kill->victim->characterID, $kill->victim->characterName), "characterName" => $kill->victim->characterName, "corporationID" => $this->ensureCorporationID($kill->victim->corporationID, $kill->victim->corporationName), "corporationName" => $kill->victim->corporationName, "allianceID" => (int) $kill->victim->allianceID, "allianceName" => $kill->victim->allianceName, "factionID" => (int) $kill->victim->factionID, "factionName" => $kill->victim->factionName, "damageTaken" => $kill->victim->damageTaken, "shipTypeID" => (int) $kill->victim->shipTypeID, "shipType" => Kingboard_EveItem::getByItemId($kill->victim->shipTypeID)->typeName)); $killdata['attackers'] = array(); foreach ($kill->attackers as $attacker) { $killdata['attackers'][] = array("characterID" => $attacker->characterID, "characterName" => $attacker->characterName, "entityType" => Kingboard_Helper_EntityType::getEntityTypeByEntityId((int) $attacker->characterID), "corporationID" => $this->ensureCorporationID($attacker->corporationID, $attacker->corporationName), "corporationName" => $attacker->corporationName, "allianceID" => (int) $attacker->allianceID, "allianceName" => $attacker->allianceName, "factionID" => (int) $attacker->factionID, "factionName" => $attacker->factionName, "securityStatus" => $attacker->securityStatus, "damageDone" => $attacker->damageDone, "finalBlow" => $attacker->finalBlow, "weaponTypeID" => (int) $attacker->weaponTypeID, "weaponType" => Kingboard_EveItem::getByItemId($attacker->weaponTypeID)->typeName, "shipTypeID" => (int) $attacker->shipTypeID, "shipType" => Kingboard_EveItem::getByItemId($attacker->shipTypeID)->typeName); } $killdata['items'] = array(); if (isset($kill->items) && !is_null($kill->items)) { foreach ($kill->items as $item) { $killdata['items'][] = $this->ParseItem($item); } } $hash = Kingboard_KillmailHash_IdHash::getByData($killdata); $killdata['idHash'] = (string) $hash; if (is_null(Kingboard_Kill::getInstanceByIdHash($killdata['idHash']))) { $killObject = new Kingboard_Kill(); $killObject->injectDataFromMail($killdata); $killObject->save(); $newkills++; } else { $oldkills++; } } catch (Kingboard_KillmailParser_KillmailErrorException $e) { $errors++; } } return array('oldkills' => $oldkills, 'newkills' => $newkills, 'lastID' => $lastID, 'lastIntID' => $lastIntID, 'errors' => $errors); }
/** * Get the data model, create one if none set * It does not save a new one or any changes! * * @return Kingboard_Kill */ public function getModel() { $model = Kingboard_Kill::getInstanceByIdHash($this->getIdHash()); if (!$model) { $model = new Kingboard_Kill(); } $model->injectDataFromMail($this->getDataArray()); return $model; }